KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > emf > codegen > action > AddJETNatureAction


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: AddJETNatureAction.java,v 1.2 2005/06/08 06:23:43 nickb Exp $
16  */

17 package org.eclipse.emf.codegen.action;
18
19
20 import java.util.ArrayList JavaDoc;
21 import java.util.Iterator JavaDoc;
22 import java.util.List JavaDoc;
23
24 import org.eclipse.core.resources.IProject;
25 import org.eclipse.core.runtime.CoreException;
26 import org.eclipse.core.runtime.IProgressMonitor;
27 import org.eclipse.jdt.core.IJavaProject;
28 import org.eclipse.jface.action.IAction;
29 import org.eclipse.jface.dialogs.ProgressMonitorDialog;
30 import org.eclipse.jface.operation.IRunnableWithProgress;
31 import org.eclipse.jface.viewers.ISelection;
32 import org.eclipse.jface.viewers.IStructuredSelection;
33 import org.eclipse.ui.IActionDelegate;
34
35 import org.eclipse.emf.codegen.jet.JETAddNatureOperation;
36 import org.eclipse.emf.codegen.presentation.CodeGenUIPlugin;
37
38
39 public class AddJETNatureAction implements IActionDelegate
40 {
41   protected List JavaDoc projects;
42   
43   public AddJETNatureAction()
44   {
45     super();
46     projects = new ArrayList JavaDoc();
47   }
48
49   public void run(IAction action)
50   {
51     if (action.isEnabled())
52     {
53       IRunnableWithProgress op =
54         new IRunnableWithProgress()
55         {
56           public void run(IProgressMonitor monitor)
57           {
58             try
59             {
60               JETAddNatureOperation addNature = new JETAddNatureOperation(projects);
61               addNature.run(monitor);
62             }
63             catch (CoreException e)
64             {
65               CodeGenUIPlugin.write(e);
66             }
67           }
68         };
69
70       try
71       {
72         ProgressMonitorDialog dialog =
73           new ProgressMonitorDialog(CodeGenUIPlugin.getPlugin().getWorkbench().getActiveWorkbenchWindow().getShell());
74         dialog.run(false, true, op);
75       }
76       catch (Exception JavaDoc e)
77       {
78         CodeGenUIPlugin.write(e);
79       }
80     }
81   }
82
83   public void selectionChanged(IAction action, ISelection selection)
84   {
85     projects.clear();
86     if (selection instanceof IStructuredSelection)
87     {
88       for (Iterator JavaDoc i = ((IStructuredSelection)selection).iterator(); i.hasNext(); )
89       {
90         Object JavaDoc object = i.next();
91         if (object instanceof IProject)
92         {
93           projects.add(object);
94         }
95         else if (object instanceof IJavaProject)
96         {
97           projects.add(((IJavaProject)object).getProject());
98         }
99       }
100     }
101   }
102 }
103
Popular Tags