Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-patch] Utility method to remove natures.

2002-10-30 Alain Magloire

        * src/.../CProjectNature.java (removeNature): Utility
        function to remove a nature from a project.
        (removeCNature): Utility method to remove the C Nature.
        * src/.../CCProjectNature.java (removeCCNature): Utility
        method to remove the CC nature.


Index: org/eclipse/cdt/core/CCProjectNature.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CCProjectNature.java,v
retrieving revision 1.2
diff -u -r1.2 CCProjectNature.java
--- org/eclipse/cdt/core/CCProjectNature.java	26 Jul 2002 19:15:13 -0000	1.2
+++ org/eclipse/cdt/core/CCProjectNature.java	30 Oct 2002 19:54:43 -0000
@@ -18,5 +18,9 @@
 	public static void addCCNature(IProject project, IProgressMonitor mon) throws CoreException {
 		addNature(project, CC_NATURE_ID, mon);
 	}
+	
+	public static void removeCCNature(IProject project, IProgressMonitor mon) throws CoreException {
+		removeNature(project, CC_NATURE_ID, mon);
+	}
 
 }
Index: org/eclipse/cdt/core/CProjectNature.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CProjectNature.java,v
retrieving revision 1.2
diff -u -r1.2 CProjectNature.java
--- org/eclipse/cdt/core/CProjectNature.java	26 Jul 2002 19:15:13 -0000	1.2
+++ org/eclipse/cdt/core/CProjectNature.java	30 Oct 2002 19:54:44 -0000
@@ -5,6 +5,11 @@
  * All Rights Reserved.
  */
  
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.eclipse.cdt.core.resources.IBuildInfo;
 import org.eclipse.core.resources.ICommand;
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.IProjectDescription;
@@ -16,8 +21,6 @@
 import org.eclipse.core.runtime.Path;
 import org.eclipse.core.runtime.Plugin;
 
-import org.eclipse.cdt.core.resources.IBuildInfo;
-
 
 
 public class CProjectNature implements IProjectNature {
@@ -40,6 +43,10 @@
 		addNature(project, C_NATURE_ID, mon);
 	}
 
+	public static void removeCNature(IProject project, IProgressMonitor mon) throws CoreException {
+		removeNature(project, C_NATURE_ID, mon);
+	}
+	
 	/**
 	 * Utility method for adding a nature to a project.
 	 * 
@@ -63,6 +70,22 @@
 		project.setDescription(description, monitor);
 	}
 
+	/**
+	 * Utility method for removing a project nature from a project.
+	 * 
+	 * @param proj the project to remove the nature from
+	 * @param natureId the nature id to remove
+	 * @param monitor a progress monitor to indicate the duration of the operation, or
+	 * <code>null</code> if progress reporting is not required.
+	 */
+	public static void removeNature(IProject project, String natureId, IProgressMonitor monitor) throws CoreException {
+		IProjectDescription description = project.getDescription();
+		String[] prevNatures= description.getNatureIds();
+		List newNatures = new ArrayList(Arrays.asList(prevNatures));
+		newNatures.remove(natureId);
+		description.setNatureIds((String[])newNatures.toArray(new String[newNatures.size()]));
+		project.setDescription(description, monitor);
+	}
 
     /**
      * Sets the path of the build command executable.



Back to the top