diff options
author | Alexander Kurtakov | 2010-08-31 11:26:48 +0000 |
---|---|---|
committer | Alexander Kurtakov | 2010-08-31 11:26:48 +0000 |
commit | 29b26c05c594be4255ede9fa9be6ed19bb249a30 (patch) | |
tree | 79e617e36bd58bb83f6bd736717aa68e1ecb62f9 | |
parent | fd4788ad3ec66834902b951228ddf1d817f6e77e (diff) | |
download | org.eclipse.linuxtools-29b26c05c594be4255ede9fa9be6ed19bb249a30.tar.gz org.eclipse.linuxtools-29b26c05c594be4255ede9fa9be6ed19bb249a30.tar.xz org.eclipse.linuxtools-29b26c05c594be4255ede9fa9be6ed19bb249a30.zip |
2010-08-31 Alexander Kurtakov <akurtako@redhat.com>
* META-INF/MANIFEST.MF: Move to using commands framework.
* plugin.xml: Likewise.
* src/org/eclipse/linuxtools/rpmstubby/popup/actions/StubifyAction.java: Make actions command handlers.
* src/org/eclipse/linuxtools/rpmstubby/popup/actions/StubifyFeatureAction.java (execute): Likewise.
* src/org/eclipse/linuxtools/rpmstubby/popup/actions/StubifyPomAction.java (execute): Likewise.
6 files changed, 171 insertions, 36 deletions
diff --git a/rpmstubby/org.eclipse.linuxtools.rpmstubby/ChangeLog b/rpmstubby/org.eclipse.linuxtools.rpmstubby/ChangeLog index 9073730e22..4efaba904a 100644 --- a/rpmstubby/org.eclipse.linuxtools.rpmstubby/ChangeLog +++ b/rpmstubby/org.eclipse.linuxtools.rpmstubby/ChangeLog @@ -1,3 +1,11 @@ +2010-08-31 Alexander Kurtakov <akurtako@redhat.com> + + * META-INF/MANIFEST.MF: Move to using commands framework. + * plugin.xml: Likewise. + * src/org/eclipse/linuxtools/rpmstubby/popup/actions/StubifyAction.java: Make actions command handlers. + * src/org/eclipse/linuxtools/rpmstubby/popup/actions/StubifyFeatureAction.java (execute): Likewise. + * src/org/eclipse/linuxtools/rpmstubby/popup/actions/StubifyPomAction.java (execute): Likewise. + 2010-05-31 Alexander Kurtakov <akurtako@redhat.com> * src/org/eclipse/linuxtools/rpmstubby/StubbyPomGenerator.java (generateJavadocSubpackage): Add missing Requires to javadoc subpackage. (bz#312865) diff --git a/rpmstubby/org.eclipse.linuxtools.rpmstubby/META-INF/MANIFEST.MF b/rpmstubby/org.eclipse.linuxtools.rpmstubby/META-INF/MANIFEST.MF index 6721adedd6..52b1ba021d 100644 --- a/rpmstubby/org.eclipse.linuxtools.rpmstubby/META-INF/MANIFEST.MF +++ b/rpmstubby/org.eclipse.linuxtools.rpmstubby/META-INF/MANIFEST.MF @@ -8,6 +8,7 @@ Bundle-Vendor: %provider Bundle-Localization: plugin Require-Bundle: org.eclipse.ui, org.eclipse.core.runtime, + org.eclipse.core.commands, org.eclipse.core.resources, org.eclipse.pde.core, org.eclipse.ui.ide, diff --git a/rpmstubby/org.eclipse.linuxtools.rpmstubby/plugin.xml b/rpmstubby/org.eclipse.linuxtools.rpmstubby/plugin.xml index 4cd44647ce..d539287b88 100644 --- a/rpmstubby/org.eclipse.linuxtools.rpmstubby/plugin.xml +++ b/rpmstubby/org.eclipse.linuxtools.rpmstubby/plugin.xml @@ -11,38 +11,6 @@ <plugin> - <extension point="org.eclipse.ui.popupMenus"> - <objectContribution objectClass="org.eclipse.core.resources.IFile" - nameFilter="feature.xml" id="org.eclipse.linuxtools.rpmstubby.contribution1"> - <menu label="%menu.label" path="additions" - id="org.eclipse.linuxtools.rpmstubby.menu1" /> - <action label="%action.label" - class="org.eclipse.linuxtools.rpmstubby.popup.actions.StubifyFeatureAction" - menubarPath="org.eclipse.linuxtools.rpmstubby.menu1/group1" - enablesFor="+" id="org.eclipse.linuxtools.rpmstubby.newAction" /> - </objectContribution> - <objectContribution objectClass="org.eclipse.core.resources.IProject" - adaptable="true" id="org.eclipse.linuxtools.rpmstubby.contribution2"> - <menu label="%menu.label" path="additions" - id="org.eclipse.linuxtools.rpmstubby.menu1" /> - <action label="%action.label" - class="org.eclipse.linuxtools.rpmstubby.popup.actions.StubifyFeatureAction" - menubarPath="org.eclipse.linuxtools.rpmstubby.menu1/group1" - enablesFor="+" id="org.eclipse.linuxtools.rpmstubby.newAction" /> - <visibility> - <objectState name="projectNature" value="org.eclipse.pde.FeatureNature" /> - </visibility> - </objectContribution> - <objectContribution objectClass="org.eclipse.core.resources.IFile" - nameFilter="pom.xml" id="org.eclipse.linuxtools.rpmstubby.contribution3"> - <menu label="%menu.label" path="additions" - id="org.eclipse.linuxtools.rpmstubby.menu1" /> - <action label="%action.label" - class="org.eclipse.linuxtools.rpmstubby.popup.actions.StubifyPomAction" - menubarPath="org.eclipse.linuxtools.rpmstubby.menu1/group1" - enablesFor="+" id="org.eclipse.linuxtools.rpmstubby.newAction" /> - </objectContribution> - </extension> <extension point="org.eclipse.ui.preferencePages"> <page category="org.eclipse.linuxtools.rpm.ui.editor.mainpage" class="org.eclipse.linuxtools.rpmstubby.preferences.StubbyPreferencePage" @@ -54,5 +22,79 @@ class="org.eclipse.linuxtools.rpmstubby.preferences.PreferenceInitializer"> </initializer> </extension> - + <extension + point="org.eclipse.ui.commands"> + <category + name="RPMStubby Commands" + description="Commands for the RPM Stubby plugin" + id="rpmstubby.commands"> + </category> + + <command + categoryId="rpmstubby.commands" + id="rpmstubby.stubifyFeature" + description="%action.label" + name="%action.label"> + </command> + <command + categoryId="rpmstubby.commands" + id="rpmstubby.stubifyPom" + description="%action.label" + name="%action.label"> + </command> + + </extension> + <extension + point="org.eclipse.ui.handlers"> + <handler + class="org.eclipse.linuxtools.rpmstubby.popup.actions.StubifyFeatureAction" + commandId="rpmstubby.stubifyFeature"> + </handler> + <handler + class="org.eclipse.linuxtools.rpmstubby.popup.actions.StubifyPomAction" + commandId="rpmstubby.stubifyPom"> + </handler> + </extension> + <extension + point="org.eclipse.ui.menus"> + <menuContribution + locationURI="popup:org.eclipse.ui.popup.any?after=additions"> + <command + commandId="rpmstubby.stubifyFeature"> + <visibleWhen> + <or> + <with variable="selection"> + <iterate ifEmpty="false"> + <adapt type="org.eclipse.core.resources.IResource"> + <test property="org.eclipse.core.resources.name" + value="feature.xml"/> + </adapt> + </iterate> + </with> + <with variable="selection"> + <iterate ifEmpty="false"> + <adapt type="org.eclipse.core.resources.IResource"> + <test property="org.eclipse.core.resources.projectNature" + value="org.eclipse.pde.FeatureNature"/> + </adapt> + </iterate> + </with> + </or> + </visibleWhen> + </command> + <command + commandId="rpmstubby.stubifyPom"> + <visibleWhen> + <with variable="selection"> + <iterate ifEmpty="false"> + <adapt type="org.eclipse.core.resources.IResource"> + <test property="org.eclipse.core.resources.name" + value="pom.xml"/> + </adapt> + </iterate> + </with> + </visibleWhen> + </command> + </menuContribution> + </extension> </plugin> diff --git a/rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/rpmstubby/popup/actions/StubifyAction.java b/rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/rpmstubby/popup/actions/StubifyAction.java index a18e4e403c..c1ee713a97 100644 --- a/rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/rpmstubby/popup/actions/StubifyAction.java +++ b/rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/rpmstubby/popup/actions/StubifyAction.java @@ -10,6 +10,7 @@ *******************************************************************************/ package org.eclipse.linuxtools.rpmstubby.popup.actions; +import org.eclipse.core.commands.AbstractHandler; import org.eclipse.jface.action.IAction; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ISelectionProvider; @@ -23,7 +24,7 @@ import org.eclipse.ui.IWorkbenchPart; * Base class for the different stubify actions. * */ -public abstract class StubifyAction implements IObjectActionDelegate { +public abstract class StubifyAction extends AbstractHandler implements IObjectActionDelegate { protected ISelection selection; diff --git a/rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/rpmstubby/popup/actions/StubifyFeatureAction.java b/rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/rpmstubby/popup/actions/StubifyFeatureAction.java index 3187b83a32..5b5c6fd4fe 100644 --- a/rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/rpmstubby/popup/actions/StubifyFeatureAction.java +++ b/rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/rpmstubby/popup/actions/StubifyFeatureAction.java @@ -2,16 +2,21 @@ package org.eclipse.linuxtools.rpmstubby.popup.actions; import java.util.Iterator; +import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.Path; import org.eclipse.jface.action.IAction; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.linuxtools.rpmstubby.SpecfileWriter; +import org.eclipse.ui.handlers.HandlerUtil; /** * Action handling stybifying RPM spec file from a Eclipse feature.xml file. - * + * */ public class StubifyFeatureAction extends StubifyAction { @@ -34,4 +39,41 @@ public class StubifyFeatureAction extends StubifyAction { SpecfileWriter specfileWriter = new SpecfileWriter(); specfileWriter.write(featureFile); } + + public Object execute(ExecutionEvent event) { + + IFile featureFile = null; + ISelection selection = HandlerUtil.getCurrentSelection(event); + if (selection instanceof IStructuredSelection) { + for (Object element : ((IStructuredSelection) selection).toList()) { + if (element instanceof IFile) { + featureFile = (IFile) element; + } else if (element instanceof IAdaptable) { + featureFile = (IFile) ((IAdaptable) element) + .getAdapter(IFile.class); + } + if (featureFile != null) { + SpecfileWriter specfileWriter = new SpecfileWriter(); + specfileWriter.write(featureFile); + } + } + // StructuredSelection structuredSelection = (StructuredSelection) + // selection; + // for (Iterator<?> selectionIter = structuredSelection.iterator(); + // selectionIter + // .hasNext();) { + // Object selected = selectionIter.next(); + // if (selected instanceof IProject) { + // featureFile = ((IProject) selected).getFile(new Path( + // "/feature.xml")); + // } else if (selected instanceof IFile) { + // featureFile = (IFile) selected; + // } else { + // // FIXME: error + // } + // } + + } + return null; + } } diff --git a/rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/rpmstubby/popup/actions/StubifyPomAction.java b/rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/rpmstubby/popup/actions/StubifyPomAction.java index b4e65597be..cd59ed8ce6 100644 --- a/rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/rpmstubby/popup/actions/StubifyPomAction.java +++ b/rpmstubby/org.eclipse.linuxtools.rpmstubby/src/org/eclipse/linuxtools/rpmstubby/popup/actions/StubifyPomAction.java @@ -12,14 +12,19 @@ package org.eclipse.linuxtools.rpmstubby.popup.actions; import java.util.Iterator; +import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.resources.IFile; +import org.eclipse.core.runtime.IAdaptable; import org.eclipse.jface.action.IAction; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.linuxtools.rpmstubby.SpecfilePomWriter; +import org.eclipse.ui.handlers.HandlerUtil; /** * Action handling stybifying RPM spec file from a Maven pom.xml file. - * + * */ public class StubifyPomAction extends StubifyAction { @@ -40,4 +45,40 @@ public class StubifyPomAction extends StubifyAction { specfileWriter.write(pomFile); } + public Object execute(ExecutionEvent event) { + IFile featureFile = null; + ISelection selection = HandlerUtil.getCurrentSelection(event); + if (selection instanceof IStructuredSelection) { + for (Object element : ((IStructuredSelection) selection).toList()) { + if (element instanceof IFile) { + featureFile = (IFile) element; + } else if (element instanceof IAdaptable) { + featureFile = (IFile) ((IAdaptable) element) + .getAdapter(IFile.class); + } + if (featureFile != null) { + SpecfilePomWriter specfileWriter = new SpecfilePomWriter(); + specfileWriter.write(featureFile); + } + } + // StructuredSelection structuredSelection = (StructuredSelection) + // selection; + // for (Iterator<?> selectionIter = structuredSelection.iterator(); + // selectionIter + // .hasNext();) { + // Object selected = selectionIter.next(); + // if (selected instanceof IProject) { + // featureFile = ((IProject) selected).getFile(new Path( + // "/feature.xml")); + // } else if (selected instanceof IFile) { + // featureFile = (IFile) selected; + // } else { + // // FIXME: error + // } + // } + + } + return null; + } + } |