Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFred Bricon2013-05-03 05:51:26 -0400
committerFred Bricon2013-05-03 07:18:45 -0400
commit420e5747caf031d8a8b1d7312a48d832605d0c71 (patch)
treee8a5fc283e66666de08b471c80eef0be810e5487
parent6797fecbe72e9cf828b24b9a5c7c6cf7525058d9 (diff)
downloadm2e-core-420e5747caf031d8a8b1d7312a48d832605d0c71.tar.gz
m2e-core-420e5747caf031d8a8b1d7312a48d832605d0c71.tar.xz
m2e-core-420e5747caf031d8a8b1d7312a48d832605d0c71.zip
407153 : convert 'Update Project' to a Command
This commit converts the existing 'Update Project' to use an Eclipse Command. That command is by default bound to Ctrl+Alt+U. The existing o.e.m.c.u.i.UpdateMavenProjectAction class is deprecated in favor of o.e.m.c.u.i.UpdateMavenProjectCommandHandler. Selection related methods from MavenActionSupport and MavenProjectActionSupport have been refactored to SelectionUtil, to prevent code duplication Signed-off-by: Fred Bricon <fbricon@gmail.com>
-rw-r--r--org.eclipse.m2e.core.ui/plugin.properties2
-rw-r--r--org.eclipse.m2e.core.ui/plugin.xml22
-rw-r--r--org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/actions/MavenActionSupport.java45
-rw-r--r--org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/actions/MavenProjectActionSupport.java40
-rw-r--r--org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/actions/SelectionUtil.java94
-rw-r--r--org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/actions/UpdateMavenProjectAction.java16
-rw-r--r--org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/actions/UpdateMavenProjectCommandHandler.java55
7 files changed, 182 insertions, 92 deletions
diff --git a/org.eclipse.m2e.core.ui/plugin.properties b/org.eclipse.m2e.core.ui/plugin.properties
index a3a5a5d8..6f61fac0 100644
--- a/org.eclipse.m2e.core.ui/plugin.properties
+++ b/org.eclipse.m2e.core.ui/plugin.properties
@@ -59,6 +59,7 @@ m2.editor.pom.name=Maven POM Editor
m2.shortcut.addDependency=Add Maven Dependency
m2.shortcut.addPlugin=Add Maven Plugin
+m2.shortcut.updateProject=Update Project
openpomaction.label = Open POM
openpomaction.label2 = Open POM
@@ -71,6 +72,7 @@ openprojectaction.label4 = Open Project Page
command.opentype.description = Open Maven Type
command.adddependency.description = Add Maven Dependency
command.addplugin.description = Add Maven Plugin
+command.updateproject.description = Update Maven Project configuration and dependencies
keyword.label = maven
page.installations.name = Installations
page.usersettings.name = User Settings
diff --git a/org.eclipse.m2e.core.ui/plugin.xml b/org.eclipse.m2e.core.ui/plugin.xml
index 965e5522..74008e2c 100644
--- a/org.eclipse.m2e.core.ui/plugin.xml
+++ b/org.eclipse.m2e.core.ui/plugin.xml
@@ -125,6 +125,7 @@
objectClass="org.eclipse.core.resources.IProject"
adaptable="true">
<action id="org.eclipse.m2e.updateProjectAction"
+ definitionId="org.eclipse.m2e.core.ui.command.updateProject"
class="org.eclipse.m2e.core.ui.internal.actions.UpdateMavenProjectAction"
label="%m2.popup.UpdateMavenProjectAction"
style="push"
@@ -260,6 +261,7 @@
adaptable="true"
objectClass="org.eclipse.ui.IWorkingSet">
<action id="org.eclipse.m2e.updateConfigurationAction"
+ definitionId="org.eclipse.m2e.core.ui.command.updateProject"
class="org.eclipse.m2e.core.ui.internal.actions.UpdateMavenProjectAction"
label="%m2.popup.UpdateMavenProjectAction"
style="push"
@@ -368,8 +370,22 @@
id="org.eclipse.m2e.core.ui.command.addPlugin"
name="%m2.shortcut.addPlugin">
</command>
+ <command
+ categoryId="org.eclipse.ui.category.window"
+ description="%command.updateproject.description"
+ id="org.eclipse.m2e.core.ui.command.updateProject"
+ name="%m2.shortcut.updateProject">
+ </command>
</extension>
+ <extension
+ point="org.eclipse.ui.handlers">
+ <handler
+ class="org.eclipse.m2e.core.ui.internal.actions.UpdateMavenProjectCommandHandler"
+ commandId="org.eclipse.m2e.core.ui.command.updateProject">
+ </handler>
+ </extension>
+
<extension point="org.eclipse.ui.keywords">
<keyword id="org.eclipse.m2e.core.maven" label="%keyword.label"/>
</extension>
@@ -508,6 +524,12 @@
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
sequence="Ctrl+Shift+P">
</key>
+ <key
+ commandId="org.eclipse.m2e.core.ui.command.updateProject"
+ contextId="org.eclipse.ui.contexts.window"
+ schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
+ sequence="Ctrl+Alt+U">
+ </key>
</extension>
<extension point="org.eclipse.ui.propertyPages">
<page id="org.eclipse.m2e.core.MavenProjectPreferencePage"
diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/actions/MavenActionSupport.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/actions/MavenActionSupport.java
index 29868768..a2217a0c 100644
--- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/actions/MavenActionSupport.java
+++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/actions/MavenActionSupport.java
@@ -18,26 +18,19 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.IEditorInput;
-import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbench;
-import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.PlatformUI;
import org.eclipse.m2e.core.MavenPlugin;
import org.eclipse.m2e.core.embedder.ArtifactKey;
import org.eclipse.m2e.core.embedder.ArtifactRef;
-import org.eclipse.m2e.core.internal.IMavenConstants;
import org.eclipse.m2e.core.project.IMavenProjectFacade;
import org.eclipse.m2e.core.ui.internal.M2EUIPluginActivator;
@@ -100,43 +93,7 @@ public abstract class MavenActionSupport implements IObjectActionDelegate {
}
protected IFile getPomFileFromPomEditorOrViewSelection() {
- IFile file = null;
-
- //350136 we need to process the selection first! that's what is relevant for any popup menu action we have.
- //the processing of active editor first might have been only relevant when we had the actions in main menu, but even
- // then the popups were wrong..
- Object o = selection.iterator().next();
-
- if(o instanceof IProject) {
- file = ((IProject) o).getFile(IMavenConstants.POM_FILE_NAME);
- } else if(o instanceof IFile) {
- file = (IFile) o;
- }
- if(file != null) {
- return file;
- }
- //
- // If I am in the POM editor I want to get hold of the IFile that is currently in the buffer
- //
- IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
-
- if(window != null) {
- IWorkbenchPage page = window.getActivePage();
- if(page != null) {
- IEditorPart editor = page.getActiveEditor();
- if(editor != null) {
- IEditorInput input = editor.getEditorInput();
- if(input instanceof IFileEditorInput) {
- IFileEditorInput fileInput = (IFileEditorInput) input;
- file = fileInput.getFile();
- if(file.getName().equals(IMavenConstants.POM_FILE_NAME)) {
- return file;
- }
- }
- }
- }
- }
- return null;
+ return SelectionUtil.getPomFileFromPomEditorOrViewSelection(selection);
}
}
diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/actions/MavenProjectActionSupport.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/actions/MavenProjectActionSupport.java
index 514c0273..fbf9521c 100644
--- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/actions/MavenProjectActionSupport.java
+++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/actions/MavenProjectActionSupport.java
@@ -11,53 +11,15 @@
package org.eclipse.m2e.core.ui.internal.actions;
-import java.util.ArrayList;
-import java.util.Iterator;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
-import org.eclipse.ui.IWorkingSet;
-
-import org.eclipse.m2e.core.internal.IMavenConstants;
public abstract class MavenProjectActionSupport extends MavenActionSupport implements IWorkbenchWindowActionDelegate {
- private static final Logger log = LoggerFactory.getLogger(MavenProjectActionSupport.class);
-
protected IProject[] getProjects() {
- ArrayList<IProject> projectList = new ArrayList<IProject>();
- if(selection != null) {
- for(Iterator<?> it = selection.iterator(); it.hasNext();) {
- Object o = it.next();
- if(o instanceof IProject) {
- projectList.add((IProject) o);
- } else if(o instanceof IWorkingSet) {
- IWorkingSet workingSet = (IWorkingSet) o;
- for(IAdaptable adaptable : workingSet.getElements()) {
- IProject project = (IProject) adaptable.getAdapter(IProject.class);
- try {
- if(project != null && project.isAccessible() && project.hasNature(IMavenConstants.NATURE_ID)) {
- projectList.add(project);
- }
- } catch(CoreException ex) {
- log.error(ex.getMessage(), ex);
- }
- }
- }
- }
- }
- if(projectList.isEmpty()) {
- return ResourcesPlugin.getWorkspace().getRoot().getProjects();
- }
- return projectList.toArray(new IProject[projectList.size()]);
+ return SelectionUtil.getProjects(selection);
}
public void dispose() {
diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/actions/SelectionUtil.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/actions/SelectionUtil.java
index d845902f..e26ac3f6 100644
--- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/actions/SelectionUtil.java
+++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/actions/SelectionUtil.java
@@ -27,6 +27,7 @@ import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IStorage;
+import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IPath;
@@ -36,10 +37,14 @@ import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.IStorageEditorInput;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.IWorkingSet;
import org.eclipse.ui.IWorkingSetManager;
import org.eclipse.ui.PlatformUI;
@@ -354,4 +359,93 @@ public class SelectionUtil {
throw new CoreException(new Status(IStatus.ERROR, IMavenConstants.PLUGIN_ID, -1, //
Messages.SelectionUtil_error_cannot_read, null));
}
+
+ /**
+ * Finds the pom.xml from the given selection or the current active pom editor.
+ *
+ * @param selection
+ * @return the first pom.xml from the given selection or the current active pom editor. returns
+ * <code>null</null> if no pom was found.
+ * @since 1.4.0
+ */
+ public static IFile getPomFileFromPomEditorOrViewSelection(ISelection selection) {
+ IFile file = null;
+
+ //350136 we need to process the selection first! that's what is relevant for any popup menu action we have.
+ //the processing of active editor first might have been only relevant when we had the actions in main menu, but even
+ // then the popups were wrong..
+ if(selection instanceof IStructuredSelection) {
+ Object o = ((IStructuredSelection) selection).iterator().next();
+
+ if(o instanceof IProject) {
+ file = ((IProject) o).getFile(IMavenConstants.POM_FILE_NAME);
+ } else if(o instanceof IFile) {
+ file = (IFile) o;
+ }
+ if(file != null) {
+ return file;
+ }
+ }
+ //
+ // If I am in the POM editor I want to get hold of the IFile that is currently in the buffer
+ //
+ IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+
+ if(window != null) {
+ IWorkbenchPage page = window.getActivePage();
+ if(page != null) {
+ IEditorPart editor = page.getActiveEditor();
+ if(editor != null) {
+ IEditorInput input = editor.getEditorInput();
+ if(input instanceof IFileEditorInput) {
+ IFileEditorInput fileInput = (IFileEditorInput) input;
+ file = fileInput.getFile();
+ if(file.getName().equals(IMavenConstants.POM_FILE_NAME)) {
+ return file;
+ }
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Returns all the Maven projects found in the given selection, or all the workspace projects if no Maven project was
+ * found.
+ *
+ * @param selection
+ * @return an array of {@link IProject} containing all the Maven projects found in the given selection, or all the
+ * workspace projects if no Maven project was found.
+ * @since 1.4.0
+ */
+ public static IProject[] getProjects(ISelection selection) {
+ ArrayList<IProject> projectList = new ArrayList<IProject>();
+ if(selection instanceof IStructuredSelection) {
+ for(Iterator<?> it = ((IStructuredSelection) selection).iterator(); it.hasNext();) {
+ Object o = it.next();
+ if(o instanceof IProject) {
+ projectList.add((IProject) o);
+ } else if(o instanceof IWorkingSet) {
+ IWorkingSet workingSet = (IWorkingSet) o;
+ for(IAdaptable adaptable : workingSet.getElements()) {
+ IProject project = (IProject) adaptable.getAdapter(IProject.class);
+ try {
+ if(project != null && project.isAccessible() && project.hasNature(IMavenConstants.NATURE_ID)) {
+ projectList.add(project);
+ }
+ } catch(CoreException ex) {
+ log.error(ex.getMessage(), ex);
+ }
+ }
+ }
+ }
+ }
+
+ if(projectList.isEmpty()) {
+ return ResourcesPlugin.getWorkspace().getRoot().getProjects();
+ }
+ return projectList.toArray(new IProject[projectList.size()]);
+ }
+
}
diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/actions/UpdateMavenProjectAction.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/actions/UpdateMavenProjectAction.java
index ae1d8e97..471fb0f5 100644
--- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/actions/UpdateMavenProjectAction.java
+++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/actions/UpdateMavenProjectAction.java
@@ -12,12 +12,14 @@
package org.eclipse.m2e.core.ui.internal.actions;
import org.eclipse.jface.action.IAction;
-import org.eclipse.jface.window.Window;
-
-import org.eclipse.m2e.core.ui.internal.UpdateMavenProjectJob;
-import org.eclipse.m2e.core.ui.internal.dialogs.UpdateMavenProjectsDialog;
+/**
+ * UpdateMavenProjectAction
+ *
+ * @deprecated this action is deprecated in favor of {@link UpdateMavenProjectCommandHandler}
+ */
+@Deprecated
public class UpdateMavenProjectAction extends MavenProjectActionSupport {
public static final String ID = "org.eclipse.m2e.updateConfigurationAction"; //$NON-NLS-1$
@@ -26,11 +28,7 @@ public class UpdateMavenProjectAction extends MavenProjectActionSupport {
}
public void run(IAction action) {
- UpdateMavenProjectsDialog dialog = new UpdateMavenProjectsDialog(getShell(), getProjects());
- if(dialog.open() == Window.OK) {
- new UpdateMavenProjectJob(dialog.getSelectedProjects(), dialog.isOffline(), dialog.isForceUpdateDependencies(),
- dialog.isUpdateConfiguration(), dialog.isCleanProjects(), dialog.isRefreshFromLocal()).schedule();
- }
+ UpdateMavenProjectCommandHandler.openUpdateProjectsDialog(getShell(), getProjects());
}
}
diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/actions/UpdateMavenProjectCommandHandler.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/actions/UpdateMavenProjectCommandHandler.java
new file mode 100644
index 00000000..1c63c636
--- /dev/null
+++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/actions/UpdateMavenProjectCommandHandler.java
@@ -0,0 +1,55 @@
+/*******************************************************************************
+ * Copyright (c) 2008-2013 Sonatype, Inc. 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:
+ * Sonatype, Inc. - initial API and implementation
+ * Red Hat, Inc. - transformed into a CommandHandler
+ *******************************************************************************/
+
+package org.eclipse.m2e.core.ui.internal.actions;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.window.Window;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+import org.eclipse.m2e.core.ui.internal.UpdateMavenProjectJob;
+import org.eclipse.m2e.core.ui.internal.dialogs.UpdateMavenProjectsDialog;
+
+
+/**
+ * Handler for the Update Projectcommand. This can then be bound to whatever keybinding the user prefers (defaults to
+ * Ctrl+Alt+U).
+ *
+ * @author Fred Bricon
+ */
+public class UpdateMavenProjectCommandHandler extends AbstractHandler {
+
+ public Object execute(final ExecutionEvent event) {
+
+ ISelection selection = HandlerUtil.getCurrentSelection(event);
+
+ Shell shell = HandlerUtil.getActiveWorkbenchWindow(event).getShell();
+
+ IProject[] projects = SelectionUtil.getProjects(selection);
+
+ openUpdateProjectsDialog(shell, projects);
+
+ return null;
+ }
+
+ /* package */static void openUpdateProjectsDialog(Shell shell, IProject[] projects) {
+ UpdateMavenProjectsDialog dialog = new UpdateMavenProjectsDialog(shell, projects);
+ if(dialog.open() == Window.OK) {
+ new UpdateMavenProjectJob(dialog.getSelectedProjects(), dialog.isOffline(), dialog.isForceUpdateDependencies(),
+ dialog.isUpdateConfiguration(), dialog.isCleanProjects(), dialog.isRefreshFromLocal()).schedule();
+ }
+ }
+}

Back to the top