Bug 319704 - Toolbar button ordering broken

Allow the actionSets to float on top of the Eclipse4 menu and toolbar
renderer.  The contributions visibility and placement is then managed by
the 3.x legacy actionSet code.


Don't show any action sets during the initialization process.
Doing so causes multiple show requests and subsequent hide
requests will not be sufficient to get an action set to go
hidden due to reference counting.

The temporary perspective did not have an id set on it so
getPerspective(MPerspective) code was unable to identify which
perspective descriptor it represented. This meant that it had no
action sets to activate which causes an action set to be
deactivated twice. This makes the reference counts go into the
negatives and causes them to pretty much never become active
again.

Bug: 319704
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/ActionPresentation.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/ActionPresentation.java
new file mode 100644
index 0000000..46e3219
--- /dev/null
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/ActionPresentation.java
@@ -0,0 +1,222 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2009 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.ui.internal;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.dynamichelpers.IExtensionTracker;
+import org.eclipse.ui.SubActionBars;
+import org.eclipse.ui.internal.provisional.application.IActionBarConfigurer2;
+import org.eclipse.ui.internal.registry.IActionSet;
+import org.eclipse.ui.internal.registry.IActionSetDescriptor;
+
+/**
+ * Manage the configurable actions for one window.
+ */
+public class ActionPresentation {
+    private WorkbenchWindow window;
+
+    private HashMap mapDescToRec = new HashMap(3);
+
+    private HashMap invisibleBars = new HashMap(3);
+
+    private class SetRec {
+        public SetRec(IActionSet set,
+                SubActionBars bars) {
+            this.set = set;
+            this.bars = bars;
+        }
+
+        public IActionSet set;
+
+        public SubActionBars bars;
+    }
+
+    /**
+     * ActionPresentation constructor comment.
+     */
+    public ActionPresentation(WorkbenchWindow window) {
+        super();
+        this.window = window;
+    }
+
+    /**
+     * Remove all action sets.
+     */
+    public void clearActionSets() {
+        // Get all of the action sets -- both visible and invisible.
+        final List oldList = new ArrayList();
+        oldList.addAll(mapDescToRec.keySet());
+        oldList.addAll(invisibleBars.keySet());
+
+        Iterator iter = oldList.iterator();
+        while (iter.hasNext()) {
+            IActionSetDescriptor desc = (IActionSetDescriptor) iter.next();
+            removeActionSet(desc);
+        }
+    }
+
+    /**
+     * Destroy an action set.
+     */
+    public void removeActionSet(IActionSetDescriptor desc) {
+        SetRec rec = (SetRec) mapDescToRec.remove(desc);
+        if (rec == null) {
+            rec = (SetRec) invisibleBars.remove(desc);
+        }
+        if (rec != null) {
+            IActionSet set = rec.set;
+            SubActionBars bars = rec.bars;
+            if (bars != null) {
+                bars.dispose();
+            }
+            if (set != null) {
+                set.dispose();
+            }
+        }
+    }
+
+    /**
+     * Sets the list of visible action set.
+     */
+    public void setActionSets(IActionSetDescriptor[] newArray) {
+        // Convert array to list.
+        HashSet newList = new HashSet();
+        
+        for (int i = 0; i < newArray.length; i++) {
+            IActionSetDescriptor descriptor = newArray[i];
+            
+            newList.add(descriptor);
+        }
+        List oldList = new ArrayList(mapDescToRec.keySet());
+
+        // Remove obsolete actions.
+        Iterator iter = oldList.iterator();
+        while (iter.hasNext()) {
+            IActionSetDescriptor desc = (IActionSetDescriptor) iter.next();
+            if (!newList.contains(desc)) {
+                SetRec rec = (SetRec) mapDescToRec.get(desc);
+                if (rec != null) {
+                    mapDescToRec.remove(desc);
+                    IActionSet set = rec.set;
+                    SubActionBars bars = rec.bars;
+                    if (bars != null) {
+                        SetRec invisibleRec = new SetRec(set, bars);
+                        invisibleBars.put(desc, invisibleRec);
+                        bars.deactivate();
+                    }
+                }
+            }
+        }
+
+        // Add new actions.
+        ArrayList sets = new ArrayList();
+        
+        for (int i = 0; i < newArray.length; i++) {
+            IActionSetDescriptor desc = newArray[i];
+
+            if (!mapDescToRec.containsKey(desc)) {
+                try {
+                    SetRec rec;
+                    // If the action bars and sets have already been created
+                    // then
+                    // reuse those action sets
+                    if (invisibleBars.containsKey(desc)) {
+                        rec = (SetRec) invisibleBars.get(desc);
+                        if (rec.bars != null) {
+                            rec.bars.activate();
+                        }
+                        invisibleBars.remove(desc);
+                    } else {
+                        IActionSet set = desc.createActionSet();
+                        SubActionBars bars = new ActionSetActionBars(window
+								.getActionBars(), window,
+								(IActionBarConfigurer2) window.getWindowConfigurer()
+										.getActionBarConfigurer(), desc.getId());
+                        rec = new SetRec(set, bars);
+                        set.init(window, bars);
+                        sets.add(set);
+
+                        // only register against the tracker once - check for
+                        // other registrations against the provided extension
+                        Object[] existingRegistrations = window
+                                .getExtensionTracker().getObjects(
+                                        desc.getConfigurationElement()
+                                                .getDeclaringExtension());
+                        if (existingRegistrations.length == 0
+                                || !containsRegistration(existingRegistrations,
+                                        desc)) {
+                            //register the set with the page tracker
+                            //this will be cleaned up by WorkbenchWindow listener
+                            window.getExtensionTracker().registerObject(
+                                    desc.getConfigurationElement().getDeclaringExtension(),
+                                    desc, IExtensionTracker.REF_WEAK);
+                        }
+                    }
+                    mapDescToRec.put(desc, rec);
+                } catch (CoreException e) {
+                    WorkbenchPlugin
+                            .log("Unable to create ActionSet: " + desc.getId(), e);//$NON-NLS-1$
+                }
+            }
+        }
+        // We process action sets in two passes for coolbar purposes. First we
+        // process base contributions
+        // (i.e., actions that the action set contributes to its toolbar), then
+        // we process adjunct contributions
+        // (i.e., actions that the action set contributes to other toolbars).
+        // This type of processing is
+        // necessary in order to maintain group order within a coolitem.
+        PluginActionSetBuilder.processActionSets(sets, window);
+
+        iter = sets.iterator();
+        while (iter.hasNext()) {
+            PluginActionSet set = (PluginActionSet) iter.next();
+            set.getBars().activate();
+        }
+    }
+
+    /**
+     * Return whether the array contains the given action set.
+     * 
+     * @param existingRegistrations the array to check
+     * @param set the set to look for
+     * @return whether the set is in the array
+     * @since 3.1
+     */
+    private boolean containsRegistration(Object[] existingRegistrations, IActionSetDescriptor set) {
+        for (int i = 0; i < existingRegistrations.length; i++) {
+            if (existingRegistrations[i] == set) {
+				return true;
+			}
+        }
+        return false;
+    }
+
+    /**
+     */
+    public IActionSet[] getActionSets() {
+        Collection setRecCollection = mapDescToRec.values();
+        IActionSet result[] = new IActionSet[setRecCollection.size()];
+        int i = 0;
+        for (Iterator iterator = setRecCollection.iterator(); iterator
+                .hasNext(); i++) {
+			result[i] = ((SetRec) iterator.next()).set;
+		}
+        return result;
+    }
+}
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/ActionSetManager.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/ActionSetManager.java
index 200a5b1..614bf9d 100644
--- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/ActionSetManager.java
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/ActionSetManager.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2005, 2011 IBM Corporation and others.
+ * Copyright (c) 2005, 2007 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -17,11 +17,10 @@
 
 import org.eclipse.core.runtime.ListenerList;
 import org.eclipse.ui.IPropertyListener;
-import org.eclipse.ui.IWorkbenchWindow;
 import org.eclipse.ui.contexts.IContextActivation;
 import org.eclipse.ui.contexts.IContextService;
-import org.eclipse.ui.internal.expressions.WorkbenchWindowExpression;
 import org.eclipse.ui.internal.registry.IActionSetDescriptor;
