Author: fbricon
Date: 2011-07-21 07:59:12 -0400 (Thu, 21 Jul 2011)
New Revision: 33098
Added:
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/generic/
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/generic/GenericCommandActionDelegate.java
Modified:
trunk/maven/plugins/org.jboss.tools.maven.ui/plugin.xml
Log:
JBIDE-8969 : add Select maven profiles to the menu
Modified: trunk/maven/plugins/org.jboss.tools.maven.ui/plugin.xml
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.ui/plugin.xml 2011-07-21 10:31:03 UTC (rev
33097)
+++ trunk/maven/plugins/org.jboss.tools.maven.ui/plugin.xml 2011-07-21 11:59:12 UTC (rev
33098)
@@ -59,26 +59,54 @@
sequence="Ctrl+Alt+P">
</key>
</extension>
+
+ <extension point="org.eclipse.ui.popupMenus">
+ <objectContribution
id="org.jboss.tools.maven.ui.profiles.selectFromProject"
+ objectClass="org.eclipse.core.resources.IProject"
+ adaptable="true">
+ <action
id="org.jboss.tools.maven.ui.commands.selectMavenProfileAction"
+
class="org.jboss.tools.maven.ui.generic.GenericCommandActionDelegate:org.jboss.tools.maven.ui.commands.selectMavenProfileCommand"
+ label="%Select_Maven_Profiles"
+ style="push"
+
definitionId="org.jboss.tools.maven.ui.commands.selectMavenProfileCommand"
+ menubarPath="org.eclipse.m2e.core.mavenMenu/open"
+ enablesFor="+"/>
+ <visibility>
+ <and>
+ <objectState name="open" value="true"/>
+ <objectState name="nature"
value="org.eclipse.m2e.core.maven2Nature"/>
+ </and>
+ </visibility>
+ </objectContribution>
+
+ <objectContribution
id="org.jboss.tools.maven.ui.profiles.selectFromPom"
+ objectClass="org.eclipse.core.resources.IFile"
+ adaptable="true">
+ <action
id="org.jboss.tools.maven.ui.commands.selectMavenProfileAction"
+
class="org.jboss.tools.maven.ui.generic.GenericCommandActionDelegate:org.jboss.tools.maven.ui.commands.selectMavenProfileCommand"
+ label="%Select_Maven_Profiles"
+ style="push"
+ menubarPath="org.eclipse.m2e.core.fileMenu/open"
+ enablesFor="+"/>
+ <visibility>
+ <objectState name="name" value="pom.xml"/>
+ </visibility>
+ </objectContribution>
+
+ <objectContribution
id="org.jboss.tools.maven.ui.profiles.selectFromWorkingSet"
+ adaptable="true"
+ objectClass="org.eclipse.ui.IWorkingSet">
+ <action
id="org.jboss.tools.maven.ui.commands.selectMavenProfileAction"
+
class="org.jboss.tools.maven.ui.generic.GenericCommandActionDelegate:org.jboss.tools.maven.ui.commands.selectMavenProfileCommand"
+ label="%Select_Maven_Profiles"
+ style="push"
+ menubarPath="org.eclipse.m2e.core.workingSetMenu/open"
+ enablesFor="+"/>
+ </objectContribution>
+
+ </extension>
- <!--FIXME I can't make the menu appear in the maven menu-->
- <extension
- point="org.eclipse.ui.menus">
- <menuContribution
locationURI="popup:org.eclipse.m2e.core.mavenMenu?after=additions"
allPopups="true">
- <!--menuContribution locationURI="popup:common.new.menu?after=new"
allPopups="true" -->
- <command
-
commandId="org.jboss.tools.maven.ui.commands.selectMavenProfileCommand"
- id="org.jboss.tools.maven.ui.menus.selectMavenProfileCommand"
- mnemonic="P">
-
- <!--reference
- definitionId="org.jboss.tools.maven.ui.mavenProject">
- </reference-->
-
- </command>
- </menuContribution>
- </extension>
-
- <extension
+ <extension
point="org.eclipse.ui.menus">
<menuContribution
locationURI="toolbar:org.eclipse.ui.main.toolbar?after=additions">
@@ -92,24 +120,8 @@
</command>
</toolbar>
</menuContribution>
- </extension>
+ </extension>
- <extension
- point="org.eclipse.core.expressions.definitions">
- <definition id="org.jboss.tools.maven.ui.mavenProject">
- <with variable="selection">
- <iterate ifEmpty="false" operator="or">
- <adapt type="org.eclipse.core.resources.IProject">
- <and>
- <objectState name="open" value="true"/>
- <objectState name="nature"
value="org.eclipse.m2e.core.maven2Nature"/>
- </and>
- </adapt>
- </iterate>
- </with>
- </definition>
- </extension>
-
<extension point="org.eclipse.ui.editors.templates">
<template
id="org.jboss.tools.maven.editor.xml.templates.repository.jboss.public"
contextTypeId="org.eclipse.m2e.editor.xml.templates.contextType.repositories"
Added:
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/generic/GenericCommandActionDelegate.java
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/generic/GenericCommandActionDelegate.java
(rev 0)
+++
trunk/maven/plugins/org.jboss.tools.maven.ui/src/org/jboss/tools/maven/ui/generic/GenericCommandActionDelegate.java 2011-07-21
11:59:12 UTC (rev 33098)
@@ -0,0 +1,248 @@
+/*******************************************************************************
+ * Copyright (c) 2006 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
+ * Red Hat - minor refactoring
+ *
+ * Original code taken from <a
href="http://wiki.eclipse.org/Platform_Command_Framework#Using_an_IA...
+ *
http://wiki.eclipse.org/Platform_Command_Framework#Using_an_IActionDelega...
+ ******************************************************************************/
+package org.jboss.tools.maven.ui.generic;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.eclipse.core.commands.Command;
+import org.eclipse.core.commands.IParameter;
+import org.eclipse.core.commands.Parameterization;
+import org.eclipse.core.commands.ParameterizedCommand;
+import org.eclipse.core.commands.common.NotDefinedException;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExecutableExtension;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.ui.IEditorActionDelegate;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IObjectActionDelegate;
+import org.eclipse.ui.IViewActionDelegate;
+import org.eclipse.ui.IViewPart;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.IWorkbenchWindowActionDelegate;
+import org.eclipse.ui.commands.ICommandService;
+import org.eclipse.ui.handlers.IHandlerService;
+import org.eclipse.ui.internal.registry.IWorkbenchRegistryConstants;
+
+/**
+ * This action delegate can be used to specify a command with or without
+ * parameters be called from an <action/> specified in actionSets,
+ * editorActions, viewActions, or popupMenus.
+ */
+public class GenericCommandActionDelegate implements
+ IWorkbenchWindowActionDelegate, IViewActionDelegate,
+ IEditorActionDelegate, IObjectActionDelegate, IExecutableExtension {
+
+ /**
+ * The commandId parameter needed when using the <class/> form for
+ * this IActionDelegate. Value is "commandId".
+ */
+ public static final String PARM_COMMAND_ID = "commandId"; //$NON-NLS-1$
+
+ private String commandId = null;
+
+ private Map<?, ?> parameterMap = null;
+
+ private ParameterizedCommand parameterizedCommand = null;
+
+ private IHandlerService handlerService = null;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose()
+ */
+ public void dispose() {
+ handlerService = null;
+ parameterizedCommand = null;
+ parameterMap = null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
+ */
+ public void run(IAction action) {
+ if (handlerService == null) {
+ // what, no handler service ... no problem
+ return;
+ }
+ try {
+ if (commandId != null) {
+ handlerService.executeCommand(commandId, null);
+ } else if (parameterizedCommand != null) {
+ handlerService.executeCommand(parameterizedCommand, null);
+ }
+ // else there is no command for this delegate
+ } catch (Exception e) {
+ // exceptions reduced for brevity
+ // and we won't just do a print out :-)
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction,
+ * org.eclipse.jface.viewers.ISelection)
+ */
+ public void selectionChanged(IAction action, ISelection selection) {
+ // we don't care, handlers get their selection from the
+ // ExecutionEvent application context
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.eclipse.core.runtime.IExecutableExtension#setInitializationData(org.eclipse.core.runtime.IConfigurationElement,
+ * java.lang.String, java.lang.Object)
+ */
+ public void setInitializationData(IConfigurationElement config,
+ String propertyName, Object data) throws CoreException {
+ String id = config.getAttribute(IWorkbenchRegistryConstants.ATT_ID);
+ // save the data until our init(*) call, where we can get
+ // the services.
+ if (data instanceof String) {
+ commandId = (String) data;
+ } else if (data instanceof Map) {
+ parameterMap = (Map<?, ?>) data;
+ if (parameterMap.get(PARM_COMMAND_ID) == null) {
+ Status status = new Status(IStatus.ERROR,
+ "org.jboss.tools.maven.ui.generic", "The '" + id
+ + "' action won't work without a commandId");
+ throw new CoreException(status);
+ }
+ } else {
+ Status status = new Status(
+ IStatus.ERROR,
+ "org.jboss.tools.maven.ui.generic",
+ "The '"
+ + id
+ + "' action won't work without some initialization
parameters");
+ throw new CoreException(status);
+ }
+ }
+
+ /**
+ * Build a command from the executable extension information.
+ *
+ * @param commandService
+ * to get the Command object
+ */
+ private void createCommand(ICommandService commandService) {
+ String id = (String) parameterMap.get(PARM_COMMAND_ID);
+ if (id == null) {
+ return;
+ }
+ if (parameterMap.size() == 1) {
+ commandId = id;
+ return;
+ }
+ try {
+ Command cmd = commandService.getCommand(id);
+ if (!cmd.isDefined()) {
+ // command not defined? no problem ...
+ return;
+ }
+ ArrayList<Parameterization> parameters = new
ArrayList<Parameterization>();
+ Iterator<?> i = parameterMap.keySet().iterator();
+ while (i.hasNext()) {
+ String parmName = (String) i.next();
+ if (PARM_COMMAND_ID.equals(parmName)) {
+ continue;
+ }
+ IParameter parm = cmd.getParameter(parmName);
+ if (parm == null) {
+ // asking for a bogus parameter? No problem
+ return;
+ }
+ parameters.add(new Parameterization(parm, (String) parameterMap
+ .get(parmName)));
+ }
+ parameterizedCommand = new ParameterizedCommand(cmd,
+ (Parameterization[]) parameters
+ .toArray(new Parameterization[parameters.size()]));
+ } catch (NotDefinedException e) {
+ // command is bogus? No problem, we'll do nothing.
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.eclipse.ui.IWorkbenchWindowActionDelegate#init(org.eclipse.ui.IWorkbenchWindow)
+ */
+ public void init(IWorkbenchWindow window) {
+ if (handlerService != null) {
+ // already initialized
+ return;
+ }
+
+ handlerService = (IHandlerService) window
+ .getService(IHandlerService.class);
+ if (parameterMap != null) {
+ ICommandService commandService = (ICommandService) window
+ .getService(ICommandService.class);
+ createCommand(commandService);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.IViewActionDelegate#init(org.eclipse.ui.IViewPart)
+ */
+ public void init(IViewPart view) {
+ init(view.getSite().getWorkbenchWindow());
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.eclipse.ui.IEditorActionDelegate#setActiveEditor(org.eclipse.jface.action.IAction,
+ * org.eclipse.ui.IEditorPart)
+ */
+ public void setActiveEditor(IAction action, IEditorPart targetEditor) {
+ // we don't actually care about the active editor, since that
+ // information is in the ExecutionEvent application context
+ // but we need to make sure we're initialized.
+ if (targetEditor != null) {
+ init(targetEditor.getSite().getWorkbenchWindow());
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.eclipse.ui.IObjectActionDelegate#setActivePart(org.eclipse.jface.action.IAction,
+ * org.eclipse.ui.IWorkbenchPart)
+ */
+ public void setActivePart(IAction action, IWorkbenchPart targetPart) {
+ // we don't actually care about the active part, since that
+ // information is in the ExecutionEvent application context
+ // but we need to make sure we're initialized.
+ if (targetPart != null) {
+ init(targetPart.getSite().getWorkbenchWindow());
+ }
+ }
+}
+