[jbosstools-commits] JBoss Tools SVN: r42914 - in trunk/archives/plugins: org.jboss.ide.eclipse.archives.ui and 1 other directories.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Wed Aug 8 06:55:19 EDT 2012


Author: rob.stryker at jboss.com
Date: 2012-08-08 06:55:18 -0400 (Wed, 08 Aug 2012)
New Revision: 42914

Modified:
   trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/src/eclipse/org/jboss/ide/eclipse/archives/core/project/ProjectUtils.java
   trunk/archives/plugins/org.jboss.ide.eclipse.archives.ui/plugin.xml
   trunk/archives/plugins/org.jboss.ide.eclipse.archives.ui/src/main/org/jboss/ide/eclipse/archives/ui/ArchivesUIMessages.java
   trunk/archives/plugins/org.jboss.ide.eclipse.archives.ui/src/main/org/jboss/ide/eclipse/archives/ui/ArchivesUIMessages.properties
Log:
JBIDE-11927 to trunk

Modified: trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/src/eclipse/org/jboss/ide/eclipse/archives/core/project/ProjectUtils.java
===================================================================
--- trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/src/eclipse/org/jboss/ide/eclipse/archives/core/project/ProjectUtils.java	2012-08-08 10:54:55 UTC (rev 42913)
+++ trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/src/eclipse/org/jboss/ide/eclipse/archives/core/project/ProjectUtils.java	2012-08-08 10:55:18 UTC (rev 42914)
@@ -10,47 +10,111 @@
  ******************************************************************************/
 package org.jboss.ide.eclipse.archives.core.project;
 
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.IProjectDescription;
 import org.eclipse.core.resources.ResourcesPlugin;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.NullProgressMonitor;
 
 public class ProjectUtils {
-	
+
 	public static boolean addProjectNature(IPath path) {
-		IProject[] allProjects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
-		for( int i = 0; i < allProjects.length; i++ ) {
-			if( allProjects[i].getLocation().equals(path)) {
-				return addProjectNature(allProjects[i], ArchivesNature.NATURE_ID);
+		IProject[] allProjects = ResourcesPlugin.getWorkspace().getRoot()
+				.getProjects();
+		for (int i = 0; i < allProjects.length; i++) {
+			if (allProjects[i].getLocation().equals(path)) {
+				return addProjectNature(allProjects[i],
+						ArchivesNature.NATURE_ID);
 			}
 		}
 		return false;
 	}
 
-	   public static boolean addProjectNature(IProject project, String natureId) {
-		   boolean added = false;
-		   try {
-			   if (project != null && natureId != null) {
-				   IProjectDescription desc = project.getDescription();
-				   
-				   if (!project.hasNature(natureId)) {
-					   String natureIds[] = desc.getNatureIds();
-					   String newNatureIds[] = new String[natureIds.length + 1];
-					   
-					   System.arraycopy(natureIds, 0, newNatureIds, 1, natureIds.length);
-					   newNatureIds[0] = natureId;
-					   desc.setNatureIds(newNatureIds);
-					   
-					   project.getProject().setDescription(desc, new NullProgressMonitor());
-					   added = true;
-				   }
-			   }
-		   } catch (CoreException e) {
-			   e.printStackTrace();
-		   }
-		   return added;
-	   }
+	public static boolean addProjectNature(IProject project, String natureId) {
+		return addProjectNature(project, natureId, null);
+	}
+	
+	/**
+	 * @since 3.3
+	 */
+	public static boolean addProjectNature(IProject project, String natureId, IProgressMonitor monitor) {
+		monitor = monitor == null ? new NullProgressMonitor() : monitor;
+		boolean added = false;
+		try {
+			if (project != null && natureId != null) {
+				IProjectDescription desc = project.getDescription();
 
+				if (!project.hasNature(natureId)) {
+					String natureIds[] = desc.getNatureIds();
+					String newNatureIds[] = new String[natureIds.length + 1];
+
+					System.arraycopy(natureIds, 0, newNatureIds, 1,
+							natureIds.length);
+					newNatureIds[0] = natureId;
+					desc.setNatureIds(newNatureIds);
+
+					project.getProject().setDescription(desc, monitor);
+					added = true;
+				}
+			}
+		} catch (CoreException e) {
+			e.printStackTrace();
+		}
+		return added;
+	}
+
+	/**
+	 * @since 3.3
+	 */
+	public static boolean removeProjectNature(IPath path) {
+		IProject[] allProjects = ResourcesPlugin.getWorkspace().getRoot()
+				.getProjects();
+		for (int i = 0; i < allProjects.length; i++) {
+			if (allProjects[i].getLocation().equals(path)) {
+				return removeProjectNature(allProjects[i],
+						ArchivesNature.NATURE_ID);
+			}
+		}
+		return false;
+	}
+
+	/**
+	 * @since 3.3
+	 */
+	public static boolean removeProjectNature(IProject project, String natureId) {
+		return removeProjectNature(project, natureId, null);
+	}
+	/**
+	 * @since 3.3
+	 */
+	public static boolean removeProjectNature(IProject project, String natureId, IProgressMonitor monitor) {
+		monitor = monitor == null ? new NullProgressMonitor() : monitor;
+		boolean removed = false;
+		try {
+			if (project != null && natureId != null) {
+				IProjectDescription desc = project.getDescription();
+				if (project.hasNature(natureId)) {
+					String natureIds[] = desc.getNatureIds();
+					List<String> l = Arrays.asList(natureIds);
+					ArrayList<String> newDesc = new ArrayList<String>();
+					newDesc.addAll(l);
+					newDesc.remove(natureId);
+					String[] asArr = (String[]) newDesc.toArray(new String[newDesc.size()]);
+					desc.setNatureIds(asArr);
+					project.getProject().setDescription(desc, monitor);
+					removed = true;
+				}
+			}
+		} catch (CoreException e) {
+			e.printStackTrace();
+		}
+		return removed;
+	}
+
 }

Modified: trunk/archives/plugins/org.jboss.ide.eclipse.archives.ui/plugin.xml
===================================================================
--- trunk/archives/plugins/org.jboss.ide.eclipse.archives.ui/plugin.xml	2012-08-08 10:54:55 UTC (rev 42913)
+++ trunk/archives/plugins/org.jboss.ide.eclipse.archives.ui/plugin.xml	2012-08-08 10:55:18 UTC (rev 42914)
@@ -245,4 +245,64 @@
             sequence="M3+M2+Y B">
       </key>
    </extension>
+   
+   <extension
+         point="org.eclipse.ui.commands">
+      <command
+            defaultHandler="org.jboss.ide.eclipse.archives.ui.actions.EnableHandler"
+            id="org.jboss.ide.eclipse.archives.ui.actions.enableProjectArchives"
+            name="Add Project Archives Support">
+      </command>
+      <command
+            defaultHandler="org.jboss.ide.eclipse.archives.ui.actions.DisableHandler"
+            id="org.jboss.ide.eclipse.archives.ui.actions.disableProjectArchives"
+            name="Remove Project Archives Support">
+      </command>
+   </extension>
+   <extension
+         point="org.eclipse.ui.menus">
+      <menuContribution
+            allPopups="false"
+            locationURI="popup:org.eclipse.ui.projectConfigure?before=additions">
+          <command
+                  commandId="org.jboss.ide.eclipse.archives.ui.actions.enableProjectArchives"
+                  label="Add Project Archives Support"
+                  style="push">
+            <visibleWhen
+                  checkEnabled="false">
+               <and>
+                  <count value="1"/>
+                  <with variable="activeMenuSelection"/>
+                  <iterate ifEmpty="false" operator="and">
+					 <adapt type="org.eclipse.core.resources.IResource"/>
+                     <not><test
+                              forcePluginActivation="false"
+                              property="org.eclipse.core.resources.projectNature"
+                              value="org.jboss.ide.eclipse.archives.core.archivesNature">
+                     </test> </not>
+               </iterate></and>
+            </visibleWhen>
+          </command>
+
+          <command
+                  commandId="org.jboss.ide.eclipse.archives.ui.actions.disableProjectArchives"
+                  label="Remove Project Archives Support"
+                  style="push">
+            <visibleWhen
+                  checkEnabled="false">
+               <and>
+                  <count value="1"/>
+                  <with variable="activeMenuSelection"/>
+                  <iterate ifEmpty="false" operator="and">
+					 <adapt type="org.eclipse.core.resources.IResource"/>
+					 <test
+                              forcePluginActivation="false"
+                              property="org.eclipse.core.resources.projectNature"
+                              value="org.jboss.ide.eclipse.archives.core.archivesNature">
+                     </test>
+               </iterate></and>
+            </visibleWhen>
+          </command>
+      </menuContribution>
+   </extension>
 </plugin>

Modified: trunk/archives/plugins/org.jboss.ide.eclipse.archives.ui/src/main/org/jboss/ide/eclipse/archives/ui/ArchivesUIMessages.java
===================================================================
--- trunk/archives/plugins/org.jboss.ide.eclipse.archives.ui/src/main/org/jboss/ide/eclipse/archives/ui/ArchivesUIMessages.java	2012-08-08 10:54:55 UTC (rev 42913)
+++ trunk/archives/plugins/org.jboss.ide.eclipse.archives.ui/src/main/org/jboss/ide/eclipse/archives/ui/ArchivesUIMessages.java	2012-08-08 10:55:18 UTC (rev 42914)
@@ -115,6 +115,9 @@
 	public static String deleteNodeMBDesc;
 	public static String deleteNodeMBToggle;
 	
+	public static String EnableProjectArchivesJob;
+	public static String DisableProjectArchivesJob;
+	public static String DisableProjectArchivesJobError;
 	
 	static {
 		NLS.initializeMessages("org.jboss.ide.eclipse.archives.ui.ArchivesUIMessages", ArchivesUIMessages.class); //$NON-NLS-1$

Modified: trunk/archives/plugins/org.jboss.ide.eclipse.archives.ui/src/main/org/jboss/ide/eclipse/archives/ui/ArchivesUIMessages.properties
===================================================================
--- trunk/archives/plugins/org.jboss.ide.eclipse.archives.ui/src/main/org/jboss/ide/eclipse/archives/ui/ArchivesUIMessages.properties	2012-08-08 10:54:55 UTC (rev 42913)
+++ trunk/archives/plugins/org.jboss.ide.eclipse.archives.ui/src/main/org/jboss/ide/eclipse/archives/ui/ArchivesUIMessages.properties	2012-08-08 10:55:18 UTC (rev 42914)
@@ -97,3 +97,6 @@
 deleteNodeMBTitle=Delete this node?
 deleteNodeMBDesc=Are you sure you want to delete this node? This cannot be undone.
 deleteNodeMBToggle=Always delete without prompting.
+EnableProjectArchivesJob=Enabling Project Archives on project {0}
+DisableProjectArchivesJob=Disabling Project Archives on project {0}
+DisableProjectArchivesJobError=Unable to completely remove Project Archives support on project {0}
\ No newline at end of file



More information about the jbosstools-commits mailing list