+import org.eclipse.ui.services.IServiceLocator;
 
 /**
  * Maintains a reference counted set of action sets, with a visibility mask.
@@ -69,11 +68,9 @@
 	private IPropertyListener contextListener;
 	private Map activationsById = new HashMap();
 	private IContextService contextService;
-	private IWorkbenchWindow window;
     
-	public ActionSetManager(IWorkbenchWindow locator) {
+    public ActionSetManager(IServiceLocator locator) {
     	contextService = (IContextService) locator.getService(IContextService.class);
-		window = locator;
 		addListener(getContextListener());
     }
     
@@ -88,8 +85,8 @@
 						IActionSetDescriptor desc = (IActionSetDescriptor) source;
 						String id = desc.getId();
 						if (propId == PROP_VISIBLE) {
-							activationsById.put(id, contextService.activateContext(id,
-									new WorkbenchWindowExpression(window)));
+							activationsById.put(id, contextService
+									.activateContext(id));
 						} else if (propId == PROP_HIDDEN) {
 							IContextActivation act = (IContextActivation) activationsById
 									.remove(id);
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/CoolBarToTrimManager.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/CoolBarToTrimManager.java
index 4403e0f..005d55b 100644
--- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/CoolBarToTrimManager.java
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/CoolBarToTrimManager.java
@@ -11,6 +11,7 @@
 
 package org.eclipse.ui.internal;
 
+import java.util.ArrayList;
 import java.util.List;
 import org.eclipse.e4.ui.model.application.MApplication;
 import org.eclipse.e4.ui.model.application.ui.basic.MTrimBar;
@@ -26,7 +27,6 @@
 import org.eclipse.e4.ui.workbench.renderers.swt.ToolBarManagerRenderer;
 import org.eclipse.e4.ui.workbench.swt.factories.IRendererFactory;
 import org.eclipse.jface.action.AbstractGroupMarker;
-import org.eclipse.jface.action.ActionContributionItem;
 import org.eclipse.jface.action.ContributionManager;
 import org.eclipse.jface.action.GroupMarker;
 import org.eclipse.jface.action.IAction;
@@ -311,8 +311,37 @@
 	 * @see org.eclipse.jface.action.IContributionManager#getItems()
 	 */
 	public IContributionItem[] getItems() {
-		new Exception("CBTTM:getItems()").printStackTrace(); //$NON-NLS-1$
-		return new IContributionItem[0];
+		ArrayList<IContributionItem> items = new ArrayList<IContributionItem>();
+		for (MTrimElement el : trimBar.getChildren()) {
+			if (el instanceof MToolBar) {
+				final MToolBar model = (MToolBar) el;
+				if (model.getTransientData().get(OBJECT) != null) {
+					items.add((IContributionItem) model.getTransientData().get(OBJECT));
+				} else {
+					ToolBarManagerRenderer renderer = (ToolBarManagerRenderer) rendererFactory
+							.getRenderer(model, null);
+					final ToolBarManager manager = renderer.getManager(model);
+					if (manager != null) {
+						final ToolBarContributionItem toolBarContributionItem = new ToolBarContributionItem(
+								manager, model.getElementId()) {
+							@Override
+							public void setVisible(boolean visible) {
+								super.setVisible(visible);
+								model.setVisible(visible);
+							}
+						};
+						model.getTransientData().put(OBJECT, toolBarContributionItem);
+						items.add(toolBarContributionItem);
+					} else if (model.getTags().contains(TOOLBAR_SEPARATOR)) {
+						if (model.getTransientData().get(OBJECT) != null) {
+							items.add((IContributionItem) model.getTransientData().get(OBJECT));
+						}
+						items.add(new GroupMarker(model.getElementId()));
+					}
+				}
+			}
+		}
+		return items.toArray(new IContributionItem[items.size()]);
 	}
 
 	/*
@@ -331,8 +360,7 @@
 	 * @see org.eclipse.jface.action.IContributionManager#getOverrides()
 	 */
 	public IContributionManagerOverrides getOverrides() {
-		// TODO Auto-generated method stub
-		return null;
+		return toolbarOverrides;
 	}
 
 	/*
@@ -497,6 +525,7 @@
 						renderer.clearModelToManager((MToolBar) child, (ToolBarManager) parent);
 					}
 				}
+				workbenchTrimElements.remove(child);
 				
 				children.get(i).setToBeRendered(false);
 				children.remove(i);
@@ -604,6 +633,11 @@
 					//						System.out.println("update(boolean force): " + el); //$NON-NLS-1$
 					// }
 					fill((MToolBar) el, manager);
+					// TODO: Hack to work around Bug 370961
+					ToolBar tb = manager.getControl();
+					if (tb != null && !tb.isDisposed()) {
+						tb.getShell().layout(new Control[] { tb }, SWT.DEFER);
+					}
 				}
 			}
 		}
@@ -672,30 +706,6 @@
 				separator.setElementId(item.getId());
 				container.getChildren().add(separator);
 				manager.remove(item);
-			} else if (item instanceof ActionContributionItem) {
-				IAction action = ((ActionContributionItem) item).getAction();
-				if (action.getStyle() == IAction.AS_DROP_DOWN_MENU) {
-					MOpaqueToolItem toolItem = MenuFactoryImpl.eINSTANCE.createOpaqueToolItem();
-					toolItem.setOpaqueItem(item);
-					toolItem.setElementId(item.getId());
-					String iconUrl = MenuHelper.getIconURI(action.getImageDescriptor(),
-							application.getContext());
-					 toolItem.setIconURI(iconUrl);
-					String disabledIconURI = MenuHelper.getIconURI(
-							action.getDisabledImageDescriptor(), application.getContext());
-					MenuHelper.setDisabledIconURI(toolItem, disabledIconURI);
-
-					container.getChildren().add(toolItem);
-					renderer.linkModelToContribution(toolItem, item);
-				} else {
-					MToolItem toolItem = MenuHelper.createToolItem(application,
-							(ActionContributionItem) item);
-					manager.remove(item);
-					if (toolItem != null) {
-						container.getChildren().add(toolItem);
-						toolItem.getTransientData().put("Name", action.getToolTipText()); //$NON-NLS-1$						
-					}
-				}
 			} else {
 				MOpaqueToolItem toolItem = MenuFactoryImpl.eINSTANCE.createOpaqueToolItem();
 				toolItem.setElementId(item.getId());
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/Perspective.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/Perspective.java
new file mode 100644
index 0000000..b4ca9cf
--- /dev/null
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/Perspective.java
@@ -0,0 +1,386 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2010 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     IBM Corporation - initial API and implementation
+ *     Markus Alexander Kuppe, Versant GmbH - bug 215797
+ *     Sascha Zak - bug 282874
+ *******************************************************************************/
+
+package org.eclipse.ui.internal;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import org.eclipse.e4.ui.model.application.ui.advanced.MPerspective;
+import org.eclipse.ui.IMemento;
+import org.eclipse.ui.IPerspectiveDescriptor;
+import org.eclipse.ui.IWorkbenchPartReference;
+import org.eclipse.ui.contexts.IContextService;
+import org.eclipse.ui.internal.e4.compatibility.ModeledPageLayout;
+import org.eclipse.ui.internal.registry.ActionSetRegistry;
+import org.eclipse.ui.internal.registry.IActionSetDescriptor;
+import org.eclipse.ui.internal.registry.PerspectiveDescriptor;
+import org.eclipse.ui.presentations.IStackPresentationSite;
+
+/**
+ * The ViewManager is a factory for workbench views.  
+ */
+public class Perspective {
+    protected PerspectiveDescriptor descriptor;
+
+    protected WorkbenchPage page;
+
+    // Editor Area management
+	// protected LayoutPart editorArea;
+	// protected PartPlaceholder editorHolder;
+    protected boolean editorHidden = false;
+    protected boolean editorAreaRestoreOnUnzoom = false;
+    protected int editorAreaState = IStackPresentationSite.STATE_RESTORED;
+
+	// private ViewFactory viewFactory;
+    
+    protected ArrayList alwaysOnActionSets;
+
+    protected ArrayList alwaysOffActionSets;
+    
+    /**	IDs of menu items the user has chosen to hide	*/
+    protected Collection hideMenuIDs;
+    
+    /**	IDs of toolbar items the user has chosen to hide	*/
+    protected Collection hideToolBarIDs;
+
+    //private List fastViews;
+	// protected FastViewManager fastViewManager = null;
+
+    private Map mapIDtoViewLayoutRec;
+
+    protected boolean fixed;
+
+    protected ArrayList showInPartIds;
+
+    protected HashMap showInTimes = new HashMap();
+
+    protected IMemento memento;
+
+    /**
+     * Reference to the part that was previously active
+     * when this perspective was deactivated.
+     */
+    private IWorkbenchPartReference oldPartRef = null;
+
+    protected boolean shouldHideEditorsOnActivate = false;
+
+	// protected PageLayout layout;
+	protected MPerspective layout;
+
+    /**
+     * ViewManager constructor comment.
+     */
+	public Perspective(PerspectiveDescriptor desc, MPerspective layout, WorkbenchPage page) {
+        this(page);
+		this.layout = layout;
+        descriptor = desc;
+    }
+
+	public void initActionSets() {
+		if (descriptor != null) {
+			List temp = new ArrayList();
+			createInitialActionSets(temp,
+					ModeledPageLayout.getIds(layout, ModeledPageLayout.ACTION_SET_TAG));
+			for (Iterator iter = temp.iterator(); iter.hasNext();) {
+				IActionSetDescriptor descriptor = (IActionSetDescriptor) iter.next();
+				if (!alwaysOnActionSets.contains(descriptor)) {
+					alwaysOnActionSets.add(descriptor);
+				}
+			}
+		}
+
+	}
+    /**
+     * ViewManager constructor comment.
+     */
+	protected Perspective(WorkbenchPage page) {
+        this.page = page;
+        alwaysOnActionSets = new ArrayList(2);
+        alwaysOffActionSets = new ArrayList(2);
+        hideMenuIDs = new HashSet();
+        hideToolBarIDs = new HashSet();
+        
+        
+        mapIDtoViewLayoutRec = new HashMap();
+    }
+
+
+    /**
+     * Create the initial list of action sets.
+     */
+    protected void createInitialActionSets(List outputList, List stringList) {
+        ActionSetRegistry reg = WorkbenchPlugin.getDefault()
+                .getActionSetRegistry();
+        Iterator iter = stringList.iterator();
+        while (iter.hasNext()) {
+            String id = (String) iter.next();
+            IActionSetDescriptor desc = reg.findActionSet(id);
+            if (desc != null) {
+				outputList.add(desc);
+			} else {
+				WorkbenchPlugin.log("Unable to find Action Set: " + id);//$NON-NLS-1$
+			}
+        }
+    }
+
+    /**
+     * Dispose the perspective and all views contained within.
+     */
+    public void dispose() {
+        // Get rid of presentation.
+		mapIDtoViewLayoutRec.clear();
+    }
+
+	/**
+	 * Returns the perspective.
+	 */
+    public IPerspectiveDescriptor getDesc() {
+        return descriptor;
+    }
+
+
+    /**
+     * Returns the new wizard shortcuts associated with this perspective.
+     * 
+     * @return an array of new wizard identifiers
+     */
+    public String[] getNewWizardShortcuts() {
+		return page.getNewWizardShortcuts();
+    }
+
+    /**
+     * Returns the perspective shortcuts associated with this perspective.
+     * 
+     * @return an array of perspective identifiers
+     */
+    public String[] getPerspectiveShortcuts() {
+		return page.getPerspectiveShortcuts();
+    }
+
+    /**
+     * Returns the ids of the parts to list in the Show In... dialog.
+     * This is a List of Strings.
+     */
+    public ArrayList getShowInPartIds() {
+		return page.getShowInPartIds();
+    }
+
+    /**
+     * Returns the time at which the last Show In was performed
+     * for the given target part, or 0 if unknown.
+     */
+    public long getShowInTime(String partId) {
+        Long t = (Long) showInTimes.get(partId);
+        return t == null ? 0L : t.longValue();
+    }
+
+    /**
+     * Returns the show view shortcuts associated with this perspective.
+     * 
+     * @return an array of view identifiers
+     */
+    public String[] getShowViewShortcuts() {
+		return page.getShowViewShortcuts();
+    }
+
+    private void removeAlwaysOn(IActionSetDescriptor descriptor) {
+        if (descriptor == null) {
+            return;
+        }
+        if (!alwaysOnActionSets.contains(descriptor)) {
+            return;
+        }
+        
+        alwaysOnActionSets.remove(descriptor);
+        if (page != null) {
+            page.perspectiveActionSetChanged(this, descriptor, ActionSetManager.CHANGE_HIDE);
+        }
+    }
+    
+    protected void addAlwaysOff(IActionSetDescriptor descriptor) {
+        if (descriptor == null) {
+            return;
+        }
+        if (alwaysOffActionSets.contains(descriptor)) {
+            return;
+        }
+        alwaysOffActionSets.add(descriptor);
+        if (page != null) {
+            page.perspectiveActionSetChanged(this, descriptor, ActionSetManager.CHANGE_MASK);
+        }
+        removeAlwaysOn(descriptor);
+    }
+    
+    protected void addAlwaysOn(IActionSetDescriptor descriptor) {
+        if (descriptor == null) {
+            return;
+        }
+        if (alwaysOnActionSets.contains(descriptor)) {
+            return;
+        }
+        alwaysOnActionSets.add(descriptor);
+        if (page != null) {
+            page.perspectiveActionSetChanged(this, descriptor, ActionSetManager.CHANGE_SHOW);
+        }
+        removeAlwaysOff(descriptor);
+    }
+    
+    private void removeAlwaysOff(IActionSetDescriptor descriptor) {
+        if (descriptor == null) {
+            return;
+        }
+        if (!alwaysOffActionSets.contains(descriptor)) {
+            return;
+        }
+        alwaysOffActionSets.remove(descriptor);
+        if (page != null) {
+            page.perspectiveActionSetChanged(this, descriptor, ActionSetManager.CHANGE_UNMASK);
+        }
+    }
+    
+    /**
+     * Returns the ActionSets read from perspectiveExtensions in the registry.  
+     */
+    protected ArrayList getPerspectiveExtensionActionSets() {
+		return page.getPerspectiveExtensionActionSets(descriptor.getOriginalId());
+    }
+    
+    public void turnOnActionSets(IActionSetDescriptor[] newArray) {
+        for (int i = 0; i < newArray.length; i++) {
+            IActionSetDescriptor descriptor = newArray[i];
+            
+            addAlwaysOn(descriptor);
+        }
+    }
+    
+    public void turnOffActionSets(IActionSetDescriptor[] toDisable) {
+        for (int i = 0; i < toDisable.length; i++) {
+            IActionSetDescriptor descriptor = toDisable[i];
+            
+            turnOffActionSet(descriptor);
+        }
+    }
+
+    public void turnOffActionSet(IActionSetDescriptor toDisable) {
+        addAlwaysOff(toDisable);
+    }
+    
+
+
+    /**
+     * Returns the old part reference.
+     * Returns null if there was no previously active part.
+     * 
+     * @return the old part reference or <code>null</code>
+     */
+    public IWorkbenchPartReference getOldPartRef() {
+        return oldPartRef;
+    }
+
+    /**
+     * Sets the old part reference.
+     * 
+     * @param oldPartRef The old part reference to set, or <code>null</code>
+     */
+    public void setOldPartRef(IWorkbenchPartReference oldPartRef) {
+        this.oldPartRef = oldPartRef;
+    }
+
+    //for dynamic UI
+    protected void addActionSet(IActionSetDescriptor newDesc) {
+    	IContextService service = (IContextService)page.getWorkbenchWindow().getService(IContextService.class);
+    	try {
+			service.deferUpdates(true);
+			for (int i = 0; i < alwaysOnActionSets.size(); i++) {
+				IActionSetDescriptor desc = (IActionSetDescriptor) alwaysOnActionSets
+						.get(i);
+				if (desc.getId().equals(newDesc.getId())) {
+					removeAlwaysOn(desc);
+					removeAlwaysOff(desc);
+					break;
+				}
+			}
+			addAlwaysOn(newDesc);
+			final String actionSetID = newDesc.getId();
+
+			// Add Tags
+			String tag = ModeledPageLayout.ACTION_SET_TAG + actionSetID;
+			if (!layout.getTags().contains(tag)) {
+				layout.getTags().add(tag);
+			}
+		} finally {
+    		service.deferUpdates(false);
+    	}
+    }
+
+    // for dynamic UI
+    /* package */void removeActionSet(String id) {
+    	IContextService service = (IContextService)page.getWorkbenchWindow().getService(IContextService.class);
+    	try {
+			service.deferUpdates(true);
+			for (int i = 0; i < alwaysOnActionSets.size(); i++) {
+				IActionSetDescriptor desc = (IActionSetDescriptor) alwaysOnActionSets
+						.get(i);
+				if (desc.getId().equals(id)) {
+					removeAlwaysOn(desc);
+					break;
+				}
+			}
+
+			for (int i = 0; i < alwaysOffActionSets.size(); i++) {
+				IActionSetDescriptor desc = (IActionSetDescriptor) alwaysOffActionSets
+						.get(i);
+				if (desc.getId().equals(id)) {
+					removeAlwaysOff(desc);
+					break;
+				}
+			}
+		} finally {
+    		service.deferUpdates(false);
+    	}
+    }
+    
+    void removeActionSet(IActionSetDescriptor toRemove) {
+        removeAlwaysOn(toRemove);
+        removeAlwaysOff(toRemove);
+    }
+
+    public IActionSetDescriptor[] getAlwaysOnActionSets() {
+        return (IActionSetDescriptor[]) alwaysOnActionSets.toArray(new IActionSetDescriptor[alwaysOnActionSets.size()]);
+    }
+    
+    public IActionSetDescriptor[] getAlwaysOffActionSets() {
+        return (IActionSetDescriptor[]) alwaysOffActionSets.toArray(new IActionSetDescriptor[alwaysOffActionSets.size()]);
+    }
+	
+	/**	@return a Collection of IDs of items to be hidden from the menu bar	*/
+	public Collection getHiddenMenuItems() {
+		return hideMenuIDs;
+	}
+	
+	/**	@return a Collection of IDs of items to be hidden from the tool bar	*/
+	public Collection getHiddenToolbarItems() {
+		return hideToolBarIDs;
+	}
+	
+	public void updateActionBars() {
+		page.getActionBars().getMenuManager().updateAll(true);
+		page.resetToolBarLayout();
+	}
+
+}
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/PluginActionSetBuilder.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/PluginActionSetBuilder.java
new file mode 100644
index 0000000..04175e4
--- /dev/null
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/PluginActionSetBuilder.java
@@ -0,0 +1,779 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2009 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.ui.internal;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.dynamichelpers.IExtensionTracker;
+import org.eclipse.jface.action.AbstractGroupMarker;
+import org.eclipse.jface.action.ActionContributionItem;
+import org.eclipse.jface.action.GroupMarker;
+import org.eclipse.jface.action.IContributionItem;
+import org.eclipse.jface.action.IContributionManager;
+import org.eclipse.jface.action.ICoolBarManager;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.IToolBarManager;
+import org.eclipse.jface.action.Separator;
+import org.eclipse.jface.internal.provisional.action.IToolBarContributionItem;
+import org.eclipse.ui.IActionBars;
+import org.eclipse.ui.IWorkbenchActionConstants;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.internal.registry.ActionSetRegistry;
+import org.eclipse.ui.internal.registry.IWorkbenchRegistryConstants;
+import org.eclipse.ui.services.IDisposable;
+
+/**
+ * This builder reads the actions for an action set from the registry.
+ */
+public class PluginActionSetBuilder extends PluginActionBuilder {
+
+    private PluginActionSet actionSet;
+
+    private IWorkbenchWindow window;
+
+    private ArrayList adjunctContributions = new ArrayList(0);
+    
+    /**
+     * Used by the workbench window extension handler to unhook action sets from
+     * their associated window.
+     * 
+     * @since 3.1
+     */
+	public static class Binding implements IDisposable {
+        PluginActionSetBuilder builder;
+        PluginActionSet set;
+        IWorkbenchWindow window;
+		IExtensionTracker tracker;
+
+		/*
+		 * (non-Javadoc)
+		 * 
+		 * @see org.eclipse.ui.services.IDisposable#dispose()
+		 */
+		public void dispose() {
+			if (tracker != null) {
+				tracker.unregisterObject(set.getConfigElement()
+						.getDeclaringExtension(), this);
+				tracker = null;
+			}
+		}
+    }
+
+    /**
+     * Constructs a new builder.
+     */
+    public PluginActionSetBuilder() {
+    }
+
+    /**
+     * Read the actions within a config element. Called by customize perspective
+     * 
+     * @param set the action set
+     * @param window the window to contribute to
+     */
+    public void buildMenuAndToolBarStructure(PluginActionSet set,
+            IWorkbenchWindow window) {
+        this.actionSet = set;
+        this.window = window;
+        cache = null;
+        currentContribution = null;
+        targetID = null;
+        targetContributionTag = IWorkbenchRegistryConstants.TAG_ACTION_SET;
+
+        readElements(new IConfigurationElement[] { set.getConfigElement() });
+
+        if (cache != null) {
+            for (int i = 0; i < cache.size(); i++) {
+                ActionSetContribution contribution = (ActionSetContribution) cache
+                        .get(i);
+                contribution.contribute(actionSet.getBars(), true, true);
+                if (contribution.isAdjunctContributor()) {
+                    adjunctContributions.add(contribution);
+                }
+            }
+        }
+        for (int i = 0; i < adjunctContributions.size(); i++) {
+            ActionSetContribution contribution = (ActionSetContribution) adjunctContributions
+                    .get(i);
+            ActionSetActionBars bars = actionSet.getBars();
+            for (int j = 0; j < contribution.adjunctActions.size(); j++) {
+                ActionDescriptor adjunctAction = (ActionDescriptor) contribution.adjunctActions
+                        .get(j);
+                contribution
+                        .contributeAdjunctCoolbarAction(adjunctAction, bars);
+            }
+        }
+        
+        registerBinding(set);
+    }
+
+    /* (non-Javadoc)
+     * Method declared on PluginActionBuilder.
+     */
+    protected ActionDescriptor createActionDescriptor(
+            IConfigurationElement element) {
+        // As of 2.1, the "pulldown" attribute was deprecated and replaced by
+        // the attribute "style". See doc for more details.
+        boolean pullDownStyle = false;
+        String style = element.getAttribute(IWorkbenchRegistryConstants.ATT_STYLE);
+        if (style != null) {
+            pullDownStyle = style.equals(ActionDescriptor.STYLE_PULLDOWN);
+        } else {
+            String pulldown = element.getAttribute(ActionDescriptor.STYLE_PULLDOWN);
+            pullDownStyle = pulldown != null && pulldown.equals("true"); //$NON-NLS-1$
+        }
+
+        ActionDescriptor desc = null;
+        if (pullDownStyle) {
+			desc = new ActionDescriptor(element,
+                    ActionDescriptor.T_WORKBENCH_PULLDOWN, window);
+		} else {
+			desc = new ActionDescriptor(element, ActionDescriptor.T_WORKBENCH,
+                    window);
+		}
+        WWinPluginAction action = (WWinPluginAction) desc.getAction();
+        action.setActionSetId(actionSet.getDesc().getId());
+        actionSet.addPluginAction(action);
+        return desc;
+    }
+
+    /* (non-Javadoc)
+     * Method declared on PluginActionBuilder.
+     */
+    protected BasicContribution createContribution() {
+        return new ActionSetContribution(actionSet.getDesc().getId(), window);
+    }
+
+    /**
+     * Returns the insertion point for a new contribution item.  Clients should
+     * use this item as a reference point for insertAfter.
+     *
+     * @param startId the reference id for insertion
+     * @param sortId the sorting id for the insertion.  If null then the item
+     *		will be inserted at the end of all action sets.
+     * @param mgr the target menu manager.
+     * @param startVsEnd if <code>true</code> the items are added at the start of
+     *		action with the same id; else they are added to the end
+     * @return the insertion point, or null if not found.
+     */
+    public static IContributionItem findInsertionPoint(String startId,
+            String sortId, IContributionManager mgr, boolean startVsEnd) {
+        // Get items.
+        IContributionItem[] items = mgr.getItems();
+
+        // Find the reference item.
+        int insertIndex = 0;
+        while (insertIndex < items.length) {
+            if (startId.equals(items[insertIndex].getId())) {
+				break;
+			}
+            ++insertIndex;
+        }
+        if (insertIndex >= items.length) {
+			return null;
+		}
+
+        // Calculate startVsEnd comparison value.
+        int compareMetric = 0;
+        if (startVsEnd) {
+			compareMetric = 1;
+		}
+
+        // Find the insertion point for the new item.
+        // We do this by iterating through all of the previous
+        // action set contributions define within the current group.
+        for (int nX = insertIndex + 1; nX < items.length; nX++) {
+            IContributionItem item = items[nX];
+            if (item.isSeparator() || item.isGroupMarker()) {
+                // Fix for bug report 18357
+                break;
+            }
+            if (item instanceof IActionSetContributionItem) {
+                if (sortId != null) {
+                    String testId = ((IActionSetContributionItem) item)
+                            .getActionSetId();
+                    if (sortId.compareTo(testId) < compareMetric) {
+						break;
+					}
+                }
+                insertIndex = nX;
+            } else {
+                break;
+            }
+        }
+        // Return item.
+        return items[insertIndex];
+    }
+
+    /**
+     */
+    /* package */static void processActionSets(ArrayList pluginActionSets,
+            WorkbenchWindow window) {
+        // Process the action sets in two passes.  On the first pass the pluginActionSetBuilder
+        // will process base contributions and cache adjunct contributions.  On the second
+        // pass the adjunct contributions will be processed.
+        PluginActionSetBuilder[] builders = new PluginActionSetBuilder[pluginActionSets
+                .size()];
+        for (int i = 0; i < pluginActionSets.size(); i++) {
+            PluginActionSet set = (PluginActionSet) pluginActionSets.get(i);
+            PluginActionSetBuilder builder = new PluginActionSetBuilder();
+            builder.readActionExtensions(set, window);
+            builders[i] = builder;
+        }
+        for (int i = 0; i < builders.length; i++) {
+            PluginActionSetBuilder builder = builders[i];
+            builder.processAdjunctContributions();
+        }
+    }
+
+    /**
+     */
+    protected void processAdjunctContributions() {
+        // Contribute the adjunct contributions.
+        for (int i = 0; i < adjunctContributions.size(); i++) {
+            ActionSetContribution contribution = (ActionSetContribution) adjunctContributions
+                    .get(i);
+            ActionSetActionBars bars = actionSet.getBars();
+            for (int j = 0; j < contribution.adjunctActions.size(); j++) {
+                ActionDescriptor adjunctAction = (ActionDescriptor) contribution.adjunctActions
+                        .get(j);
+                contribution
+                        .contributeAdjunctCoolbarAction(adjunctAction, bars);
+            }
+        }
+    }
+
+    /**
+     * Read the actions within a config element.
+     */
+    protected void readActionExtensions(PluginActionSet set,
+            IWorkbenchWindow window) {
+        this.actionSet = set;
+        this.window = window;
+        cache = null;
+        currentContribution = null;
+        targetID = null;
+        targetContributionTag = IWorkbenchRegistryConstants.TAG_ACTION_SET;
+
+        readElements(new IConfigurationElement[] { set.getConfigElement() });
+
+        if (cache != null) {
+            // for dynamic UI - save cache for future removal lf actionset extensions
+            //        Don't call addCache -- it's broken, and is only used for dynamic plugin removal,
+            //        which the workbench doesn't currently support.
+            //        See bug 66374 for more details.
+            //			WorkbenchPlugin.getDefault().getActionSetRegistry().addCache(set.getDesc().getId(), cache);
+            for (int i = 0; i < cache.size(); i++) {
+                ActionSetContribution contribution = (ActionSetContribution) cache
+                        .get(i);
+                contribution.contribute(actionSet.getBars(), true, true);
+                if (contribution.isAdjunctContributor()) {
+                    adjunctContributions.add(contribution);
+                }
+            }
+            
+            registerBinding(set);
+            
+        } else {
+            WorkbenchPlugin
+                    .log("Action Set is empty: " + set.getDesc().getId()); //$NON-NLS-1$
+        }
+    }
+    
+    private void registerBinding(final PluginActionSet set) {
+    	final IExtensionTracker tracker = window.getExtensionTracker();
+    	 
+    	// register the new binding
+    	final Binding binding = new Binding();
+        binding.builder = this;
+        binding.set = set;
+        binding.window = window;
+		binding.tracker = tracker;
+        tracker.registerObject(
+                set.getConfigElement().getDeclaringExtension(), binding,
+                IExtensionTracker.REF_STRONG);
+		set.setBuilder(binding);
+    }
+
+    /**
+     * Helper class to collect the menus and actions defined within a
+     * contribution element.
+     */
+    private static class ActionSetContribution extends BasicContribution {
+        private String actionSetId;
+
+        private WorkbenchWindow window;
+
+        protected ArrayList adjunctActions = new ArrayList(0);
+
+        /**
+         * Create a new instance of <code>ActionSetContribution</code>.
+         * 
+         * @param id the id
+         * @param window the window to contribute to
+         */
+        public ActionSetContribution(String id, IWorkbenchWindow window) {
+            super();
+            actionSetId = id;
+            this.window = (WorkbenchWindow) window;
+        }
+
+        /**
+         * This implementation inserts the group into the action set additions group.  
+         */
+        protected void addGroup(IContributionManager mgr, String name) {
+            IContributionItem refItem = findInsertionPoint(
+                    IWorkbenchActionConstants.MB_ADDITIONS, actionSetId, mgr,
+                    true);
+            // Insert the new group marker.
+            ActionSetSeparator group = new ActionSetSeparator(name, actionSetId);
+            if (refItem == null) {
+                mgr.add(group);
+            } else {
+                mgr.insertAfter(refItem.getId(), group);
+            }
+        }
+
+        /**
+         * Contributes submenus and/or actions into the provided menu and tool bar
+         * managers.
+         * 
+         * @param bars the action bars to contribute to
+         * @param menuAppendIfMissing append to the menubar if missing
+         * @param toolAppendIfMissing append to the toolbar if missing
+         */
+        public void contribute(IActionBars bars, boolean menuAppendIfMissing,
+                boolean toolAppendIfMissing) {
+
+            IMenuManager menuMgr = bars.getMenuManager();
+            IToolBarManager toolBarMgr = bars.getToolBarManager();
+            if (menus != null && menuMgr != null) {
+                for (int i = 0; i < menus.size(); i++) {
+                    IConfigurationElement menuElement = (IConfigurationElement) menus
+                            .get(i);
+                    contributeMenu(menuElement, menuMgr, menuAppendIfMissing);
+                }
+            }
+
+            if (actions != null) {
+                for (int i = 0; i < actions.size(); i++) {
+                    ActionDescriptor ad = (ActionDescriptor) actions.get(i);
+                    if (menuMgr != null) {
+						contributeMenuAction(ad, menuMgr, menuAppendIfMissing);
+					}
+                    if (toolBarMgr != null) {
+                        if (bars instanceof ActionSetActionBars) {
+                            contributeCoolbarAction(ad,
+                                    (ActionSetActionBars) bars);
+                        } else {
+                            contributeToolbarAction(ad, toolBarMgr,
+                                    toolAppendIfMissing);
+                        }
+                    }
+                }
+            }
+        }
+
+        /**
+         * Contributes action from the action descriptor into the cool bar manager.
+         */
+        protected void contributeAdjunctCoolbarAction(ActionDescriptor ad,
+                ActionSetActionBars bars) {
+            String toolBarId = ad.getToolbarId();
+            String toolGroupId = ad.getToolbarGroupId();
+
+            String contributingId = bars.getActionSetId();
+            ICoolBarManager coolBarMgr = bars.getCoolBarManager();
+            if (coolBarMgr == null) {
+                return;
+            }
+
+            PluginAction action = ad.getAction();
+            ActionContributionItem actionContribution = new PluginActionCoolBarContributionItem(
+                    action);
+            actionContribution.setMode(ad.getMode());
+
+            bars.addAdjunctContribution(actionContribution);
+
+            // create a coolitem for the toolbar id if it does not yet exist				
+            IToolBarManager toolBarManager = bars.getToolBarManager(toolBarId);
+
+            // Check to see if the group already exists
+            IContributionItem groupMarker = toolBarManager.find(toolGroupId);
+            // Add a group marker if one does not exist
+            if (groupMarker == null) {
+                toolBarManager.add(new Separator(toolGroupId));
+            }
+            IContributionItem refItem = findAlphabeticalOrder(toolGroupId,
+                    contributingId, toolBarManager);
+            if (refItem != null && refItem.getId() != null) {
+                toolBarManager.insertAfter(refItem.getId(), actionContribution);
+            } else {
+                toolBarManager.add(actionContribution);
+            }
+            toolBarManager.update(false);
+
+        }
+
+        /**
+         * Contributes action from the action descriptor into the cool bar manager.
+         */
+        protected void contributeCoolbarAction(ActionDescriptor ad,
+                ActionSetActionBars bars) {
+            String toolBarId = ad.getToolbarId();
+            String toolGroupId = ad.getToolbarGroupId();
+            if (toolBarId == null && toolGroupId == null) {
+				return;
+			}
+
+            String contributingId = bars.getActionSetId();
+
+            if (toolBarId == null || toolBarId.equals("")) { //$NON-NLS-1$ 
+                // the item is being added to the coolitem for its action set
+                toolBarId = contributingId;
+            }
+
+            if (!toolBarId.equals(contributingId)) {
+                // adding to another action set, validate the id
+                if (!isValidCoolItemId(toolBarId, window)) {
+                    // toolbarid not valid, add the item to the coolitem for its action set
+                    toolBarId = contributingId;
+                } else {
+                    adjunctActions.add(ad);
+                    return;
+                }
+            }
+
+            // Create the action
+            PluginAction action = ad.getAction();
+            ActionContributionItem actionContribution = new PluginActionCoolBarContributionItem(
+                    action);
+            actionContribution.setMode(ad.getMode());
+
+            // retreive the toolbar from the action bars.
+            IToolBarManager toolBar = bars.getToolBarManager(toolBarId);
+
+            // Check to see if the group already exists
+            IContributionItem groupMarker = toolBar.find(toolGroupId);
+            // Add a group marker if one does not exist
+            if (groupMarker == null) {
+                // @issue should this be a GroupMarker?
+                toolBar.add(new Separator(toolGroupId));
+            }
+            toolBar.prependToGroup(toolGroupId, actionContribution);
+            toolBar.update(false);
+
+        }
+
+        /**
+         * Checks to see if the cool item id is in the given window.
+         */
+        private boolean isValidCoolItemId(String id, WorkbenchWindow window) {
+            ActionSetRegistry registry = WorkbenchPlugin.getDefault()
+                    .getActionSetRegistry();
+            if (registry.findActionSet(id) != null) {
+				return true;
+			}
+            if (window != null) {
+                return window.isWorkbenchCoolItemId(id);
+            }
+            return false;
+        }
+
+        /* (non-Javadoc)
+         * Method declared on Basic Contribution.
+         */
+        protected void insertMenuGroup(IMenuManager menu,
+                AbstractGroupMarker marker) {
+            if (actionSetId != null) {
+                IContributionItem[] items = menu.getItems();
+                // Loop thru all the current groups looking for the first
+                // group whose id > than the current action set id. Insert
+                // current marker just before this item then.
+                for (int i = 0; i < items.length; i++) {
+                    IContributionItem item = items[i];
+                    if (item.isSeparator() || item.isGroupMarker()) {
+                        if (item instanceof IActionSetContributionItem) {
+                            String testId = ((IActionSetContributionItem) item)
+                                    .getActionSetId();
+                            if (actionSetId.compareTo(testId) < 0) {
+                                menu.insertBefore(items[i].getId(), marker);
+                                return;
+                            }
+                        }
+                    }
+                }
+            }
+
+            menu.add(marker);
+        }
+
+        private IContributionItem findAlphabeticalOrder(String startId,
+                String itemId, IContributionManager mgr) {
+            IContributionItem[] items = mgr.getItems();
+            int insertIndex = 0;
+
+            // look for starting point
+            while (insertIndex < items.length) {
+                IContributionItem item = items[insertIndex];
+                if (startId != null && startId.equals(item.getId())) {
+					break;
+				}
+                ++insertIndex;
+            }
+
+            // Find the index that this item should be inserted in
+            for (int i = insertIndex + 1; i < items.length; i++) {
+                IContributionItem item = items[i];
+                if (item.isGroupMarker()) {
+					break;
+				}
+
+                String testId = null;
+                if (item instanceof PluginActionCoolBarContributionItem) {
+                    testId = ((PluginActionCoolBarContributionItem) item)
+                            .getActionSetId();
+                }
+                if (testId == null) {
+                    break;
+                }
+
+                if (itemId != null && testId != null) {
+                    if (itemId.compareTo(testId) < 1) {
+						break;
+					}
+                }
+                insertIndex = i;
+            }
+            if (insertIndex >= items.length) {
+                return null;
+            }
+            return items[insertIndex];
+        }
+
+        /**
+         * Returns whether the contributor is an adjunct contributor.
+         * 
+         * @return whether the contributor is an adjunct contributor
+         */
+        public boolean isAdjunctContributor() {
+            return adjunctActions.size() > 0;
+        }
+
+        /* (non-Javadoc)
+         * Method declared on Basic Contribution.
+         */
+        protected void insertAfter(IContributionManager mgr, String refId,
+                IContributionItem item) {
+            IContributionItem refItem = findInsertionPoint(refId, actionSetId,
+                    mgr, true);
+            if (refItem != null) {
+                mgr.insertAfter(refItem.getId(), item);
+            } else {
+                WorkbenchPlugin
+                        .log("Reference item " + refId + " not found for action " + item.getId()); //$NON-NLS-1$ //$NON-NLS-2$
+            }
+        }
+
+        //for dynamic UI
+        protected void revokeContribution(WorkbenchWindow window,
+                IActionBars bars, String id) {
+            revokeActionSetFromMenu(window.getMenuManager(), id);
+            //			IMenuManager menuMgr = bars.getMenuManager();
+            //			if (menuMgr != null) 
+            //				revokeActionSetFromMenu(menuMgr, id);
+
+            revokeActionSetFromCoolbar(window.getCoolBarManager2(), id);
+            //			IToolBarManager toolBarMgr = bars.getToolBarManager();
+            //			if (toolBarMgr != null && toolBarMgr instanceof CoolItemToolBarManager) 
+            //				revokeActionSetFromToolbar(toolBarMgr, id);
+        }
+
+        //for dynamic UI
+        protected void revokeAdjunctCoolbarAction(ActionDescriptor ad,
+                ActionSetActionBars bars) {
+            String toolBarId = ad.getToolbarId();
+//            String toolGroupId = ad.getToolbarGroupId();
+//
+//            String contributingId = bars.getActionSetId();
+            ICoolBarManager coolBarMgr = bars.getCoolBarManager();
+            //				((CoolItemToolBarManager)bars.getToolBarManager()).getParentManager();
+            PluginAction action = ad.getAction();
+            PluginActionCoolBarContributionItem actionContribution = new PluginActionCoolBarContributionItem(
+                    action);
+            actionContribution.setMode(ad.getMode());
+
+            bars.removeAdjunctContribution(actionContribution);
+
+            // remove a coolitem for the toolbar id if it exists 			
+            IContributionItem cbItem = coolBarMgr.find(toolBarId);
+            if (cbItem != null) {
+				coolBarMgr.remove(cbItem);
+			}
+
+            //			activeManager = cbItem.getToolBarManager();	
+            //			activeManager.remove(contributingId);	
+            //			IContributionItem groupMarker = activeManager.find(toolGroupId);
+            //			if (groupMarker != null) {
+            //				int idx = activeManager.indexOf(toolGroupId);
+            //				IContributionItem[] items = activeManager.getItems();
+            //				if (items.length == idx+1 || 
+            //						((items.length > idx && items[idx+1] instanceof Separator)))
+            //					if (activeManager.find(toolGroupId) != null)
+            //						activeManager.remove(toolGroupId);
+            //			} 			
+            //			activeManager.addAdjunctItemToGroup(toolGroupId, contributingId, actionContribution);		 
+        }
+
+        //for dynamic UI
+        private void revokeActionSetFromMenu(IMenuManager menuMgr,
+                String actionsetId) {
+            IContributionItem[] items = menuMgr.getItems();
+            ArrayList itemsToRemove = new ArrayList();
+            String id;
+            for (int i = 0; i < items.length; i++) {
+				if (items[i] instanceof IMenuManager) {
+                    revokeActionSetFromMenu((IMenuManager) items[i],
+                            actionsetId);
+                } else if (items[i] instanceof ActionSetContributionItem) {
+                    id = ((ActionSetContributionItem) items[i])
+                            .getActionSetId();
+                    if (actionsetId.equals(id)) {
+						itemsToRemove.add(items[i]);
+					}
+                } else if (items[i] instanceof Separator) {
+                    id = ((Separator) items[i]).getId();
+                    if (actionsetId.equals(id)) {
+						itemsToRemove.add(items[i]);
+					}
+                } else if (items[i] instanceof GroupMarker) {
+                    id = ((GroupMarker) items[i]).getId();
+                    if (actionsetId.equals(id)) {
+						itemsToRemove.add(items[i]);
+					}
+                }
+			}
+            Iterator iter = itemsToRemove.iterator();
+            while (iter.hasNext()) {
+                IContributionItem item = (IContributionItem) iter.next();
+                menuMgr.remove(item);
+            }
+            menuMgr.update(true);
+        }
+
+        // for dynamic UI
+        private void revokeActionSetFromCoolbar(ICoolBarManager coolbarMgr,
+                String actionsetId) {
+            IContributionItem[] items = coolbarMgr.getItems();
+            ArrayList itemsToRemove = new ArrayList();
+            String id;
+            for (int i = 0; i < items.length; i++) {
+                id = items[i].getId();
+                if (actionsetId.equals(id)) {
+                    itemsToRemove.add(items[i]);
+                    continue;
+                }
+                if (items[i] instanceof IToolBarManager) {
+                    revokeActionSetFromToolbar((IToolBarManager) items[i],
+                            actionsetId);
+                } else if (items[i] instanceof IToolBarContributionItem) {
+                    id = ((IToolBarContributionItem) items[i]).getId();
+                    if (actionsetId.equals(id)) {
+						itemsToRemove.add(items[i]);
+					}
+                } else if (items[i] instanceof GroupMarker) {
+                    id = ((GroupMarker) items[i]).getId();
+                    if (actionsetId.equals(id)) {
+						itemsToRemove.add(items[i]);
+					}
+                }
+            }
+            Iterator iter = itemsToRemove.iterator();
+            while (iter.hasNext()) {
+				coolbarMgr.remove((IContributionItem) iter.next());
+			}
+            coolbarMgr.update(true);
+        }
+
+        // for dynamic UI
+        private void revokeActionSetFromToolbar(IToolBarManager toolbarMgr,
+                String actionsetId) {
+            IContributionItem[] items = toolbarMgr.getItems();
+            ArrayList itemsToRemove = new ArrayList();
+            String id;
+            for (int i = 0; i < items.length; i++) {
+                id = items[i].getId();
+                if (id.equals(actionsetId)) {
+                    itemsToRemove.add(items[i]);
+                    continue;
+                }
+                if (items[i] instanceof PluginActionCoolBarContributionItem) {
+                    id = ((PluginActionCoolBarContributionItem) items[i])
+                            .getActionSetId();
+                    if (actionsetId.equals(id)) {
+						itemsToRemove.add(items[i]);
+					}
+                } else if (items[i] instanceof ActionContributionItem) {
+                    id = ((ActionContributionItem) items[i]).getId();
+                    if (actionsetId.equals(id)) {
+						itemsToRemove.add(items[i]);
+					}
+                } else if (items[i] instanceof GroupMarker) {
+                    id = ((GroupMarker) items[i]).getId();
+                    if (actionsetId.equals(id)) {
+						itemsToRemove.add(items[i]);
+					}
+                }
+            }
+            Iterator iter = itemsToRemove.iterator();
+            while (iter.hasNext()) {
+				toolbarMgr.remove((IContributionItem) iter.next());
+			}
+            toolbarMgr.update(true);
+        }
+    }
+
+
+    /**
+     * Remove the given action set from the window.
+     * 
+     * @param set the set to remove
+     * @param window the window to remove from
+     */
+    protected void removeActionExtensions(PluginActionSet set,
+            IWorkbenchWindow window) {
+        this.actionSet = set;
+        this.window = window;
+        currentContribution = null;
+        targetID = null;
+        targetContributionTag = IWorkbenchRegistryConstants.TAG_ACTION_SET;
+        String id = set.getDesc().getId();
+        
+        if (cache != null) {
+            for (int i = 0; i < cache.size(); i++) {
+                ActionSetContribution contribution = (ActionSetContribution) cache
+                        .get(i);
+                contribution.revokeContribution((WorkbenchWindow) window,
+                        actionSet.getBars(), id);
+                if (contribution.isAdjunctContributor()) {
+                    for (int j = 0; j < contribution.adjunctActions.size(); j++) {
+                        ActionDescriptor adjunctAction = (ActionDescriptor) contribution.adjunctActions
+                                .get(j);
+                        contribution.revokeAdjunctCoolbarAction(adjunctAction,
+                                actionSet.getBars());
+                    }
+                }
+            }
+        }
+    }
+}
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchPage.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchPage.java
index 81f81ff..e06e469 100644
--- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchPage.java
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchPage.java
@@ -130,6 +130,7 @@
 import org.eclipse.ui.internal.menus.MenuHelper;
 import org.eclipse.ui.internal.misc.ExternalEditor;
 import org.eclipse.ui.internal.misc.UIListenerLogging;
