diff options
author | snjeza | 2011-07-23 17:28:17 +0000 |
---|---|---|
committer | Igor Fedorenko | 2011-08-04 02:06:17 +0000 |
commit | 69257df2ca151b98e75b65d5e4f97b25b4131dc7 (patch) | |
tree | 37d74a195ae962d378ffcbbbe40324841c4ea3c3 | |
parent | 691af24c2b882426c1c544d213d481e2c0276d69 (diff) | |
download | m2e-core-69257df2ca151b98e75b65d5e4f97b25b4131dc7.tar.gz m2e-core-69257df2ca151b98e75b65d5e4f97b25b4131dc7.tar.xz m2e-core-69257df2ca151b98e75b65d5e4f97b25b4131dc7.zip |
Fixing JBIDE-5914
Signed-off-by: snjeza <snjezana.peco@redhat.com>
-rw-r--r-- | org.eclipse.m2e.refactoring/OSGI-INF/l10n/bundle.properties | 3 | ||||
-rw-r--r-- | org.eclipse.m2e.refactoring/plugin.xml | 62 | ||||
-rw-r--r-- | org.eclipse.m2e.refactoring/src/org/eclipse/m2e/refactoring/rename/RenameArtifactHandler.java (renamed from org.eclipse.m2e.refactoring/src/org/eclipse/m2e/refactoring/rename/RenameArtifactAction.java) | 66 |
3 files changed, 71 insertions, 60 deletions
diff --git a/org.eclipse.m2e.refactoring/OSGI-INF/l10n/bundle.properties b/org.eclipse.m2e.refactoring/OSGI-INF/l10n/bundle.properties index 6f565cae..8edf851f 100644 --- a/org.eclipse.m2e.refactoring/OSGI-INF/l10n/bundle.properties +++ b/org.eclipse.m2e.refactoring/OSGI-INF/l10n/bundle.properties @@ -1,8 +1,7 @@ #Properties file for org.eclipse.m2e.refactoring Bundle-Vendor = Eclipse.org - m2e Bundle-Name = Maven Integration for Eclipse Refactoring -action.rename1.label = Rename Maven Artifact... -action.rename2.label = Rename Maven Artifact... +action.rename.label = Rename Maven Artifact... action.exclude1.label = Exclude Maven Artifact... action.exclude2.label = Exclude Maven Artifact... action.exclude3.label = Exclude Maven Artifact...
\ No newline at end of file diff --git a/org.eclipse.m2e.refactoring/plugin.xml b/org.eclipse.m2e.refactoring/plugin.xml index 64f1fa54..61f75bec 100644 --- a/org.eclipse.m2e.refactoring/plugin.xml +++ b/org.eclipse.m2e.refactoring/plugin.xml @@ -9,33 +9,43 @@ <?eclipse version="3.2"?> <plugin> + <extension point="org.eclipse.ui.menus"> + <menuContribution + locationURI="popup:org.eclipse.jdt.ui.refactoring.menu?after=additions"> + <command + commandId="org.eclipse.m2e.editor.RenameArtifactAction" + icon="$nl$/icons/m2.gif" + label="%action.rename.label" + id="org.eclipse.m2e.editor.RenameArtifactAction"> + <visibleWhen + checkEnabled="false"> + <with variable="selection"> + <count value="1"/> + <iterate> + <or> + <adapt type="org.eclipse.core.resources.IProject"> + <test property="org.eclipse.core.resources.projectNature" value="org.eclipse.m2e.core.maven2Nature"/> + </adapt> + <adapt type="org.eclipse.core.resources.IResource"> + <test property="org.eclipse.core.resources.name" value="pom.xml"/> + </adapt> + </or> + </iterate> + </with> + </visibleWhen> + </command> + </menuContribution> + </extension> + + <extension + point="org.eclipse.ui.commands"> + <command + id="org.eclipse.m2e.editor.RenameArtifactAction" + name="%action.rename.label" + defaultHandler="org.eclipse.m2e.refactoring.rename.RenameArtifactHandler"/> + </extension> + <extension point="org.eclipse.ui.popupMenus"> - <objectContribution - id="org.eclipse.m2e.refactoring.rename.pomContributor" - objectClass="org.eclipse.core.resources.IFile" - nameFilter="pom.xml" adaptable="true"> - <action id="org.eclipse.m2e.editor.RenamePomAction" - class="org.eclipse.m2e.refactoring.rename.RenameArtifactAction" - enablesFor="1" - label="%action.rename1.label" - menubarPath="group.edit"/> - <!-- add visibility condition for managed poms --> - </objectContribution> - <objectContribution id="org.eclipse.m2e.refactoring.rename.projectContributor" - objectClass="org.eclipse.core.resources.IProject" - adaptable="true"> - <action id="org.eclipse.m2e.editor.RenameProjectAction" - class="org.eclipse.m2e.refactoring.rename.RenameArtifactAction" - enablesFor="1" - label="%action.rename2.label" - menubarPath="org.eclipse.jdt.ui.refactoring.menu/MavenRefactoring"/> - <visibility> - <and> - <objectState name="open" value="true"/> - <objectState name="nature" value="org.eclipse.m2e.core.maven2Nature"/> - </and> - </visibility> - </objectContribution> <!-- actions in pom editor --> <objectContribution diff --git a/org.eclipse.m2e.refactoring/src/org/eclipse/m2e/refactoring/rename/RenameArtifactAction.java b/org.eclipse.m2e.refactoring/src/org/eclipse/m2e/refactoring/rename/RenameArtifactHandler.java index 3ded0280..c0afda28 100644 --- a/org.eclipse.m2e.refactoring/src/org/eclipse/m2e/refactoring/rename/RenameArtifactAction.java +++ b/org.eclipse.m2e.refactoring/src/org/eclipse/m2e/refactoring/rename/RenameArtifactHandler.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008-2010 Sonatype, Inc. + * Copyright (c) 2011 Sonatype, Inc. * 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 @@ -8,48 +8,35 @@ * Contributors: * Sonatype, Inc. - initial API and implementation *******************************************************************************/ - package org.eclipse.m2e.refactoring.rename; +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; -import org.eclipse.jface.action.IAction; +import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation; import org.eclipse.m2e.refactoring.internal.SaveDirtyFilesDialog; -import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.actions.ActionDelegate; -import org.eclipse.ui.internal.ObjectPluginAction; +import org.eclipse.ui.handlers.HandlerUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +public class RenameArtifactHandler extends AbstractHandler { + private static final Logger log = LoggerFactory.getLogger(RenameArtifactHandler.class); -/** - * @author Anton Kraev - */ -@SuppressWarnings("restriction") -public class RenameArtifactAction extends ActionDelegate { - private static final Logger log = LoggerFactory.getLogger(RenameArtifactAction.class); - - @Override - public void init(IAction action) { - super.init(action); - } - - @Override - public void run(IAction action) { - doRun(action); - } - - @Override - public void runWithEvent(IAction action, Event event) { - doRun(action); - } - - public void doRun(IAction action) { - Object element = ((IStructuredSelection) ((ObjectPluginAction) action).getSelection()).getFirstElement(); + /* (non-Javadoc) + * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent) + */ + public Object execute(ExecutionEvent event) throws ExecutionException { + ISelection selection = computeSelection(event); + if (! (selection instanceof IStructuredSelection)) { + return null; + } + Object element = ((IStructuredSelection) selection).getFirstElement(); if(element instanceof IFile) { rename((IFile) element); } else if (element instanceof IProject) { @@ -59,8 +46,9 @@ public class RenameArtifactAction extends ActionDelegate { rename(file); } } + return null; } - + private void rename(IFile file) { try { // get the model from existing file @@ -76,5 +64,19 @@ public class RenameArtifactAction extends ActionDelegate { log.error("Unable to rename " + file, e); } } -} + + protected ISelection computeSelection(ExecutionEvent event) { + ISelection selection = HandlerUtil.getActiveMenuSelection(event); + if (!(selection instanceof IStructuredSelection)) { + selection = HandlerUtil.getActiveMenuEditorInput(event); + } + if (!(selection instanceof IStructuredSelection)) { + selection = HandlerUtil.getCurrentSelection(event); + } + if (!(selection instanceof IStructuredSelection)) { + selection = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getSelection(); + } + return selection; + } +} |