aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarco Descher2013-02-28 10:26:48 (EST)
committerPaul Webster2013-02-28 10:26:48 (EST)
commit927225bc26a1d2b28da586879c9bae3141ecef44 (patch)
tree6570358530a524f0117f7495b2bef14dd467546e
parent24831413fe25ee2a254a6fd93389ddd6a08814d2 (diff)
downloadeclipse.platform.ui-927225bc26a1d2b28da586879c9bae3141ecef44.zip
eclipse.platform.ui-927225bc26a1d2b28da586879c9bae3141ecef44.tar.gz
eclipse.platform.ui-927225bc26a1d2b28da586879c9bae3141ecef44.tar.bz2
Bug 398866 - Dynamic menu contribution position in application model not
equal to rendering Place contribution model elements after the dynamic element.
-rw-r--r--bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/DynamicContributionContributionItem.java86
-rw-r--r--bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/MenuManagerRenderer.java23
-rw-r--r--bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/MenuManagerShowProcessor.java41
3 files changed, 135 insertions, 15 deletions
diff --git a/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/DynamicContributionContributionItem.java b/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/DynamicContributionContributionItem.java
new file mode 100644
index 0000000..5e6e372
--- /dev/null
+++ b/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/DynamicContributionContributionItem.java
@@ -0,0 +1,86 @@
+/*******************************************************************************
+ * Copyright (c) 2013 MEDEVIT, FHV 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:
+ * Marco Descher <marco@descher.at> - initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.e4.ui.workbench.renderers.swt;
+
+import org.eclipse.e4.ui.model.application.ui.menu.MDynamicMenuContribution;
+import org.eclipse.jface.action.ContributionItem;
+import org.eclipse.jface.action.IContributionManager;
+import org.eclipse.jface.action.IMenuListener;
+import org.eclipse.jface.action.IMenuManager;
+
+/**
+ * This item currently serves as a placeholder to determine the correct location
+ * of a dynamic menu contribution entry.
+ */
+class DynamicContributionContributionItem extends ContributionItem {
+ private MDynamicMenuContribution model;
+
+ private IMenuListener menuListener = new IMenuListener() {
+ public void menuAboutToShow(IMenuManager manager) {
+ manager.markDirty();
+ }
+ };
+
+ /**
+ * Create the item and associated model;
+ *
+ * @param item
+ */
+ public DynamicContributionContributionItem(MDynamicMenuContribution item) {
+ super(item.getElementId());
+ model = item;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.action.ContributionItem#isDirty()
+ */
+ public boolean isDirty() {
+ return true;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.action.ContributionItem#isDynamic()
+ */
+ public boolean isDynamic() {
+ return true;
+ }
+
+ /**
+ * @return the model element
+ */
+ public MDynamicMenuContribution getModel() {
+ return model;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.jface.action.ContributionItem#setParent(org.eclipse.jface
+ * .action.IContributionManager)
+ */
+ public void setParent(IContributionManager parent) {
+ if (getParent() instanceof IMenuManager) {
+ IMenuManager menuMgr = (IMenuManager) getParent();
+ menuMgr.removeMenuListener(menuListener);
+ }
+ if (parent instanceof IMenuManager) {
+ IMenuManager menuMgr = (IMenuManager) parent;
+ menuMgr.addMenuListener(menuListener);
+ }
+ super.setParent(parent);
+ }
+}
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..2fae849 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2012 IBM Corporation and others.
+ * Copyright (c) 2009, 2013 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
@@ -7,7 +7,7 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
- * Marco Descher <descher@medevit.at> - Bug 389063 Dynamic Menu Contribution
+ * Marco Descher <marco@descher.at> - Bug 389063, Bug 398865, Bug 398866
*******************************************************************************/
package org.eclipse.e4.ui.workbench.renderers.swt;
@@ -610,6 +610,9 @@ public class MenuManagerRenderer extends SWTPartRenderer {
} else if (childME instanceof MMenu) {
MMenu itemModel = (MMenu) childME;
processMenu(menuManager, itemModel);
+ } else if (childME instanceof MDynamicMenuContribution) {
+ MDynamicMenuContribution itemModel = (MDynamicMenuContribution) childME;
+ processDynamicMenuContribution(menuManager, itemModel);
}
}
@@ -705,6 +708,22 @@ public class MenuManagerRenderer extends SWTPartRenderer {
}
/**
+ * @param menuManager
+ * @param itemModel
+ */
+ private void processDynamicMenuContribution(MenuManager menuManager,
+ MDynamicMenuContribution itemModel) {
+ IContributionItem ici = getContribution(itemModel);
+ if (ici != null) {
+ return;
+ }
+ DynamicContributionContributionItem ci = new DynamicContributionContributionItem(
+ itemModel);
+ addToManager(menuManager, itemModel, ci);
+ linkModelToContribution(itemModel, ci);
+ }
+
+ /**
* @param parentManager
* @param itemModel
*/
diff --git a/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/MenuManagerShowProcessor.java b/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/MenuManagerShowProcessor.java
index b22cb04..e87a064 100644
--- a/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/MenuManagerShowProcessor.java
+++ b/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/MenuManagerShowProcessor.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010, 2012 IBM Corporation and others.
+ * Copyright (c) 2010, 2013 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
@@ -7,7 +7,7 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
- * Marco Descher <marco@descher.at> - Bug 389063 Dynamic Menu Contribution
+ * Marco Descher <marco@descher.at> - Bug 389063, Bug 398865, Bug 398866
*******************************************************************************/
package org.eclipse.e4.ui.workbench.renderers.swt;
@@ -173,18 +173,33 @@ public class MenuManagerShowProcessor implements IMenuListener2 {
storageMap.remove(DYNAMIC_ELEMENT_STORAGE_KEY);
- // ensure that each element of the list has a valid element id
- // and set the parent of the entries
- for (int j = 0; j < mel.size(); j++) {
- MMenuElement menuElement = mel.get(j);
- if (menuElement.getElementId() == null
- || menuElement.getElementId().length() < 1)
- menuElement.setElementId(currentMenuElement
- .getElementId() + "." + j); //$NON-NLS-1$
- menuElement.setParent(currentMenuElement.getParent());
- renderer.modelProcessSwitch(menuManager, menuElement);
+ if (mel.size() > 0) {
+
+ int position = 0;
+ while (position < menuModel.getChildren().size()) {
+ if (currentMenuElement == menuModel.getChildren().get(
+ position)) {
+ position++;
+ break;
+ }
+ position++;
+ }
+
+ // ensure that each element of the list has a valid element
+ // id
+ // and set the parent of the entries
+ for (int j = 0; j < mel.size(); j++) {
+ MMenuElement menuElement = mel.get(j);
+ if (menuElement.getElementId() == null
+ || menuElement.getElementId().length() < 1) {
+ menuElement.setElementId(currentMenuElement
+ .getElementId() + "." + j); //$NON-NLS-1$
+ }
+ menuModel.getChildren().add(position++, menuElement);
+ renderer.modelProcessSwitch(menuManager, menuElement);
+ }
+ storageMap.put(DYNAMIC_ELEMENT_STORAGE_KEY, mel);
}
- storageMap.put(DYNAMIC_ELEMENT_STORAGE_KEY, mel);
}
}
}