summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorJosh Davis2013-01-25 13:14:44 (EST)
committer Paul Webster2013-01-25 13:14:44 (EST)
commit8929a2049341288baf2a349dbf7bb97151bb96cc (patch)
tree114bf442125c422db6fb4fa13ebcbbb94b364008
parent674ea200ba288ab8158b212287dfa7cad3bb0da3 (diff)
downloadeclipse.platform.ui-8929a2049341288baf2a349dbf7bb97151bb96cc.zip
eclipse.platform.ui-8929a2049341288baf2a349dbf7bb97151bb96cc.tar.gz
eclipse.platform.ui-8929a2049341288baf2a349dbf7bb97151bb96cc.tar.bz2
Bug 374568 - Part menu is not rendered correctly after removing menuv20130125-181444
items
-rw-r--r--bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/MenuManagerRenderer.java71
1 files changed, 71 insertions, 0 deletions
diff --git a/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/MenuManagerRenderer.java b/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/MenuManagerRenderer.java
index c5f3bef..702fa02 100644
--- a/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/MenuManagerRenderer.java
+++ b/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/MenuManagerRenderer.java
@@ -52,6 +52,7 @@ import org.eclipse.e4.ui.model.application.ui.menu.MRenderedMenuItem;
import org.eclipse.e4.ui.model.application.ui.menu.impl.MenuFactoryImpl;
import org.eclipse.e4.ui.workbench.IResourceUtilities;
import org.eclipse.e4.ui.workbench.UIEvents;
+import org.eclipse.e4.ui.workbench.UIEvents.ElementContainer;
import org.eclipse.e4.ui.workbench.modeling.ExpressionContext;
import org.eclipse.e4.ui.workbench.swt.util.ISWTResourceUtilities;
import org.eclipse.emf.common.util.URI;
@@ -208,6 +209,48 @@ public class MenuManagerRenderer extends SWTPartRenderer {
}
};
+ private EventHandler childUpdater = new EventHandler() {
+ public void handleEvent(Event event) {
+ // Ensure that this event is for a MMenuItem
+ if (!(event.getProperty(UIEvents.EventTags.ELEMENT) instanceof MMenu))
+ return;
+
+ Object menuModel = event.getProperty(UIEvents.EventTags.ELEMENT);
+
+ if (UIEvents.isADD(event)) {
+ processContents((MElementContainer<MUIElement>) menuModel);
+ } else if (UIEvents.isREMOVE(event)) {
+ MenuManager parentManager = getManager((MMenu) menuModel);
+ if (parentManager == null) {
+ return;
+ }
+ Object oldValue = event
+ .getProperty(UIEvents.EventTags.OLD_VALUE);
+ if (oldValue instanceof MMenu) {
+ disposeMenuManager(getManager((MMenu) oldValue),
+ parentManager, (MMenu) oldValue);
+ } else if (oldValue instanceof MMenuElement) {
+ disposeContributionItem(
+ getContribution((MMenuElement) oldValue),
+ parentManager, (MMenuElement) oldValue);
+ parentManager.update(false);
+ } else if (oldValue instanceof List) {
+ for (Object object : (List) oldValue) {
+ if (object instanceof MMenu) {
+ disposeMenuManager(getManager((MMenu) object),
+ parentManager, (MMenu) object);
+ } else if (object instanceof MMenuElement) {
+ disposeContributionItem(
+ getContribution((MMenuElement) object),
+ parentManager, (MMenuElement) object);
+ }
+ }
+ parentManager.update(false);
+ }
+ }
+ }
+ };
+
private MenuManagerRendererFilter rendererFilter;
@PostConstruct
@@ -217,6 +260,7 @@ public class MenuManagerRenderer extends SWTPartRenderer {
eventBroker.subscribe(UIEvents.Item.TOPIC_ENABLED, enabledUpdater);
eventBroker
.subscribe(UIEvents.UIElement.TOPIC_ALL, toBeRenderedUpdater);
+ eventBroker.subscribe(ElementContainer.TOPIC_CHILDREN, childUpdater);
context.set(MenuManagerRenderer.class, this);
Display display = context.get(Display.class);
@@ -239,6 +283,7 @@ public class MenuManagerRenderer extends SWTPartRenderer {
eventBroker.unsubscribe(selectionUpdater);
eventBroker.unsubscribe(enabledUpdater);
eventBroker.unsubscribe(toBeRenderedUpdater);
+ eventBroker.unsubscribe(childUpdater);
ContextInjectionFactory.uninject(MenuManagerEventHelper.showHelper,
context);
@@ -537,6 +582,32 @@ public class MenuManagerRenderer extends SWTPartRenderer {
parentManager.update(false);
}
+ // Disposes the menuManager and its children
+ private void disposeMenuManager(MenuManager menuManager,
+ MenuManager parentManager, MMenu menuModel) {
+ // Cleanup all contributions in menuManager since the parent is being
+ // disposed.
+ for (IContributionItem contributionItem : menuManager.getItems()) {
+ if (contributionItem instanceof MenuManager) {
+ disposeMenuManager((MenuManager) contributionItem, menuManager,
+ getMenuModel((MenuManager) contributionItem));
+ } else {
+ disposeContributionItem(contributionItem, parentManager,
+ getMenuElement(contributionItem));
+ }
+ }
+ clearModelToManager(menuModel, menuManager);
+ parentManager.remove(menuManager);
+ menuManager.dispose();
+ }
+
+ private void disposeContributionItem(IContributionItem contributionItem,
+ MenuManager parentManager, MMenuElement menuElement) {
+ clearModelToContribution(menuElement, contributionItem);
+ parentManager.remove(contributionItem);
+ contributionItem.dispose();
+ }
+
private void addToManager(MenuManager parentManager, MMenuElement model,
IContributionItem menuManager) {
MElementContainer<MUIElement> parent = model.getParent();