+import org.eclipse.ui.internal.registry.ActionSetRegistry;
 import org.eclipse.ui.internal.registry.EditorDescriptor;
 import org.eclipse.ui.internal.registry.IActionSetDescriptor;
 import org.eclipse.ui.internal.registry.IWorkbenchRegistryConstants;
@@ -213,8 +214,8 @@
 	private MPerspectiveStack _perspectiveStack;
 
 	/**
-	 * Deactivate the last editor's action bars if another type of editor has
-	 * been activated.
+	 * Deactivate the last editor's action bars if another type of editor has //
+	 * * been activated.
 	 * 
 	 * @param part
 	 *            the part that is being activated
@@ -269,9 +270,7 @@
 		((WorkbenchWindow) getWorkbenchWindow()).getStatusLineManager().update(false);
 
 		IWorkbenchPart workbenchPart = getWorkbenchPart(part);
-		if (workbenchPart instanceof IEditorPart) {
-			navigationHistory.markEditor((IEditorPart) workbenchPart);
-		}
+		actionSwitcher.updateActivePart(workbenchPart);
 	}
 
 	private void updateActivePartSources(MPart part) {
@@ -288,75 +287,46 @@
 
 	}
 
-	/**
-	 * Calculates the action sets to show for the given part and editor
-	 * 
-	 * @param part
-	 *            the active part, may be <code>null</code>
-	 * @param editor
-	 *            the current editor, may be <code>null</code>, may be the
-	 *            active part
-	 * @return the action sets that are applicable to the given part and editor
-	 */
-	private ArrayList<IActionSetDescriptor> calculateActionSets(IWorkbenchPart part,
-			IEditorPart editor) {
-		ArrayList<IActionSetDescriptor> newActionSets = new ArrayList<IActionSetDescriptor>();
-		if (part != null) {
-			IActionSetDescriptor[] partActionSets = WorkbenchPlugin.getDefault()
-					.getActionSetRegistry().getActionSetsFor(part.getSite().getId());
-			for (IActionSetDescriptor partActionSet : partActionSets) {
-				newActionSets.add(partActionSet);
-			}
-		}
-		if (editor != null && editor != part) {
-			IActionSetDescriptor[] editorActionSets = WorkbenchPlugin.getDefault()
-					.getActionSetRegistry().getActionSetsFor(editor.getSite().getId());
-			for (IActionSetDescriptor editorActionSet : editorActionSets) {
-				newActionSets.add(editorActionSet);
-			}
-		}
-		return newActionSets;
-	}
+	private void updateActionSets(Perspective oldPersp, Perspective newPersp) {
+		// Update action sets
 
-	/**
-	 * Updates the actions we are showing for the active part and current
-	 * editor.
-	 * 
-	 * @param newActionSets
-	 *            the action sets to show
-	 */
-	private void updateActionSets(ArrayList<IActionSetDescriptor> newActionSets) {
-		if (oldActionSets.equals(newActionSets)) {
-			return;
-		}
-
-		WorkbenchWindow workbenchWindow = (WorkbenchWindow) getWorkbenchWindow();
-		IContextService service = (IContextService) workbenchWindow
-				.getService(
-				IContextService.class);
+		IContextService service = (IContextService) legacyWindow.getService(IContextService.class);
 		try {
 			service.deferUpdates(true);
+			if (newPersp != null) {
+				IActionSetDescriptor[] newAlwaysOn = newPersp.getAlwaysOnActionSets();
+				for (int i = 0; i < newAlwaysOn.length; i++) {
+					IActionSetDescriptor descriptor = newAlwaysOn[i];
 
-			// show the new
-			for (IActionSetDescriptor newActionSet : newActionSets) {
-				actionSets.showAction(newActionSet);
+					actionSets.showAction(descriptor);
+				}
+
+				IActionSetDescriptor[] newAlwaysOff = newPersp.getAlwaysOffActionSets();
+				for (int i = 0; i < newAlwaysOff.length; i++) {
+					IActionSetDescriptor descriptor = newAlwaysOff[i];
+
+					actionSets.maskAction(descriptor);
+				}
 			}
 
-			// hide the old
-			for (IActionSetDescriptor oldActionSet : oldActionSets) {
-				actionSets.hideAction(oldActionSet);
-			}
+			if (oldPersp != null) {
+				IActionSetDescriptor[] newAlwaysOn = oldPersp.getAlwaysOnActionSets();
+				for (int i = 0; i < newAlwaysOn.length; i++) {
+					IActionSetDescriptor descriptor = newAlwaysOn[i];
 
-			oldActionSets = newActionSets;
+					actionSets.hideAction(descriptor);
+				}
+
+				IActionSetDescriptor[] newAlwaysOff = oldPersp.getAlwaysOffActionSets();
+				for (int i = 0; i < newAlwaysOff.length; i++) {
+					IActionSetDescriptor descriptor = newAlwaysOff[i];
+
+					actionSets.unmaskAction(descriptor);
+				}
+			}
 		} finally {
 			service.deferUpdates(false);
 		}
-
-		if (getPerspective() != null) {
-			workbenchWindow.updateActionSets();
-			workbenchWindow.firePerspectiveChanged(WorkbenchPage.this, getPerspective(),
-					CHANGE_ACTION_SET_SHOW);
-		}
 	}
 
 	private IWorkbenchPart getWorkbenchPart(MPart part) {
@@ -377,7 +347,10 @@
 		window.getContext().set(ISources.ACTIVE_EDITOR_INPUT_NAME,
 				editor == null ? null : editor.getEditorInput());
 
-		updateActionSets(calculateActionSets(getWorkbenchPart(part), editor));
+		if (editor != null) {
+			navigationHistory.markEditor(editor);
+		}
+		actionSwitcher.updateTopEditor(editor);
 	}
 
 	public void updateShowInSources(MPart part) {
@@ -517,11 +490,6 @@
     
     private ActionSetManager actionSets;
 
-    /**
-     * The action sets that were last requested to be shown.
-     */
-	private ArrayList<IActionSetDescriptor> oldActionSets = new ArrayList<IActionSetDescriptor>();
-
     private NavigationHistory navigationHistory = new NavigationHistory(this);
     
 
@@ -553,6 +521,7 @@
         }
     };
 
+	private ActionSwitcher actionSwitcher = new ActionSwitcher();
 
 	private IExtensionTracker tracker;
     
@@ -563,6 +532,256 @@
 	private IWorkingSet[] workingSets = new IWorkingSet[0];
 	private String aggregateWorkingSetId;
 
+	/**
+	 * Manages editor contributions and action set part associations.
+	 */
+	private class ActionSwitcher {
+		private IWorkbenchPart activePart;
+
+		private IEditorPart topEditor;
+
+		private ArrayList oldActionSets = new ArrayList();
+
+		/**
+		 * Updates the contributions given the new part as the active part.
+		 * 
+		 * @param newPart
+		 *            the new active part, may be <code>null</code>
+		 */
+		public void updateActivePart(IWorkbenchPart newPart) {
+			if (activePart == newPart) {
+				return;
+			}
+
+			boolean isNewPartAnEditor = newPart instanceof IEditorPart;
+			if (isNewPartAnEditor) {
+				String oldId = null;
+				if (topEditor != null) {
+					oldId = topEditor.getSite().getId();
+				}
+				String newId = newPart.getSite().getId();
+
+				// if the active part is an editor and the new editor
+				// is the same kind of editor, then we don't have to do
+				// anything
+				if (activePart == topEditor && newId.equals(oldId)) {
+					activePart = newPart;
+					topEditor = (IEditorPart) newPart;
+					return;
+				}
+
+				// remove the contributions of the old editor
+				// if it is a different kind of editor
+				if (oldId != null && !oldId.equals(newId)) {
+					deactivateContributions(topEditor, true);
+				}
+
+				// if a view was the active part, disable its contributions
+				if (activePart != null && activePart != topEditor) {
+					deactivateContributions(activePart, true);
+				}
+
+				// show (and enable) the contributions of the new editor
+				// if it is a different kind of editor or if the
+				// old active part was a view
+				if (!newId.equals(oldId) || activePart != topEditor) {
+					activateContributions(newPart, true);
+				}
+
+			} else if (newPart == null) {
+				if (activePart != null) {
+					// remove all contributions
+					deactivateContributions(activePart, true);
+				}
+			} else {
+				// new part is a view
+
+				// if old active part is a view, remove all contributions,
+				// but if old part is an editor only disable
+				if (activePart != null) {
+					deactivateContributions(activePart, activePart instanceof IViewPart);
+				}
+
+				activateContributions(newPart, true);
+			}
+
+			ArrayList newActionSets = null;
+			if (isNewPartAnEditor || (activePart == topEditor && newPart == null)) {
+				newActionSets = calculateActionSets(newPart, null);
+			} else {
+				newActionSets = calculateActionSets(newPart, topEditor);
+			}
+
+			if (!updateActionSets(newActionSets)) {
+				updateActionBars();
+			}
+
+			if (isNewPartAnEditor) {
+				topEditor = (IEditorPart) newPart;
+			} else if (activePart == topEditor && newPart == null) {
+				// since we removed all the contributions, we clear the top
+				// editor
+				topEditor = null;
+			}
+
+			activePart = newPart;
+		}
+
+		/**
+		 * Updates the contributions given the new part as the topEditor.
+		 * 
+		 * @param newEditor
+		 *            the new top editor, may be <code>null</code>
+		 */
+		public void updateTopEditor(IEditorPart newEditor) {
+			if (topEditor == newEditor) {
+				return;
+			}
+
+			if (activePart == topEditor) {
+				updateActivePart(newEditor);
+				return;
+			}
+
+			String oldId = null;
+			if (topEditor != null) {
+				oldId = topEditor.getSite().getId();
+			}
+			String newId = null;
+			if (newEditor != null) {
+				newId = newEditor.getSite().getId();
+			}
+			if (oldId == null ? newId == null : oldId.equals(newId)) {
+				// we don't have to change anything
+				topEditor = newEditor;
+				return;
+			}
+
+			// Remove the contributions of the old editor
+			if (topEditor != null) {
+				deactivateContributions(topEditor, true);
+			}
+
+			// Show (disabled) the contributions of the new editor
+			if (newEditor != null) {
+				activateContributions(newEditor, false);
+			}
+
+			ArrayList newActionSets = calculateActionSets(activePart, newEditor);
+			if (!updateActionSets(newActionSets)) {
+				updateActionBars();
+			}
+
+			topEditor = newEditor;
+		}
+
+		/**
+		 * Activates the contributions of the given part. If <code>enable</code>
+		 * is <code>true</code> the contributions are visible and enabled,
+		 * otherwise they are disabled.
+		 * 
+		 * @param part
+		 *            the part whose contributions are to be activated
+		 * @param enable
+		 *            <code>true</code> the contributions are to be enabled, not
+		 *            just visible.
+		 */
+		private void activateContributions(IWorkbenchPart part, boolean enable) {
+			PartSite site = (PartSite) part.getSite();
+			site.activateActionBars(enable);
+		}
+
+		/**
+		 * Deactivates the contributions of the given part. If
+		 * <code>remove</code> is <code>true</code> the contributions are
+		 * removed, otherwise they are disabled.
+		 * 
+		 * @param part
+		 *            the part whose contributions are to be deactivated
+		 * @param remove
+		 *            <code>true</code> the contributions are to be removed, not
+		 *            just disabled.
+		 */
+		private void deactivateContributions(IWorkbenchPart part, boolean remove) {
+			PartSite site = (PartSite) part.getSite();
+			site.deactivateActionBars(remove);
+		}
+
+		/**
+		 * Calculates the action sets to show for the given part and editor
+		 * 
+		 * @param part
+		 *            the active part, may be <code>null</code>
+		 * @param editor
+		 *            the current editor, may be <code>null</code>, may be the
+		 *            active part
+		 * @return the new action sets
+		 */
+		private ArrayList calculateActionSets(IWorkbenchPart part, IEditorPart editor) {
+			ArrayList newActionSets = new ArrayList();
+			if (part != null) {
+				IActionSetDescriptor[] partActionSets = WorkbenchPlugin.getDefault()
+						.getActionSetRegistry().getActionSetsFor(part.getSite().getId());
+				for (int i = 0; i < partActionSets.length; i++) {
+					newActionSets.add(partActionSets[i]);
+				}
+			}
+			if (editor != null && editor != part) {
+				IActionSetDescriptor[] editorActionSets = WorkbenchPlugin.getDefault()
+						.getActionSetRegistry().getActionSetsFor(editor.getSite().getId());
+				for (int i = 0; i < editorActionSets.length; i++) {
+					newActionSets.add(editorActionSets[i]);
+				}
+			}
+			return newActionSets;
+		}
+
+		/**
+		 * Updates the actions we are showing for the active part and current
+		 * editor.
+		 * 
+		 * @param newActionSets
+		 *            the action sets to show
+		 * @return <code>true</code> if the action sets changed
+		 */
+		private boolean updateActionSets(ArrayList newActionSets) {
+			if (oldActionSets.equals(newActionSets)) {
+				return false;
+			}
+
+			IContextService service = (IContextService) legacyWindow
+					.getService(IContextService.class);
+			try {
+				service.deferUpdates(true);
+
+				// show the new
+				for (int i = 0; i < newActionSets.size(); i++) {
+					actionSets.showAction((IActionSetDescriptor) newActionSets.get(i));
+				}
+
+				// hide the old
+				for (int i = 0; i < oldActionSets.size(); i++) {
+					actionSets.hideAction((IActionSetDescriptor) oldActionSets.get(i));
+				}
+
+				oldActionSets = newActionSets;
+
+			} finally {
+				service.deferUpdates(false);
+			}
+			Perspective persp = getActivePerspective();
+			if (persp == null) {
+				return false;
+			}
+
+			legacyWindow.updateActionSets(); // this calls updateActionBars
+			legacyWindow.firePerspectiveChanged(WorkbenchPage.this, getPerspective(),
+					CHANGE_ACTION_SET_SHOW);
+			return true;
+		}
+
+	}
+
 	private EPartService partService;
 
 	private MApplication application;
@@ -638,6 +857,7 @@
 		MPart mpart = findPart(part);
 		if (mpart != null) {
 			partService.activate(mpart);
+			actionSwitcher.updateActivePart(part);
 		}
 	}
 
