Author: max.andersen(a)jboss.com
Date: 2007-07-16 14:07:11 -0400 (Mon, 16 Jul 2007)
New Revision: 2448
Added:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/builder/
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/builder/ToggleSeamNatureAction.java
Modified:
trunk/seam/plugins/org.jboss.tools.seam.ui/plugin.xml
Log:
JBIDE-581 add/remove seam nature
Modified: trunk/seam/plugins/org.jboss.tools.seam.ui/plugin.xml
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.ui/plugin.xml 2007-07-16 15:50:25 UTC (rev
2447)
+++ trunk/seam/plugins/org.jboss.tools.seam.ui/plugin.xml 2007-07-16 18:07:11 UTC (rev
2448)
@@ -205,6 +205,24 @@
<partitiontype id="org.eclipse.jst.jsp.SCRIPT.JSP_EL2" />
</contentAssistProcessor>
- </extension>
+ </extension>
+
+ <extension
+ point="org.eclipse.ui.popupMenus">
+ <!-- TODO: We should either remove this or move it to a not so prominient place
in the final release -->
+ <objectContribution
+ adaptable="true"
+ id="org.jboss.tools.seam.ui.enableSeamAction"
+ nameFilter="*"
+ objectClass="org.eclipse.core.resources.IProject">
+ <action
+ class="org.jboss.tools.seam.ui.builder.ToggleSeamNatureAction"
+ enablesFor="+"
+ id="org.jboss.tools.seam.ui.addRemoveSeamNatureAction"
+ label="Add/Remove Seam support"
+ menubarPath="additions">
+ </action>
+ </objectContribution>
+ </extension>
</plugin>
Added:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/builder/ToggleSeamNatureAction.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/builder/ToggleSeamNatureAction.java
(rev 0)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/builder/ToggleSeamNatureAction.java 2007-07-16
18:07:11 UTC (rev 2448)
@@ -0,0 +1,103 @@
+package org.jboss.tools.seam.ui.builder;
+
+import java.util.Iterator;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IProjectDescription;
+import org.eclipse.core.runtime.CoreException;
+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.ui.IObjectActionDelegate;
+import org.eclipse.ui.IWorkbenchPart;
+import org.jboss.tools.seam.core.ISeamProject;
+
+/**
+ * Class for toggling the Seam Nature.
+ *
+ * @author max
+ *
+ */
+public class ToggleSeamNatureAction implements IObjectActionDelegate {
+
+ private ISelection selection;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
+ */
+ public void run(IAction action) {
+ if (selection instanceof IStructuredSelection) {
+ for (Iterator it = ((IStructuredSelection) selection).iterator(); it
+ .hasNext();) {
+ Object element = it.next();
+ IProject project = null;
+ if (element instanceof IProject) {
+ project = (IProject) element;
+ } else if (element instanceof IAdaptable) {
+ project = (IProject) ((IAdaptable) element)
+ .getAdapter(IProject.class);
+ }
+ if (project != null) {
+ toggleNature(project);
+ }
+ }
+ }
+ }
+
+ /*
+ * (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) {
+ this.selection = selection;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.eclipse.ui.IObjectActionDelegate#setActivePart(org.eclipse.jface.action.IAction,
+ * org.eclipse.ui.IWorkbenchPart)
+ */
+ public void setActivePart(IAction action, IWorkbenchPart targetPart) {
+ }
+
+ /**
+ * Toggles sample nature on a project
+ *
+ * @param project
+ * to have sample nature added or removed
+ */
+ private void toggleNature(IProject project) {
+ try {
+ IProjectDescription description = project.getDescription();
+ String[] natures = description.getNatureIds();
+
+ for (int i = 0; i < natures.length; ++i) {
+ if (ISeamProject.NATURE_ID.equals(natures[i])) {
+ // Remove the nature
+ String[] newNatures = new String[natures.length - 1];
+ System.arraycopy(natures, 0, newNatures, 0, i);
+ System.arraycopy(natures, i + 1, newNatures, i,
+ natures.length - i - 1);
+ description.setNatureIds(newNatures);
+ project.setDescription(description, null);
+ return;
+ }
+ }
+
+ // Add the nature
+ String[] newNatures = new String[natures.length + 1];
+ System.arraycopy(natures, 0, newNatures, 0, natures.length);
+ newNatures[natures.length] = ISeamProject.NATURE_ID;
+ description.setNatureIds(newNatures);
+ project.setDescription(description, null);
+ } catch (CoreException e) {
+ }
+ }
+
+}