summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorJosh Davis2013-03-05 12:07:44 (EST)
committer Paul Webster2013-04-04 11:00:49 (EDT)
commitd0d966c9226abaada1a9b6bc98e4c486ceb4f640 (patch)
tree98e44b415bcb3b4a97d2d62d4f92ab281b4134fe
parent4aa6a08f482dc347a28d27e99e7e041e0af2a838 (diff)
downloadeclipse.platform.ui-d0d966c9226abaada1a9b6bc98e4c486ceb4f640.zip
eclipse.platform.ui-d0d966c9226abaada1a9b6bc98e4c486ceb4f640.tar.gz
eclipse.platform.ui-d0d966c9226abaada1a9b6bc98e4c486ceb4f640.tar.bz2
Bug 374568 - Part menu is not rendered correctly after removing menurefs/changes/60/10860/7
items Respond to incoming model changes. Change-Id: Id3b90536d6f7afbcbfb5bc3a4cca8bff1df53627
-rw-r--r--bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/MenuManagerRenderer.java82
1 files changed, 80 insertions, 2 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 0cf54a3..912a15e 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,68 @@ public class MenuManagerRenderer extends SWTPartRenderer {
}
};
+ private EventHandler childUpdater = new EventHandler() {
+ public void handleEvent(Event event) {
+ // Ensure that this event is for a MMenu
+ final Object obj = event.getProperty(UIEvents.EventTags.ELEMENT);
+ if (!(obj instanceof MMenu) || (obj instanceof MOpaqueMenu))
+ return;
+
+ MMenu menuModel = (MMenu) obj;
+
+ if (UIEvents.isADD(event)) {
+ MenuManager parentManager = getManager(menuModel);
+ if (parentManager == null) {
+ return;
+ }
+ Object newValue = event
+ .getProperty(UIEvents.EventTags.NEW_VALUE);
+ if (newValue instanceof List) {
+ for (Object object : (List) newValue) {
+ if (object instanceof MMenuElement) {
+ modelProcessSwitch(parentManager,
+ (MMenuElement) object);
+ }
+ }
+ } else if (newValue instanceof MMenuElement) {
+ modelProcessSwitch(parentManager, (MMenuElement) newValue);
+ }
+ } else if (UIEvents.isREMOVE(event)) {
+ MenuManager parentManager = getManager(menuModel);
+ if (parentManager == null) {
+ return;
+ }
+ Object oldValue = event
+ .getProperty(UIEvents.EventTags.OLD_VALUE);
+ if (oldValue instanceof MMenu
+ && !(oldValue instanceof MOpaqueMenu)) {
+ cleanUp((MMenu) oldValue);
+ 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
+ && !(object instanceof MOpaqueMenu)) {
+ cleanUp((MMenu) object);
+ 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 +280,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 +303,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 +602,19 @@ public class MenuManagerRenderer extends SWTPartRenderer {
parentManager.update(false);
}
+ private void disposeMenuManager(MenuManager menuManager,
+ MenuManager parentManager, MMenu modelElement) {
+ clearModelToManager(modelElement, menuManager);
+ parentManager.remove(menuManager);
+ }
+
+ 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();
@@ -629,8 +707,8 @@ public class MenuManagerRenderer extends SWTPartRenderer {
Object obj = itemModel.getContributionItem();
if (obj instanceof IContextFunction) {
final IEclipseContext lclContext = getContext(itemModel);
- ici = (IContributionItem) ((IContextFunction) obj)
- .compute(lclContext, null);
+ ici = (IContributionItem) ((IContextFunction) obj).compute(
+ lclContext, null);
itemModel.setContributionItem(ici);
} else if (obj instanceof IContributionItem) {
ici = (IContributionItem) obj;