@@ -989,11 +1209,19 @@
 		switch (mode) {
 		case VIEW_ACTIVATE:
 			partService.showPart(part, PartState.ACTIVATE);
+			if (part.getObject() instanceof CompatibilityView) {
+				CompatibilityView compatibilityView = (CompatibilityView) part.getObject();
+				actionSwitcher.updateActivePart(compatibilityView.getPart());
+			}
 			break;
 		case VIEW_VISIBLE:
 			MPart activePart = partService.getActivePart();
 			if (activePart == null) {
 				partService.showPart(part, PartState.ACTIVATE);
+				if (part.getObject() instanceof CompatibilityView) {
+					CompatibilityView compatibilityView = (CompatibilityView) part.getObject();
+					actionSwitcher.updateActivePart(compatibilityView.getPart());
+				}
 			} else {
 				part = ((PartServiceImpl) partService).addPart(part);
 				MPlaceholder activePlaceholder = activePart.getCurSharedRef();
@@ -1408,6 +1636,7 @@
 				}
 			}
 			modelService.removePerspectiveModel(persp, window);
+			modelToPerspectiveMapping.remove(persp);
 		}
 	}
 
@@ -1471,6 +1700,7 @@
 		viewReferences.clear();
 		editorReferences.clear();
 		sortedPerspectives.clear();
