@@ -848,6 +857,46 @@
return result;
}
+
+ /**
+ * Install the commands into the specified viewer
+ *
+ * @param viewer
+ */
+ public void bindCommandMenuContributions(StructuredViewer viewer) {
+ CommandMenuContributionDescriptorManager mgr = CommandMenuContributionDescriptorManager
+ .getInstance();
+
+ final IMenuService menuService = (IMenuService) PlatformUI.getWorkbench().getService(
+ IMenuService.class);
+
+ String urlBase = "popup:" + getViewerId(); //$NON-NLS-1$
+
+ Iterator it = mgr.getDescriptors().iterator();
+ while (it.hasNext()) {
+ CommandMenuContributionDescriptor desc = (CommandMenuContributionDescriptor) it.next();
+ NavigatorViewerDescriptor vd = NavigatorViewerDescriptorManager.getInstance()
+ .getNavigatorViewerDescriptor(getViewerId());
+ if (vd.isVisibleCommand(desc.getCommandId())) {
+ final CommandMenuContributionDescriptor finalDesc = desc;
+
+ String url = urlBase;
+ if (desc.getAfter() != null)
+ url += "?after=" + desc.getAfter(); //$NON-NLS-1$
+
+ AbstractContributionFactory factory = new AbstractContributionFactory(url, desc.getPluginId()) {
+ public void createContributionItems(IServiceLocator serviceLocator,
+ IContributionRoot additions) {
+ CommandContributionItemParameter cp = new CommandContributionItemParameter(serviceLocator, null, finalDesc.getCommandId(), CommandContributionItem.STYLE_PULLDOWN);
+ CommandContributionItem item = new CommandContributionItem(cp);
+ additions.addContributionItem(item, null);
+ }
+ };
+ menuService.addContributionFactory(factory);
+ }
+ }
+ }
+
/*
* (non-Javadoc)
*
Index: src/org/eclipse/ui/internal/navigator/extensions/CommandMenuContributionDescriptor.java
===================================================================
RCS file: src/org/eclipse/ui/internal/navigator/extensions/CommandMenuContributionDescriptor.java
diff -N src/org/eclipse/ui/internal/navigator/extensions/CommandMenuContributionDescriptor.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/ui/internal/navigator/extensions/CommandMenuContributionDescriptor.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,77 @@
+/*******************************************************************************
+ * Copyright (c) 2003, 2010 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.ui.internal.navigator.extensions;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.ui.internal.navigator.extensions.INavigatorContentExtPtConstants;
+
+/**
+ *
+ *
+ * @since 3.5
+ */
+public class CommandMenuContributionDescriptor implements INavigatorContentExtPtConstants {
+
+ private final IConfigurationElement configurationElement;
+
+ private final String commandId;
+
+ private final String after;
+
+ private final String pluginId;
+
+ private String toString;
+
+ /**
+ * @param aConfigElement
+ */
+ public CommandMenuContributionDescriptor(IConfigurationElement aConfigElement) {
+ super();
+ Assert.isTrue(TAG_COMMAND_MENU_CONTRIBUTION.equals(aConfigElement.getName()));
+ configurationElement = aConfigElement;
+ pluginId = configurationElement.getContributor().getName();
+ commandId = configurationElement.getAttribute(ATT_COMMAND_ID);
+ after = configurationElement.getAttribute(ATT_AFTER);
+ }
+
+ /**
+ *
+ * @return The command id.
+ */
+ public String getCommandId() {
+ return commandId;
+ }
+
+ /**
+ *
+ * @return The after value which is which group the command is placed in in
+ * the context menu.
+ */
+ public String getAfter() {
+ return after;
+ }
+
+ /**
+ * @return the id of the contributing plugin
+ */
+ public String getPluginId() {
+ return pluginId;
+ }
+
+ public String toString() {
+ if (toString == null) {
+ toString = "CommandMenuContributionDescriptor[commandId=" + getCommandId() + ", after=" + getAfter() + "]"; //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
+ }
+ return toString;
+ }
+
+}
Index: src/org/eclipse/ui/internal/navigator/extensions/CommandMenuContributionDescriptorManager.java
===================================================================
RCS file: src/org/eclipse/ui/internal/navigator/extensions/CommandMenuContributionDescriptorManager.java
diff -N src/org/eclipse/ui/internal/navigator/extensions/CommandMenuContributionDescriptorManager.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/ui/internal/navigator/extensions/CommandMenuContributionDescriptorManager.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,79 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Oakland Software Incorporated 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:
+ * Francis Upton IV, Oakland Software Incorporated - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.ui.internal.navigator.extensions;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.ui.internal.navigator.extensions.NavigatorContentRegistryReader;
+
+/**
+ * Manages descriptors consumed from the 'commandMenuContribution' elements of
+ * the org.eclipse.ui.navigator.navigatorContent extension point.
+ *
+ * @since 3.5
+ *
+ */
+public class CommandMenuContributionDescriptorManager {
+
+ private static final CommandMenuContributionDescriptorManager INSTANCE = new CommandMenuContributionDescriptorManager();
+
+ private CommandMenuContributionDescriptorManager() {
+
+ new RegistryReader().readRegistry();
+ }
+
+ /**
+ * @return the singleton instance of the this class
+ */
+ public static CommandMenuContributionDescriptorManager getInstance() {
+ return INSTANCE;
+ }
+
+ private final Set rootDescriptors = new HashSet();
+
+ private final List rootDescriptorsList = new ArrayList();
+
+ /**
+ * @return the descriptors
+ */
+ public List getDescriptors() {
+ return rootDescriptorsList;
+ }
+
+ /**
+ *
+ * @param descriptor
+ * A valid descriptor to begin managing.
+ */
+ protected void addActionDescriptor(CommandMenuContributionDescriptor descriptor) {
+ if (rootDescriptors.contains(descriptor.getCommandId())) {
+ return;
+ }
+ rootDescriptorsList.add(descriptor);
+ rootDescriptors.add(descriptor.getCommandId());
+ }
+
+ private class RegistryReader extends NavigatorContentRegistryReader {
+
+ protected boolean readElement(IConfigurationElement anElement) {
+ if (TAG_COMMAND_MENU_CONTRIBUTION.equals(anElement.getName())) {
+ addActionDescriptor(new CommandMenuContributionDescriptor(anElement));
+ return true;
+ }
+ return super.readElement(anElement);
+ }
+ }
+
+}
Index: src/org/eclipse/ui/internal/navigator/extensions/INavigatorContentExtPtConstants.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.ui.navigator/src/org/eclipse/ui/internal/navigator/extensions/INavigatorContentExtPtConstants.java,v
retrieving revision 1.9
diff -u -r1.9 INavigatorContentExtPtConstants.java
--- src/org/eclipse/ui/internal/navigator/extensions/INavigatorContentExtPtConstants.java 8 Mar 2009 14:34:56 -0000 1.9
+++ src/org/eclipse/ui/internal/navigator/extensions/INavigatorContentExtPtConstants.java 7 Mar 2010 01:58:53 -0000
@@ -20,6 +20,9 @@
String TAG_ACTION_PROVIDER = "actionProvider"; //$NON-NLS-1$
/** */
+ String TAG_COMMAND_MENU_CONTRIBUTION = "commandMenuContribution"; //$NON-NLS-1$
+
+ /** */
String TAG_NAVIGATOR_CONTENT = "navigatorContent"; //$NON-NLS-1$
/** */
@@ -62,6 +65,12 @@
String ATT_ID = "id"; //$NON-NLS-1$
/** */
+ String ATT_COMMAND_ID = "commandId"; //$NON-NLS-1$
+
+ /** */
+ String ATT_AFTER = "after"; //$NON-NLS-1$
+
+ /** */
String ATT_NAME = "name"; //$NON-NLS-1$
/** */
Index: src/org/eclipse/ui/internal/navigator/extensions/IViewerExtPtConstants.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.ui.navigator/src/org/eclipse/ui/internal/navigator/extensions/IViewerExtPtConstants.java,v
retrieving revision 1.5
diff -u -r1.5 IViewerExtPtConstants.java
--- src/org/eclipse/ui/internal/navigator/extensions/IViewerExtPtConstants.java 25 May 2009 20:52:48 -0000 1.5
+++ src/org/eclipse/ui/internal/navigator/extensions/IViewerExtPtConstants.java 7 Mar 2010 01:58:53 -0000
@@ -36,6 +36,12 @@
String TAG_VIEWER_ACTION_BINDING = "viewerActionBinding"; //$NON-NLS-1$
/** */
+ String TAG_VIEWER_COMMAND_BINDING = "viewerCommandMenuBinding"; //$NON-NLS-1$
+
+ /** */
+ String TAG_VIEWER_HANDLER_BINDING = "viewerHandlerBinding"; //$NON-NLS-1$
+
+ /** */
String TAG_POPUP_MENU = "popupMenu"; //$NON-NLS-1$
/** */
Index: src/org/eclipse/ui/internal/navigator/extensions/NavigatorViewerDescriptor.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.ui.navigator/src/org/eclipse/ui/internal/navigator/extensions/NavigatorViewerDescriptor.java,v
retrieving revision 1.12
diff -u -r1.12 NavigatorViewerDescriptor.java
--- src/org/eclipse/ui/internal/navigator/extensions/NavigatorViewerDescriptor.java 25 May 2009 20:52:48 -0000 1.12
+++ src/org/eclipse/ui/internal/navigator/extensions/NavigatorViewerDescriptor.java 7 Mar 2010 01:58:53 -0000
@@ -48,9 +48,11 @@
static final String ATT_PATTERN = "pattern"; //$NON-NLS-1$
- private static final String TAG_CONTENT_EXTENSION = "contentExtension"; //$NON-NLS-1$
+ static final String TAG_CONTENT_EXTENSION = "contentExtension"; //$NON-NLS-1$
- private static final String TAG_ACTION_EXTENSION = "actionExtension"; //$NON-NLS-1$
+ static final String TAG_ACTION_EXTENSION = "actionExtension"; //$NON-NLS-1$
+
+ static final String TAG_COMMAND_MENU_EXTENSION = "commandMenuExtension"; //$NON-NLS-1$
private final String viewerId;
@@ -60,6 +62,8 @@
private Binding contentBinding = new Binding(TAG_CONTENT_EXTENSION);
+ private Binding commandBinding = new Binding(TAG_COMMAND_MENU_EXTENSION);
+
private MenuInsertionPoint[] customInsertionPoints = null;
private boolean allowsPlatformContributions = true;
@@ -101,28 +105,6 @@
return popupMenuId != null ? popupMenuId : viewerId;
}
- /**
- * Consume an action binding for this viewer.
- *
- * @param element
- * The IConfigurationElement containing a viewerActionBinding
- * element.
- */
- public void consumeActionBinding(IConfigurationElement element) {
- consumeBinding(element, false);
- }
-
- /**
- * Consume a content binding for this viewer.
- *
- * @param element
- * The IConfigurationElement containing a viewerContentBinding
- * element.
- */
- public void consumeContentBinding(IConfigurationElement element) {
- consumeBinding(element, true);
- }
-
public boolean isRootExtension(String aContentExtensionId) {
return contentBinding.isRootExtension(aContentExtensionId);
}
@@ -139,6 +121,10 @@
return actionBinding.isVisibleExtension(anActionExtensionId);
}
+ public boolean isVisibleCommand(String aCommandId) {
+ return commandBinding.isVisibleExtension(aCommandId);
+ }
+
public boolean hasOverriddenRootExtensions() {
return contentBinding.hasOverriddenRootExtensions();
}
@@ -237,6 +223,20 @@
}
/**
+ * @param binding
+ */
+ public void setCommandBinding(Binding binding) {
+ commandBinding = binding;
+ }
+
+ /**
+ * @return the content Binding
+ */
+ public Binding getCommandBinding() {
+ return commandBinding;
+ }
+
+ /**
* @param assistants
*/
public void setDragAssistants(Set assistants) {
@@ -328,16 +328,26 @@
return dragAssistants;
}
- private void consumeBinding(IConfigurationElement element, boolean isContent) {
+ /**
+ * @param element
+ * @param bindingTag
+ */
+ public void consumeBinding(IConfigurationElement element, String bindingTag) {
IConfigurationElement[] includesElement = element
.getChildren(TAG_INCLUDES);
+ boolean respectRoots = false;
+ Binding binding = null;
+ if (bindingTag.equals(TAG_CONTENT_EXTENSION)) {
+ binding = contentBinding;
+ respectRoots = true;
+ } else if (bindingTag.equals(TAG_ACTION_EXTENSION))
+ binding = actionBinding;
+ else if (bindingTag.equals(TAG_COMMAND_MENU_EXTENSION))
+ binding = commandBinding;
+
if (includesElement.length == 1) {
- if (isContent) {
- contentBinding.consumeIncludes(includesElement[0], true);
- } else {
- actionBinding.consumeIncludes(includesElement[0], false);
- }
+ binding.consumeIncludes(includesElement[0], respectRoots);
} else if (includesElement.length >= 1) {
NavigatorPlugin.logError(0, NLS.bind(
CommonNavigatorMessages.Too_many_elements_Warning,
@@ -353,12 +363,7 @@
.getChildren(TAG_EXCLUDES);
if (excludesElement.length == 1) {
-
- if (isContent) {
- contentBinding.consumeExcludes(excludesElement[0]);
- } else {
- actionBinding.consumeExcludes(excludesElement[0]);
- }
+ binding.consumeExcludes(excludesElement[0]);
} else if (excludesElement.length >= 1) {
NavigatorPlugin.logError(0, NLS.bind(
CommonNavigatorMessages.Too_many_elements_Warning,
@@ -371,4 +376,11 @@
}
}
+ void setupFromParent(NavigatorViewerDescriptor parentDesc) {
+ setActionBinding(parentDesc.getActionBinding());
+ setContentBinding(parentDesc.getContentBinding());
+ setCommandBinding(parentDesc.getCommandBinding());
+ setDragAssistants(parentDesc.getDragAssistants());
+ }
+
}
Index: src/org/eclipse/ui/internal/navigator/extensions/NavigatorViewerDescriptorManager.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.ui.navigator/src/org/eclipse/ui/internal/navigator/extensions/NavigatorViewerDescriptorManager.java,v
retrieving revision 1.8
diff -u -r1.8 NavigatorViewerDescriptorManager.java
--- src/org/eclipse/ui/internal/navigator/extensions/NavigatorViewerDescriptorManager.java 8 Mar 2009 20:45:04 -0000 1.8
+++ src/org/eclipse/ui/internal/navigator/extensions/NavigatorViewerDescriptorManager.java 7 Mar 2010 01:58:53 -0000
@@ -46,9 +46,7 @@
NavigatorViewerDescriptor desc = (NavigatorViewerDescriptor) it.next();
NavigatorViewerDescriptor parentDesc = (NavigatorViewerDescriptor) viewerDescriptors.get(desc.getInheritBindingsFromViewer());
if (parentDesc != null) {
- desc.setActionBinding(parentDesc.getActionBinding());
- desc.setContentBinding(parentDesc.getContentBinding());
- desc.setDragAssistants(parentDesc.getDragAssistants());
+ desc.setupFromParent(parentDesc);
}
}
}
@@ -179,18 +177,28 @@
}
return true;
}
+
+ System.out.println("name: " + element.getName()); //$NON-NLS-1$
+
if (TAG_VIEWER_CONTENT_BINDING.equals(element.getName())) {
String viewerId = element.getAttribute(ATT_VIEWER_ID);
NavigatorViewerDescriptor descriptor = getNavigatorViewerDescriptor(viewerId);
- descriptor.consumeContentBinding(element);
+ descriptor.consumeBinding(element, NavigatorViewerDescriptor.TAG_CONTENT_EXTENSION);
return true;
}
if (TAG_VIEWER_ACTION_BINDING.equals(element.getName())) {
String viewerId = element.getAttribute(ATT_VIEWER_ID);
NavigatorViewerDescriptor descriptor = getNavigatorViewerDescriptor(viewerId);
- descriptor.consumeActionBinding(element);
+ descriptor.consumeBinding(element, NavigatorViewerDescriptor.TAG_ACTION_EXTENSION);
return true;
- } if (TAG_DRAG_ASSISTANT.equals(element.getName())) {
+ }
+ if (TAG_VIEWER_COMMAND_BINDING.equals(element.getName())) {
+ String viewerId = element.getAttribute(ATT_VIEWER_ID);
+ NavigatorViewerDescriptor descriptor = getNavigatorViewerDescriptor(viewerId);
+ descriptor.consumeBinding(element, NavigatorViewerDescriptor.TAG_COMMAND_MENU_EXTENSION);
+ return true;
+ }
+ if (TAG_DRAG_ASSISTANT.equals(element.getName())) {
String viewerId = element.getAttribute(ATT_VIEWER_ID);
NavigatorViewerDescriptor descriptor = getNavigatorViewerDescriptor(viewerId);
descriptor.addDragAssistant(new CommonDragAssistantDescriptor(element));
Index: src/org/eclipse/ui/navigator/CommonNavigator.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.ui.navigator/src/org/eclipse/ui/navigator/CommonNavigator.java,v
retrieving revision 1.47
diff -u -r1.47 CommonNavigator.java
--- src/org/eclipse/ui/navigator/CommonNavigator.java 8 Mar 2009 20:45:04 -0000 1.47
+++ src/org/eclipse/ui/navigator/CommonNavigator.java 7 Mar 2010 01:58:54 -0000
@@ -12,6 +12,7 @@
*******************************************************************************/
package org.eclipse.ui.navigator;
+import org.eclipse.core.commands.IHandler;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.PerformanceStats;
import org.eclipse.jface.action.IAction;
@@ -432,6 +433,17 @@
return super.getAdapter(adapter);
}
+
+ /**
+ * @param commandId
+ * @param handler
+ *
+ * @since 3.5
+ */
+ public void bindHandler(String commandId, IHandler handler) {
+
+ }
+
/**
* Returns the IShowInSource
for this view.
*/
Index: src/org/eclipse/ui/navigator/CommonViewer.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.ui.navigator/src/org/eclipse/ui/navigator/CommonViewer.java,v
retrieving revision 1.40
diff -u -r1.40 CommonViewer.java
--- src/org/eclipse/ui/navigator/CommonViewer.java 10 Jan 2010 09:48:50 -0000 1.40
+++ src/org/eclipse/ui/navigator/CommonViewer.java 7 Mar 2010 01:58:54 -0000
@@ -109,6 +109,7 @@
setContentProvider(contentService.createCommonContentProvider());
setLabelProvider(new NavigatorDecoratingLabelProvider(contentService.createCommonLabelProvider()));
initDragAndDrop();
+ contentService.bindCommandMenuContributions(this);
}
void setCommonNavigator(CommonNavigator navigator) {
Index: src/org/eclipse/ui/navigator/INavigatorViewerDescriptor.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.ui.navigator/src/org/eclipse/ui/navigator/INavigatorViewerDescriptor.java,v
retrieving revision 1.14
diff -u -r1.14 INavigatorViewerDescriptor.java
--- src/org/eclipse/ui/navigator/INavigatorViewerDescriptor.java 8 Mar 2009 20:45:04 -0000 1.14
+++ src/org/eclipse/ui/navigator/INavigatorViewerDescriptor.java 7 Mar 2010 01:58:54 -0000
@@ -93,6 +93,19 @@
boolean isVisibleActionExtension(String anActionExtensionId);
/**
+ * Returns true if a command with the given id is 'visible'. A command
+ * is 'visible' if it matches a viewerCommandMenuBinding for the
+ * given viewer id.
+ *
+ * @param aCommandId
+ * The id to query
+ * @return True if the command id matches a viewerCommandMenuBinding for
+ * the viewer id of this descriptor.
+ * @since 3.5
+ */
+ boolean isVisibleCommand(String aCommandId);
+
+ /**
* Returns true if the content extension of the given id matches a
* viewerContentBinding extension that declares isRoot as true.
*
#P org.eclipse.ui.navigator.resources
Index: plugin.properties
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.ui.navigator.resources/plugin.properties,v
retrieving revision 1.16
diff -u -r1.16 plugin.properties
--- plugin.properties 25 May 2009 20:52:22 -0000 1.16
+++ plugin.properties 7 Mar 2010 01:58:55 -0000
@@ -15,6 +15,8 @@
resourceGoTo.extension.name=Resources Go To
workingsets.extension.name=Working Sets
Common_Resource_Navigator=Project Explorer
+
+command.goToResource=Go To Resource
filters.startsWithDot.name=.* resources
filters.startsWithDot.description=Hides resources that begin with "."
Index: plugin.xml
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.ui.navigator.resources/plugin.xml,v
retrieving revision 1.42
diff -u -r1.42 plugin.xml
--- plugin.xml 22 Jan 2009 23:08:33 -0000 1.42
+++ plugin.xml 7 Mar 2010 01:58:55 -0000
@@ -58,6 +58,22 @@