aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSopot Cela2013-11-19 06:13:09 (EST)
committerGerrit Code Review @ Eclipse.org2013-11-27 15:26:43 (EST)
commit2d66e04c48991203af1c624a69877928796b40e8 (patch)
treeae629b4da6ead83e7a8d7a2f59c2a21d9cfc93ea
parent1337593288b15da51af8ec09b2a051478563a17c (diff)
downloadeclipse.platform.ui-2d66e04c48991203af1c624a69877928796b40e8.zip
eclipse.platform.ui-2d66e04c48991203af1c624a69877928796b40e8.tar.gz
eclipse.platform.ui-2d66e04c48991203af1c624a69877928796b40e8.tar.bz2
Bug 391430 - Dynamically creating / deleting menu items in Menu andrefs/changes/56/18556/4
MPopupMenu doesn't work Change-Id: I0257600c4aa8f2f4fba8944787f401a7d205f804 Signed-off-by: Sopot Cela <sopotcela@gmail.com>
-rw-r--r--bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/MenuManagerRenderer.java49
1 files changed, 49 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 349c942..49ffbd7 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
@@ -250,6 +250,29 @@ public class MenuManagerRenderer extends SWTPartRenderer {
}
};
+ private EventHandler childrenUpdater = new EventHandler() {
+
+ public void handleEvent(Event event) {
+ Object changedObj = event.getProperty(UIEvents.EventTags.ELEMENT);
+ if (changedObj instanceof MMenu) {
+ MMenu menuModel = (MMenu) changedObj;
+ MenuManager manager = getManager(menuModel);
+ if (manager == null)
+ return;
+ if (UIEvents.isREMOVE(event)) {
+ MMenuElement menuElement = (MMenuElement) event
+ .getProperty(UIEvents.EventTags.OLD_VALUE);
+ handleMenuElementRemove(manager, menuElement);
+ } else if (UIEvents.isADD(event)) {
+ MMenuElement menuElement = (MMenuElement) event
+ .getProperty(UIEvents.EventTags.NEW_VALUE);
+ handleMenuElementAdd(manager, menuElement);
+ }
+ }
+
+ }
+ };
+
private MenuManagerRendererFilter rendererFilter;
@PostConstruct
@@ -260,6 +283,8 @@ public class MenuManagerRenderer extends SWTPartRenderer {
eventBroker.subscribe(UIEvents.Item.TOPIC_ENABLED, enabledUpdater);
eventBroker
.subscribe(UIEvents.UIElement.TOPIC_ALL, toBeRenderedUpdater);
+ eventBroker.subscribe(UIEvents.ElementContainer.TOPIC_CHILDREN,
+ childrenUpdater);
context.set(MenuManagerRenderer.class, this);
Display display = context.get(Display.class);
@@ -276,6 +301,29 @@ public class MenuManagerRenderer extends SWTPartRenderer {
}
+ /**
+ * @param manager
+ * @param menuElement
+ */
+ protected void handleMenuElementAdd(MenuManager manager,
+ MMenuElement menuElement) {
+ modelProcessSwitch(manager, menuElement);
+ }
+
+ /**
+ * @param manager
+ * @param menuElement
+ */
+ protected void handleMenuElementRemove(MenuManager manager,
+ MMenuElement menuElement) {
+ if (menuElement instanceof MMenu) {
+ MMenu menuModel = (MMenu) menuElement;
+ manager.remove(getManager(menuModel));
+ } else
+ manager.remove(getContribution(menuElement));
+ manager.update(false);
+ }
+
@PreDestroy
public void contextDisposed() {
eventBroker.unsubscribe(itemUpdater);
@@ -283,6 +331,7 @@ public class MenuManagerRenderer extends SWTPartRenderer {
eventBroker.unsubscribe(selectionUpdater);
eventBroker.unsubscribe(enabledUpdater);
eventBroker.unsubscribe(toBeRenderedUpdater);
+ eventBroker.unsubscribe(childrenUpdater);
ContextInjectionFactory.uninject(MenuManagerEventHelper.showHelper,
context);