+		modelToPerspectiveMapping.clear();
 
 		if (unsetPage) {
 			legacyWindow.setActivePage(null);
@@ -2157,9 +2387,12 @@
 		MPerspective curPersp = ps.getSelectedElement();
 		if (curPersp == null)
 			return null;
+		return getPerspectiveDesc(curPersp.getElementId());
+	}
 
+	public IPerspectiveDescriptor getPerspectiveDesc(String id) {
 		IPerspectiveDescriptor desc = PlatformUI.getWorkbench().getPerspectiveRegistry()
-				.findPerspectiveWithId(curPersp.getElementId());
+				.findPerspectiveWithId(id);
 		return desc;
 	}
 
@@ -2271,24 +2504,21 @@
      * @see IWorkbenchPage
      */
     public void hideActionSet(String actionSetID) {
-		MPerspective persp = getCurrentPerspective();
-		if (persp == null)
+		MPerspective mpersp = getCurrentPerspective();
+		if (mpersp == null)
 			return;
 
 		// Remove Tags
 		String tag = ModeledPageLayout.ACTION_SET_TAG + actionSetID;
-		if (persp.getTags().contains(tag)) {
-			persp.getTags().remove(tag);
-
-			// ActionSetManager does reference counting to determine visibility
-			// so don't add action sets that have already been added
-			IActionSetDescriptor descriptor = WorkbenchPlugin.getDefault().getActionSetRegistry()
-					.findActionSet(actionSetID);
-			if (descriptor != null) {
-				actionSets.hideAction(descriptor);
-			}
+		if (mpersp.getTags().contains(tag)) {
+			mpersp.getTags().remove(tag);
 		}
-
+		Perspective persp = getActivePerspective();
+		if (persp != null) {
+			persp.removeActionSet(actionSetID);
+			legacyWindow.updateActionSets();
+			legacyWindow.firePerspectiveChanged(this, getPerspective(), CHANGE_ACTION_SET_HIDE);
+		}
 		addHiddenItems(tag);
     }
 
@@ -2337,7 +2567,7 @@
 		this.legacyWindow = w;
         this.input = input;
         actionSets = new ActionSetManager(w);
-
+		initActionSetListener();
 	}
 
 	@PostConstruct
