1 17 package org.eclipse.emf.codegen.action; 18 19 20 import java.util.ArrayList ; 21 import java.util.Iterator ; 22 import java.util.List ; 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 projects; 42 43 public AddJETNatureAction() 44 { 45 super(); 46 projects = new ArrayList (); 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 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 i = ((IStructuredSelection)selection).iterator(); i.hasNext(); ) 89 { 90 Object 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 |