aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWojciech Sudol2014-04-18 07:04:27 (EDT)
committerPaul Webster2014-04-22 10:54:44 (EDT)
commit1f2affab064ea79b7b96e2f7bdcb91faf4929163 (patch)
tree38aaf1f77d6cc87e14a7338518528776fa807df0
parente1a872d4dcf51b4bebc10ca25c20aec1348e253d (diff)
downloadeclipse.platform.ui-1f2affab064ea79b7b96e2f7bdcb91faf4929163.zip
eclipse.platform.ui-1f2affab064ea79b7b96e2f7bdcb91faf4929163.tar.gz
eclipse.platform.ui-1f2affab064ea79b7b96e2f7bdcb91faf4929163.tar.bz2
Bug 405262 - [Contributions] Duplicate context menu entries in XMLrefs/changes/54/25154/3
editor source tab Change-Id: Ia183bcd386d417046bbedfb56e5d9286e8911999 Signed-off-by: Wojciech Sudol <wojciech.sudol@pl.ibm.com>
-rw-r--r--bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/ObjectActionContributorManager.java42
-rw-r--r--bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/PopupMenuExtender.java24
-rw-r--r--tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/dynamicplugins/ObjectContributionTests.java10
3 files changed, 44 insertions, 32 deletions
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/ObjectActionContributorManager.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/ObjectActionContributorManager.java
index 9b0a6c7..93b7956 100644
--- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/ObjectActionContributorManager.java
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/ObjectActionContributorManager.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
+ * Copyright (c) 2000, 2014 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
@@ -13,7 +13,7 @@ package org.eclipse.ui.internal;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
-
+import java.util.Set;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtension;
import org.eclipse.core.runtime.dynamichelpers.IExtensionTracker;
@@ -40,16 +40,21 @@ public class ObjectActionContributorManager extends ObjectContributorManager {
}
/**
- * Contributes submenus and/or actions applicable to the selection in the
- * provided viewer into the provided popup menu.
- *
- * @param part the part being contributed to
- * @param popupMenu the menu being contributed to
- * @param selProv the selection provider
- * @return whether anything was contributed
- */
- public boolean contributeObjectActions(IWorkbenchPart part,
- IMenuManager popupMenu, ISelectionProvider selProv) {
+ * Contributes submenus and/or actions applicable to the selection in the
+ * provided viewer into the provided popup menu.
+ *
+ * @param part
+ * the part being contributed to
+ * @param popupMenu
+ * the menu being contributed to
+ * @param selProv
+ * the selection provider
+ * @param alreadyContributed
+ * the set of contributors that already contributed to the menu
+ * @return whether anything was contributed
+ */
+ public boolean contributeObjectActions(IWorkbenchPart part, IMenuManager popupMenu,
+ ISelectionProvider selProv, Set<IObjectActionContributor> alreadyContributed) {
// Get a selection.
ISelection selection = selProv.getSelection();
if (selection == null) {
@@ -68,7 +73,8 @@ public class ObjectActionContributorManager extends ObjectContributorManager {
elements.add(selection);
}
- List contributors = getContributors(elements);
+ List<IObjectActionContributor> contributors = getContributors(elements);
+ contributors.removeAll(alreadyContributed);
if (contributors.isEmpty()) {
return false;
@@ -78,25 +84,27 @@ public class ObjectActionContributorManager extends ObjectContributorManager {
// list any non-applicable contributions.
boolean actualContributions = false;
ArrayList overrides = new ArrayList(4);
- for (Iterator it = contributors.iterator(); it.hasNext();) {
- IObjectActionContributor contributor = (IObjectActionContributor) it.next();
+ for (Iterator<IObjectActionContributor> it = contributors.iterator(); it.hasNext();) {
+ IObjectActionContributor contributor = it.next();
if (!isApplicableTo(elements, contributor)) {
it.remove();
continue;
}
if (contributor.contributeObjectMenus(popupMenu, selProv)) {
actualContributions = true;
+ alreadyContributed.add(contributor);
}
contributor.contributeObjectActionIdOverrides(overrides);
}
// Second pass, add the contributions that are applicable to
// the selection.
- for (Iterator it = contributors.iterator(); it.hasNext();) {
- IObjectActionContributor contributor = (IObjectActionContributor) it.next();
+ for (Iterator<IObjectActionContributor> it = contributors.iterator(); it.hasNext();) {
+ IObjectActionContributor contributor = it.next();
if (contributor.contributeObjectActions(part, popupMenu, selProv,
overrides)) {
actualContributions = true;
+ alreadyContributed.add(contributor);
}
}
return actualContributions;
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/PopupMenuExtender.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/PopupMenuExtender.java
index fb43592..94720f5 100644
--- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/PopupMenuExtender.java
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/PopupMenuExtender.java
@@ -14,6 +14,7 @@ package org.eclipse.ui.internal;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -265,7 +266,7 @@ public class PopupMenuExtender implements IMenuListener2,
/**
* Contributes items registered for the currently active editor.
*/
- private void addEditorActions(IMenuManager mgr) {
+ private void addEditorActions(IMenuManager mgr, Set<IObjectActionContributor> alreadyContributed) {
ISelectionProvider activeEditor = new ISelectionProvider() {
/* (non-Javadoc)
@@ -312,21 +313,21 @@ public class PopupMenuExtender implements IMenuListener2,
}
};
- if (ObjectActionContributorManager.getManager()
- .contributeObjectActions(part, mgr, activeEditor)) {
- mgr.add(new Separator());
- }
+ if (ObjectActionContributorManager.getManager().contributeObjectActions(part, mgr,
+ activeEditor, alreadyContributed)) {
+ mgr.add(new Separator());
+ }
}
/**
* Contributes items registered for the object type(s) in
* the current selection.
*/
- private void addObjectActions(IMenuManager mgr) {
+ private void addObjectActions(IMenuManager mgr, Set<IObjectActionContributor> alreadyContributed) {
if (selProvider != null) {
- if (ObjectActionContributorManager.getManager()
- .contributeObjectActions(part, mgr, selProvider)) {
- mgr.add(new Separator());
+ if (ObjectActionContributorManager.getManager().contributeObjectActions(part, mgr,
+ selProvider, alreadyContributed)) {
+ mgr.add(new Separator());
}
}
}
@@ -397,10 +398,11 @@ public class PopupMenuExtender implements IMenuListener2,
mgr = menuWrapper;
menuWrapper.removeAll();
}
+ Set<IObjectActionContributor> contributedItems = new HashSet<IObjectActionContributor>();
if ((bitSet & INCLUDE_EDITOR_INPUT) != 0) {
- addEditorActions(mgr);
+ addEditorActions(mgr, contributedItems);
}
- addObjectActions(mgr);
+ addObjectActions(mgr, contributedItems);
addStaticActions(mgr);
}
diff --git a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/dynamicplugins/ObjectContributionTests.java b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/dynamicplugins/ObjectContributionTests.java
index 8602e89..8b16ed2 100644
--- a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/dynamicplugins/ObjectContributionTests.java
+++ b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/dynamicplugins/ObjectContributionTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2012 IBM Corporation and others.
+ * Copyright (c) 2004, 2014 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
@@ -10,6 +10,7 @@
*******************************************************************************/
package org.eclipse.ui.tests.dynamicplugins;
+import java.util.HashSet;
import java.util.Random;
import junit.framework.TestSuite;
@@ -25,6 +26,7 @@ import org.eclipse.ui.IWorkbenchActionConstants;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.ide.IDE;
+import org.eclipse.ui.internal.IObjectActionContributor;
import org.eclipse.ui.internal.ObjectActionContributorManager;
import org.eclipse.ui.internal.PartSite;
import org.eclipse.ui.internal.PopupMenuExtender;
@@ -144,17 +146,17 @@ public class ObjectContributionTests extends DynamicTestCase {
};
- manager.contributeObjectActions(part, menu, provider);
+ manager.contributeObjectActions(part, menu, provider, new HashSet<IObjectActionContributor>());
assertNull(menu.find(OBJECT_ACTION_ID));
menu.removeAll();
getBundle();
- manager.contributeObjectActions(part, menu, provider);
+ manager.contributeObjectActions(part, menu, provider, new HashSet<IObjectActionContributor>());
assertNotNull(menu.find(OBJECT_ACTION_ID));
menu.removeAll();
removeBundle();
- manager.contributeObjectActions(part, menu, provider);
+ manager.contributeObjectActions(part, menu, provider, new HashSet<IObjectActionContributor>());
assertNull(menu.find(OBJECT_ACTION_ID));
menu.removeAll();
}