@@ -2445,6 +2675,23 @@
 		}
 	}
 
+	ArrayList getPerspectiveExtensionActionSets(String id) {
+		IPerspectiveDescriptor desc = getWorkbenchWindow().getWorkbench().getPerspectiveRegistry()
+				.findPerspectiveWithId(id);
+		if (desc != null) {
+			MPerspective temporary = AdvancedFactoryImpl.eINSTANCE.createPerspective();
+			ModeledPageLayout modelLayout = new ModeledPageLayout(window, modelService,
+					partService, temporary, desc, this, true);
+
+			PerspectiveExtensionReader reader = new PerspectiveExtensionReader();
+			reader.setIncludeOnlyTags(new String[] { IWorkbenchRegistryConstants.TAG_ACTION_SET });
+			reader.extendLayout(null, id, modelLayout);
+			return new ArrayList(ModeledPageLayout.getIds(temporary,
+					ModeledPageLayout.ACTION_SET_TAG));
+		}
+		return null;
+	}
+
 	/**
 	 * Copies action set extensions from the temporary perspective to the other
 	 * one.
@@ -2513,10 +2760,11 @@
 
 			MPerspective oldPersp = (MPerspective) event.getProperty(UIEvents.EventTags.OLD_VALUE);
 			MPerspective newPersp = (MPerspective) event.getProperty(UIEvents.EventTags.NEW_VALUE);
-			updatePerspectiveActionSets(oldPersp, newPersp);
+			// updatePerspectiveActionSets(oldPersp, newPersp);
 
-			((CoolBarToTrimManager) legacyWindow.getCoolBarManager2()).updateAll(true);
-			legacyWindow.menuManager.updateAll(true);
+			// ((CoolBarToTrimManager)
+			// legacyWindow.getCoolBarManager2()).updateAll(true);
+			// legacyWindow.menuManager.updateAll(true);
 
 			List<MPart> hiddenParts = new ArrayList<MPart>();
 			List<MPart> visibleParts = new ArrayList<MPart>();
@@ -2560,17 +2808,18 @@
 				firePartVisible(visiblePart);
 			}
 
+			updateActionSets(getPerspective(oldPersp), getPerspective(newPersp));
+
 			// might've been set to null if we were closing the perspective
 			if (newPersp != null) {
-				IPerspectiveRegistry registry = getWorkbenchWindow().getWorkbench()
-						.getPerspectiveRegistry();
-				IPerspectiveDescriptor perspective = registry.findPerspectiveWithId(newPersp
+				IPerspectiveDescriptor perspective = getPerspectiveDesc(newPersp
 						.getElementId());
 				legacyWindow.firePerspectiveActivated(WorkbenchPage.this, perspective);
 
 				sortedPerspectives.remove(perspective);
 				sortedPerspectives.add(perspective);
 			}
+			legacyWindow.updateActionSets();
 		}
 	};
 
@@ -3021,6 +3270,7 @@
 		if (dummyPerspective == null) {
 			// instantiate a dummy perspective perspective
 			dummyPerspective = AdvancedFactoryImpl.eINSTANCE.createPerspective();
+			dummyPerspective.setElementId(persp.getElementId());
 
 			IPerspectiveFactory factory = ((PerspectiveDescriptor) desc).createFactory();
 			ModeledPageLayout modelLayout = new ModeledPageLayout(window, modelService,
@@ -3035,9 +3285,10 @@
 		String hiddenItems = dummyPerspective.getPersistedState().get(ModeledPageLayout.HIDDEN_ITEMS_KEY);
 		persp.getPersistedState().put(ModeledPageLayout.HIDDEN_ITEMS_KEY, hiddenItems);
 		
-		legacyWindow.getMenuManager().updateAll(true);
-		((ICoolBarManager2) ((WorkbenchWindow) getWorkbenchWindow()).getCoolBarManager2())
-				.resetItemOrder();
+		// legacyWindow.getMenuManager().updateAll(true);
+		// ((ICoolBarManager2) ((WorkbenchWindow)
+		// getWorkbenchWindow()).getCoolBarManager2())
+		// .resetItemOrder();
 
 		// Hide placeholders for parts that exist in the 'global' areas
 		modelService.hideLocalPlaceholders(window, dummyPerspective);
@@ -3070,7 +3321,8 @@
 		}
 
 		// deactivate and activate other action sets as
-		updatePerspectiveActionSets(persp, dummyPerspective);
+		updateActionSets(getPerspective(persp), getPerspective(dummyPerspective));
+		modelToPerspectiveMapping.remove(dummyPerspective);
 
 		// migrate the tags
 		List<String> tags = persp.getTags();
@@ -3083,44 +3335,27 @@
 		legacyWindow.firePerspectiveChanged(this, desc, CHANGE_RESET_COMPLETE);
 	}
 
-	private void updatePerspectiveActionSets(MPerspective currentPerspective,
-			MPerspective newPerspective) {
-		List<String> oldTemp = ModeledPageLayout.getIds(currentPerspective,
-				ModeledPageLayout.ACTION_SET_TAG);
-		List<String> newTemp = ModeledPageLayout.getIds(newPerspective,
-				ModeledPageLayout.ACTION_SET_TAG);
-
-		// remove action sets that are visible in both perspectives so that a
-		// unique set is created
-		List<String> oldActionSets = new ArrayList<String>(oldTemp);
-		oldActionSets.removeAll(newTemp);
-		List<String> newActionSets = new ArrayList<String>(newTemp);
-		newActionSets.removeAll(oldTemp);
-
-		IContextService contextService = window.getContext().get(IContextService.class);
-		try {
-			contextService.deferUpdates(true);
-
-			// deactivate action sets that are no longer valid
-			for (String oldId : oldActionSets) {
-				IActionSetDescriptor actionSet = WorkbenchPlugin.getDefault()
-						.getActionSetRegistry().findActionSet(oldId);
-				if (actionSet != null) {
-					actionSets.hideAction(actionSet);
-				}
-			}
-
-			// activate the new ones
-			for (String newId : newActionSets) {
-				IActionSetDescriptor actionSet = WorkbenchPlugin.getDefault()
-						.getActionSetRegistry().findActionSet(newId);
-				if (actionSet != null) {
-					actionSets.showAction(actionSet);
-				}
-			}
-		} finally {
-			contextService.deferUpdates(false);
-		}
+	private void initActionSetListener() {
+		// actionSets.addListener(new IPropertyListener() {
+		// public void propertyChanged(Object source, int propId) {
+		// if (source instanceof IActionSetDescriptor) {
+		// final IActionSetDescriptor desc = (IActionSetDescriptor) source;
+		// final String actionSetId = ModeledPageLayout.ACTION_SET_TAG +
+		// desc.getId();
+		// final MPerspective currentPerspective = getCurrentPerspective();
+		// if (currentPerspective != null) {
+		// final List<String> tags = currentPerspective.getTags();
+		// if (propId == ActionSetManager.PROP_VISIBLE) {
+		// if (!tags.contains(actionSetId)) {
+		// tags.add(actionSetId);
+		// }
+		// } else if (propId == ActionSetManager.PROP_HIDDEN) {
+		// tags.remove(actionSetId);
+		// }
+		// }
+		// }
+		// }
+		// });
 	}
 
     /**
@@ -3285,6 +3520,22 @@
 		}
 	}
 
+	private HashMap<MPerspective, Perspective> modelToPerspectiveMapping = new HashMap<MPerspective, Perspective>();
+
+	private Perspective getPerspective(MPerspective mperspective) {
+		if (mperspective == null) {
+			return null;
+		}
+		if (!modelToPerspectiveMapping.containsKey(mperspective)) {
+			Perspective p = new Perspective(
+					(PerspectiveDescriptor) getPerspectiveDesc(mperspective.getElementId()),
+					mperspective, this);
+			modelToPerspectiveMapping.put(mperspective, p);
+			p.initActionSets();
+		}
+		return modelToPerspectiveMapping.get(mperspective);
+	}
+
 	/*
 	 * (non-Javadoc)
 	 * 
@@ -3312,7 +3563,6 @@
 				// this perspective already exists, switch to this one
 				perspectives.setSelectedElement(mperspective);
 				mperspective.getContext().activate();
-				legacyWindow.firePerspectiveActivated(this, perspective);
 				return;
 			}
 		}
@@ -3357,12 +3607,19 @@
 		perspectives.getChildren().add(modelPerspective);
 		// activate it
 		perspectives.setSelectedElement(modelPerspective);
+
 		modelPerspective.getContext().activate();
-		legacyWindow.firePerspectiveActivated(this, perspective);
 
 		UIEvents.publishEvent(UIEvents.UILifeCycle.PERSPECTIVE_OPENED, modelPerspective);
 	}
 
+	void perspectiveActionSetChanged(Perspective perspective, IActionSetDescriptor descriptor,
+			int changeType) {
+		if (perspective == getActivePerspective()) {
+			actionSets.change(descriptor, changeType);
+		}
+	}
+
 
 	/**
 	 * Retrieves the perspective stack of the window that's containing this
@@ -3448,26 +3705,19 @@
      * @see IWorkbenchPage
      */
     public void showActionSet(String actionSetID) {
-		MPerspective persp = getPerspectiveStack().getSelectedElement();
-		if (persp == null) {
-			return;
-		}
-
-		// Add Tags
-		String tag = ModeledPageLayout.ACTION_SET_TAG + actionSetID;
-		if (!persp.getTags().contains(tag)) {
-			persp.getTags().add(tag);
-
-			// ActionSetManager does reference counting to determine visibility
-			// so don't add action sets that have already been added
-			IActionSetDescriptor descriptor = WorkbenchPlugin.getDefault().getActionSetRegistry()
-					.findActionSet(actionSetID);
-			if (descriptor != null) {
-				actionSets.showAction(descriptor);
-			}
-		}
-
-		removeHiddenItems(tag);
+    	 Perspective persp = getActivePerspective();
+         if (persp != null) {
+             ActionSetRegistry reg = WorkbenchPlugin.getDefault()
+                  .getActionSetRegistry();
+             
+             IActionSetDescriptor desc = reg.findActionSet(actionSetID);
+             if (desc != null) {
+                 persp.addActionSet(desc);
+                 legacyWindow.updateActionSets();
+                 legacyWindow.firePerspectiveChanged(this, getPerspective(),
+                         CHANGE_ACTION_SET_SHOW);
+             }
+         }
     }
 
     /**
@@ -3701,6 +3951,10 @@
 		return stack == null ? null : stack.getSelectedElement();
 	}
 
+	Perspective getActivePerspective() {
+		return getPerspective(getCurrentPerspective());
+	}
+
     /*
      * (non-Javadoc)
      * 
@@ -3982,7 +4236,7 @@
 	}
 
 	void updatePerspectiveActionSets() {
-		updatePerspectiveActionSets(null, getPerspectiveStack().getSelectedElement());
+		updateActionSets(null, getActivePerspective());
 	}
 
 	void fireInitialPartVisibilityEvents() {
@@ -4503,4 +4757,12 @@
 		persp.getTags().removeAll(existingNewWizards);
 		persp.getTags().addAll(newWizards);
 	}
+
+	/**
+	 * 
+	 */
+	public void resetToolBarLayout() {
+		ICoolBarManager2 mgr = (ICoolBarManager2) legacyWindow.getCoolBarManager2();
+		mgr.resetItemOrder();
+	}
 }
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchWindow.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchWindow.java
index c9fe156..be5971f 100644
--- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchWindow.java
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchWindow.java
@@ -74,7 +74,6 @@
 import org.eclipse.e4.ui.workbench.renderers.swt.TrimBarLayout;
 import org.eclipse.e4.ui.workbench.swt.factories.IRendererFactory;
 import org.eclipse.jface.action.AbstractGroupMarker;
