1 17 package org.eclipse.emf.codegen.jet; 18 19 20 import java.util.ArrayList ; 21 import java.util.Collection ; 22 import java.util.Iterator ; 23 import java.util.List ; 24 25 import org.eclipse.core.resources.IProject; 26 import org.eclipse.core.resources.IProjectDescription; 27 import org.eclipse.core.resources.IWorkspaceRunnable; 28 import org.eclipse.core.runtime.CoreException; 29 import org.eclipse.core.runtime.IProgressMonitor; 30 import org.eclipse.core.runtime.SubProgressMonitor; 31 32 import org.eclipse.emf.codegen.CodeGenPlugin; 33 34 35 public class JETAddNatureOperation implements IWorkspaceRunnable 36 { 37 protected List projects; 38 39 42 public JETAddNatureOperation(Collection objects) 43 { 44 super(); 45 projects = new ArrayList (); 46 for (Iterator i = objects.iterator(); i.hasNext(); ) 47 { 48 Object object = i.next(); 49 if (object instanceof IProject) 50 { 51 projects.add(object); 52 } 53 } 54 } 55 56 59 public void run(IProgressMonitor monitor) throws CoreException 60 { 61 if (!projects.isEmpty()) 62 { 63 monitor.beginTask("", projects.size()); 64 monitor.subTask(CodeGenPlugin.getPlugin().getString("_UI_AddJETNature_message")); 65 66 for (Iterator i = projects.iterator(); i.hasNext(); ) 67 { 68 IProject project = (IProject)i.next(); 69 70 monitor.subTask(CodeGenPlugin.getPlugin().getString("_UI_AddJETNatureTo_message", new Object [] { project.getName() })); 71 IProjectDescription description = project.getDescription(); 72 String [] natures = description.getNatureIds(); 73 String [] newNatures = new String [natures.length + 1]; 74 System.arraycopy(natures, 0, newNatures, 1, natures.length); 75 newNatures[0] = IJETNature.NATURE_ID; 76 description.setNatureIds(newNatures); 77 project.setDescription(description, new SubProgressMonitor(monitor, 1)); 78 } 79 80 monitor.done(); 81 } 82 } 83 } 84 | Popular Tags |