1 11 package org.eclipse.pde.internal.ui.wizards.tools; 12 13 import java.util.ArrayList ; 14 import java.util.Vector ; 15 16 import org.eclipse.core.resources.IFile; 17 import org.eclipse.core.resources.IProject; 18 import org.eclipse.jdt.core.IJavaProject; 19 import org.eclipse.jface.action.IAction; 20 import org.eclipse.jface.dialogs.MessageDialog; 21 import org.eclipse.jface.viewers.ISelection; 22 import org.eclipse.jface.viewers.IStructuredSelection; 23 import org.eclipse.jface.wizard.WizardDialog; 24 import org.eclipse.pde.internal.core.natures.PDE; 25 import org.eclipse.pde.internal.ui.PDEPlugin; 26 import org.eclipse.pde.internal.ui.PDEUIMessages; 27 import org.eclipse.swt.custom.BusyIndicator; 28 import org.eclipse.swt.widgets.Display; 29 import org.eclipse.ui.IObjectActionDelegate; 30 import org.eclipse.ui.IWorkbenchPart; 31 32 public class ConvertProjectsAction implements IObjectActionDelegate { 33 34 private ISelection fSelection; 35 36 42 public void setActivePart(IAction action, IWorkbenchPart targetPart) { 43 } 44 45 50 public void run(IAction action) { 51 IProject[] unconverted = getUnconvertedProjects(); 52 if (unconverted.length == 0) { 53 MessageDialog 54 .openInformation( 55 this.getDisplay().getActiveShell(), 56 PDEUIMessages.ConvertProjectsAction_find, PDEUIMessages.ConvertProjectsAction_none); return; 58 } 59 60 if (fSelection instanceof IStructuredSelection) { 61 Object [] elems = ((IStructuredSelection) fSelection).toArray(); 62 Vector initialSelection = new Vector (elems.length); 63 64 for (int i = 0; i < elems.length; i++) { 65 Object elem = elems[i]; 66 IProject project = null; 67 68 if (elem instanceof IFile) { 69 IFile file = (IFile) elem; 70 project = file.getProject(); 71 } else if (elem instanceof IProject) { 72 project = (IProject) elem; 73 } else if (elem instanceof IJavaProject) { 74 project = ((IJavaProject) elem).getProject(); 75 } 76 if (project != null) 77 initialSelection.add(project); 78 } 79 80 ConvertedProjectWizard wizard = new ConvertedProjectWizard( 81 unconverted, initialSelection); 82 83 final Display display = getDisplay(); 84 final WizardDialog dialog = new WizardDialog(display 85 .getActiveShell(), wizard); 86 BusyIndicator.showWhile(display, new Runnable () { 87 public void run() { 88 dialog.open(); 89 } 90 }); 91 } 92 } 93 94 100 public void selectionChanged(IAction action, ISelection selection) { 101 fSelection = selection; 102 } 103 104 public Display getDisplay() { 105 Display display = Display.getCurrent(); 106 if (display == null) 107 display = Display.getDefault(); 108 return display; 109 } 110 111 private IProject[] getUnconvertedProjects() { 112 ArrayList unconverted = new ArrayList (); 113 IProject[] projects = PDEPlugin.getWorkspace().getRoot().getProjects(); 114 for (int i = 0; i < projects.length; i++) { 115 if (projects[i].isOpen() && !PDE.hasPluginNature(projects[i]) 116 && !PDE.hasFeatureNature(projects[i]) 117 && !PDE.hasUpdateSiteNature(projects[i]) 118 && projects[i].getName().indexOf('%') == -1 119 && projects[i].getLocation().toString().indexOf('%') == -1) 120 unconverted.add(projects[i]); 121 } 122 return (IProject[]) unconverted 123 .toArray(new IProject[unconverted.size()]); 124 } 125 } 126 | Popular Tags |