-import org.eclipse.jface.action.ActionContributionItem;
 import org.eclipse.jface.action.ContributionManager;
 import org.eclipse.jface.action.CoolBarManager;
 import org.eclipse.jface.action.GroupMarker;
@@ -89,6 +88,7 @@
 import org.eclipse.jface.commands.ActionHandler;
 import org.eclipse.jface.dialogs.IDialogConstants;
 import org.eclipse.jface.internal.provisional.action.CoolBarManager2;
+import org.eclipse.jface.internal.provisional.action.ICoolBarManager2;
 import org.eclipse.jface.internal.provisional.action.IToolBarManager2;
 import org.eclipse.jface.internal.provisional.action.ToolBarManager2;
 import org.eclipse.jface.operation.IRunnableWithProgress;
@@ -116,6 +116,7 @@
 import org.eclipse.ui.ISelectionService;
 import org.eclipse.ui.ISources;
 import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchActionConstants;
 import org.eclipse.ui.IWorkbenchPage;
 import org.eclipse.ui.IWorkbenchPart;
 import org.eclipse.ui.IWorkbenchPartReference;
@@ -153,6 +154,7 @@
 import org.eclipse.ui.internal.progress.ProgressRegion;
 import org.eclipse.ui.internal.provisional.application.IActionBarConfigurer2;
 import org.eclipse.ui.internal.provisional.presentations.IActionBarPresentationFactory;
+import org.eclipse.ui.internal.registry.IActionSetDescriptor;
 import org.eclipse.ui.internal.registry.IWorkbenchRegistryConstants;
 import org.eclipse.ui.internal.registry.UIExtensionTracker;
 import org.eclipse.ui.internal.services.EvaluationReference;
@@ -536,12 +538,6 @@
 			}
 		}
 		page.setPerspective(perspective);
-		if (newWindow) {
-			page.fireInitialPartVisibilityEvents();
-		} else {
-			page.updatePerspectiveActionSets();
-		}
-		firePageActivated();
 
 		populateTopTrimContributions();
 		populateBottomTrimContributions();
@@ -600,7 +596,14 @@
 
 		eventBroker.subscribe(UIEvents.UIElement.TOPIC_WIDGET, windowWidgetHandler);
 
+		firePageActivated();
+		if (newWindow) {
+			page.fireInitialPartVisibilityEvents();
+		} else {
+			page.updatePerspectiveActionSets();
+		}
 		partService.setPage(page);
+		updateActionSets();
 
 		IPreferenceStore preferenceStore = PrefUtil.getAPIPreferenceStore();
 		boolean enableAnimations = preferenceStore
@@ -874,13 +877,6 @@
 				if (menuItem != null) {
 					menu.getChildren().add(menuItem);
 				}
-			} else if (item instanceof ActionContributionItem) {
-				MMenuItem menuItem = MenuHelper.createItem(application,
-						(ActionContributionItem) item);
-				manager.remove(item);
-				if (menuItem != null) {
-					menu.getChildren().add(menuItem);
-				}
 			} else if (item instanceof AbstractGroupMarker) {
 				MMenuSeparator separator = MenuFactoryImpl.eINSTANCE.createMenuSeparator();
 				separator.setVisible(item.isVisible());
@@ -1536,6 +1532,10 @@
 		return getActionBarAdvisor().isApplicationMenu(menuID);
 	}
 
+	boolean isWorkbenchCoolItemId(String id) {
+		return windowConfigurer.containsCoolItem(id);
+	}
+
 	/**
 	 * Called when this window is about to be closed.
 	 */
@@ -1698,6 +1698,8 @@
 			page = (WorkbenchPage) in;
 			model.getContext().set(IWorkbenchPage.class, page);
 			partService.setPage(page);
+			updateActionSets();
+			// submitGlobalActions();
 		}
 	}
 
@@ -1784,7 +1786,17 @@
 		if (updateDisabled || updatesDeferred()) {
 			return;
 		}
