KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > emf > codegen > jet > JETAddNatureOperation


1 /**
2  * <copyright>
3  *
4  * Copyright (c) 2002-2004 IBM Corporation and others.
5  * All rights reserved. This program and the accompanying materials
6  * are made available under the terms of the Eclipse Public License v1.0
7  * which accompanies this distribution, and is available at
8  * http://www.eclipse.org/legal/epl-v10.html
9  *
10  * Contributors:
11  * IBM - Initial API and implementation
12  *
13  * </copyright>
14  *
15  * $Id: JETAddNatureOperation.java,v 1.2 2005/06/08 06:15:56 nickb Exp $
16  */

17 package org.eclipse.emf.codegen.jet;
18
19
20 import java.util.ArrayList JavaDoc;
21 import java.util.Collection JavaDoc;
22 import java.util.Iterator JavaDoc;
23 import java.util.List JavaDoc;
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 JavaDoc projects;
38
39   /**
40    * Creates an instance from the given collection of projects.
41    */

42   public JETAddNatureOperation(Collection JavaDoc objects)
43   {
44     super();
45     projects = new ArrayList JavaDoc();
46     for (Iterator JavaDoc i = objects.iterator(); i.hasNext(); )
47     {
48       Object JavaDoc object = i.next();
49       if (object instanceof IProject)
50       {
51         projects.add(object);
52       }
53     }
54   }
55
56   /**
57    * Perform this operation.
58    */

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 JavaDoc i = projects.iterator(); i.hasNext(); )
67       {
68         IProject project = (IProject)i.next();
69
70         monitor.subTask(CodeGenPlugin.getPlugin().getString("_UI_AddJETNatureTo_message", new Object JavaDoc [] { project.getName() }));
71         IProjectDescription description = project.getDescription();
72         String JavaDoc[] natures = description.getNatureIds();
73         String JavaDoc[] newNatures = new String JavaDoc[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