-		getCoolBarManager2().update(true);
+		// updateAll required in order to enable accelerators on pull-down menus
+		getMenuBarManager().update(false);
+
+		try {
+			getShell().setLayoutDeferred(true);
+			getCoolBarManager2().update(false);
+		} finally {
+			getShell().setLayoutDeferred(false);
+		}
+
+		getStatusLineManager().update(false);
 	}
 
 	/**
@@ -1846,6 +1858,30 @@
 			return;
 		}
 
+		WorkbenchPage currentPage = (WorkbenchPage) getActivePage();
+		if (currentPage == null) {
+			getActionPresentation().clearActionSets();
+		} else {
+			ICoolBarManager2 coolBarManager = (ICoolBarManager2) getCoolBarManager2();
+			if (coolBarManager != null) {
+				coolBarManager.refresh();
+			}
+			getActionPresentation().setActionSets(currentPage.getActionSets());
+		}
+		fireActionSetsChanged();
+		updateActionBars();
+
+		// hide the launch menu if it is empty
+		String path = IWorkbenchActionConstants.M_WINDOW + IWorkbenchActionConstants.SEP
+				+ IWorkbenchActionConstants.M_LAUNCH;
+		IMenuManager manager = getMenuBarManager().findMenuUsingPath(path);
+		IContributionItem item = getMenuBarManager().findUsingPath(path);
+
+		if (manager == null || item == null) {
+			return;
+		}
+		item.setVisible(manager.getItems().length >= 2);
+		// there is a separator for the additions group thus >= 2
 	}
 
 	private ListenerList actionSetListeners = null;
@@ -1856,6 +1892,26 @@
 
 	private ITrimManager trimManager;
 
+	private ActionPresentation actionPresentation;
+
+	private final void fireActionSetsChanged() {
+		if (actionSetListeners != null) {
+			final Object[] listeners = actionSetListeners.getListeners();
+			for (int i = 0; i < listeners.length; i++) {
+				final IActionSetsListener listener = (IActionSetsListener) listeners[i];
+				final WorkbenchPage currentPage = (WorkbenchPage) getActivePage();
+				final IActionSetDescriptor[] newActionSets;
+				if (currentPage == null) {
+					newActionSets = null;
+				} else {
+					newActionSets = currentPage.getActionSets();
+				}
+				final ActionSetsEvent event = new ActionSetsEvent(newActionSets);
+				listener.actionSetsChanged(event);
+			}
+		}
+	}
+
 	final void addActionSetsListener(final IActionSetsListener listener) {
 		if (actionSetListeners == null) {
 			actionSetListeners = new ListenerList();
@@ -2052,6 +2108,13 @@
 		return getWindowConfigurer().getShowCoolBar() && coolBarVisible;
 	}
 
+	public ActionPresentation getActionPresentation() {
+		if (actionPresentation == null) {
+			actionPresentation = new ActionPresentation(this);
+		}
+		return actionPresentation;
+	}
+
 	/**
 	 * @param visible
 	 *            whether the perspective bar should be shown. This is only
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/menus/MenuPersistence.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/menus/MenuPersistence.java
index c14da4c..a8df8d9 100644
--- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/menus/MenuPersistence.java
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/menus/MenuPersistence.java
@@ -14,9 +14,7 @@
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Comparator;
-import java.util.HashMap;
 import java.util.Iterator;
-import java.util.Map.Entry;
 import java.util.regex.Pattern;
 import org.eclipse.core.runtime.IConfigurationElement;
 import org.eclipse.core.runtime.IExtensionRegistry;
@@ -27,8 +25,6 @@
 import org.eclipse.e4.ui.model.application.MApplication;
 import org.eclipse.e4.ui.model.application.ui.menu.MMenuContribution;
 import org.eclipse.e4.ui.model.application.ui.menu.MToolBarContribution;
-import org.eclipse.e4.ui.model.application.ui.menu.MToolBarElement;
-import org.eclipse.e4.ui.model.application.ui.menu.MToolBarSeparator;
 import org.eclipse.e4.ui.model.application.ui.menu.MTrimContribution;
 import org.eclipse.ui.internal.registry.IWorkbenchRegistryConstants;
 import org.eclipse.ui.internal.services.RegistryPersistence;
@@ -49,7 +45,6 @@
 	private MApplication application;
 	private IEclipseContext appContext;
 	private ArrayList<MenuAdditionCacheEntry> cacheEntries = new ArrayList<MenuAdditionCacheEntry>();
-	private ArrayList<ActionSet> actionContributions = new ArrayList<ActionSet>();
 	private ArrayList<EditorAction> editorActionContributions = new ArrayList<EditorAction>();
 	private ArrayList<ViewAction> viewActionContributions = new ArrayList<ViewAction>();
 
@@ -91,7 +86,6 @@
 		application.getTrimContributions().removeAll(trimContributions);
 		menuContributions.clear();
 		cacheEntries.clear();
-		actionContributions.clear();
 		editorActionContributions.clear();
 		viewActionContributions.clear();
 		super.dispose();
@@ -117,7 +111,7 @@
 		super.read();
 
 		readAdditions();
-		readActionSets();
+		// readActionSets();
 		readEditorActions();
 		readViewActions();
 
@@ -177,60 +171,6 @@
 		}
 	}
 
-	private void readActionSets() {
-		final IExtensionRegistry registry = Platform.getExtensionRegistry();
-		ArrayList<IConfigurationElement> configElements = new ArrayList<IConfigurationElement>();
-
-		final IConfigurationElement[] extElements = registry
-				.getConfigurationElementsFor(IWorkbenchRegistryConstants.EXTENSION_ACTION_SETS);
-		for (IConfigurationElement element : extElements) {
-			if (contributorFilter == null
-					|| contributorFilter.matcher(element.getContributor().getName()).matches()) {
-				configElements.add(element);
-			}
-		}
-
-		Collections.sort(configElements, comparer);
-
-		HashMap<String, ArrayList<MToolBarContribution>> postProcessing = new HashMap<String, ArrayList<MToolBarContribution>>();
-		for (IConfigurationElement element : configElements) {
-			ArrayList<MToolBarContribution> localToolbarContributions = new ArrayList<MToolBarContribution>();
-			ActionSet actionSet = new ActionSet(application, appContext, element);
-			actionContributions.add(actionSet);
-			actionSet.addToModel(menuContributions, localToolbarContributions, trimContributions);
-			toolBarContributions.addAll(localToolbarContributions);
-			postProcessing.put(actionSet.getId(), localToolbarContributions);
-		}
-		for (Entry<String, ArrayList<MToolBarContribution>> entry : postProcessing.entrySet()) {
-			for (MToolBarContribution contribution : entry.getValue()) {
-				String targetParentId = contribution.getParentId();
-				if (entry.getKey().equals(targetParentId)) {
-					continue;
-				}
-				ArrayList<MToolBarContribution> adjunctContributions = postProcessing
-						.get(targetParentId);
-				if (adjunctContributions == null) {
-					continue;
-				}
-				boolean processed = false;
-				Iterator<MToolBarContribution> i = adjunctContributions.iterator();
-				while (i.hasNext() && !processed) {
-					MToolBarContribution adjunctContribution = i.next();
-					if (targetParentId.equals(adjunctContribution.getParentId())) {
-						for (MToolBarElement item : adjunctContribution.getChildren()) {
-							if (!(item instanceof MToolBarSeparator) && item.getElementId() != null) {
-								processed = true;
-								contribution.setPositionInParent("before=" + item.getElementId()); //$NON-NLS-1$
-								break;
-							}
-						}
-					}
-				}
-			}
-		}
-		postProcessing.clear();
-	}
-
 	private void readEditorActions() {
 		final IExtensionRegistry registry = Platform.getExtensionRegistry();
 		ArrayList<IConfigurationElement> configElements = new ArrayList<IConfigurationElement>();
diff --git a/tests/org.eclipse.ui.tests.harness/src/org/eclipse/ui/tests/harness/util/ActionUtil.java b/tests/org.eclipse.ui.tests.harness/src/org/eclipse/ui/tests/harness/util/ActionUtil.java
index de0b095..cb3f272 100644
--- a/tests/org.eclipse.ui.tests.harness/src/org/eclipse/ui/tests/harness/util/ActionUtil.java
+++ b/tests/org.eclipse.ui.tests.harness/src/org/eclipse/ui/tests/harness/util/ActionUtil.java
@@ -21,8 +21,8 @@
 import org.eclipse.jface.action.IMenuManager;
 import org.eclipse.jface.action.MenuManager;
 import org.eclipse.jface.action.SubContributionItem;
-import org.eclipse.jface.window.ApplicationWindow;
 import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.internal.WorkbenchWindow;
 
 /**
  * <code>ActionUtil</code> contains methods to run actions
@@ -77,7 +77,7 @@
      */
     public static void runActionWithLabel(TestCase test, IWorkbenchWindow win,
             String label) {
-        ApplicationWindow realWin = (ApplicationWindow) win;
+        WorkbenchWindow realWin = (WorkbenchWindow) win;
         IMenuManager mgr = realWin.getMenuBarManager();
         runActionWithLabel(test, mgr, label);
     }
@@ -107,7 +107,7 @@
      */
     public static void runActionUsingPath(TestCase test, IWorkbenchWindow win,
             String idPath) {
-    	ApplicationWindow realWin = (ApplicationWindow) win;
+    	WorkbenchWindow realWin = (WorkbenchWindow) win;
         IMenuManager mgr = realWin.getMenuBarManager();
         runActionUsingPath(test, mgr, idPath);
     }
diff --git a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/api/IWorkbenchPageTest.java b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/api/IWorkbenchPageTest.java
index 1141183..8c6dfeb 100644
--- a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/api/IWorkbenchPageTest.java
+++ b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/api/IWorkbenchPageTest.java
@@ -60,6 +60,7 @@
 import org.eclipse.ui.ide.IDE;
 import org.eclipse.ui.internal.WorkbenchPage;
 import org.eclipse.ui.internal.WorkbenchPlugin;
+import org.eclipse.ui.internal.registry.IActionSetDescriptor;
 import org.eclipse.ui.internal.util.Util;
 import org.eclipse.ui.navigator.resources.ProjectExplorer;
 import org.eclipse.ui.part.FileEditorInput;
@@ -1619,44 +1620,53 @@
 	public void testShowActionSet() {
 		String id = MockActionDelegate.ACTION_SET_ID;
 
-//		int totalBefore = facade.getActionSetCount(fActivePage);
-
-		// FIXME: No implementation
-		fail("facade.getActionSetCount() had no implementation");
+		int totalBefore = ((WorkbenchPage) fActivePage).getActionSets().length;
 
 		fActivePage.showActionSet(id);
 
-//		facade.assertActionSetId(fActivePage, id, true);
-		
-		// FIXME: No implementation
-		fail("facade.assertActionSetId() had no implementation");
+		IActionSetDescriptor[] sets = ((WorkbenchPage) fActivePage).getActionSets();
+		boolean found = false;
+		for (int i = 0; i < sets.length && !found; i++) {
+			if (id.equals(sets[i].getId())) {
+				found = true;
+			}
+		}
+		assertTrue("Failed for " + id,  found);
 
 
 		// check that the method does not add an invalid action set to itself
 		id = IConstants.FakeID;
 		fActivePage.showActionSet(id);
 
-//		facade.assertActionSetId(fActivePage, id, false);
-//		assertEquals(facade.getActionSetCount(fActivePage), totalBefore + 1);
+		sets = ((WorkbenchPage) fActivePage).getActionSets();
+		found = false;
+		for (int i = 0; i < sets.length && !found; i++) {
+			if (id.equals(sets[i].getId())) {
+				found = true;
+			}
+		}
+		assertFalse("Failed for " + id,  found);
+		assertEquals(sets.length, totalBefore + 1);
 	}
 
 	public void testHideActionSet() {
-//		int totalBefore = facade.getActionSetCount(fActivePage);
-		
-		// FIXME: No implementation
-		fail("facade.getActionSetCount() had no implementation");
+		int totalBefore = ((WorkbenchPage) fActivePage).getActionSets().length;
 
 		String id = MockWorkbenchWindowActionDelegate.SET_ID;
 		fActivePage.showActionSet(id);
-//		assertEquals(facade.getActionSetCount(fActivePage), totalBefore + 1);
+		assertEquals(((WorkbenchPage) fActivePage).getActionSets().length, totalBefore + 1);
 
 		fActivePage.hideActionSet(id);
-//		assertEquals(facade.getActionSetCount(fActivePage), totalBefore);
+		assertEquals(((WorkbenchPage) fActivePage).getActionSets().length, totalBefore);
 
-//		facade.assertActionSetId(fActivePage, id, false);
-		
-		// FIXME: No implementation
-		fail("facade.assertActionSetId() had no implementation");
+		IActionSetDescriptor[] sets = ((WorkbenchPage) fActivePage).getActionSets();
+		boolean found = false;
+		for (int i = 0; i < sets.length && !found; i++) {
+			if (id.equals(sets[i].getId())) {
+				found = true;
+			}
+		}
+		assertFalse("Failed for " + id,  found);
 
 	}