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.core.plugin.IPluginModelBase; 25 import org.eclipse.pde.internal.core.PDECore; 26 import org.eclipse.pde.internal.core.PluginModelManager; 27 import org.eclipse.pde.internal.core.ibundle.IBundlePluginModelBase; 28 import org.eclipse.pde.internal.ui.PDEUIMessages; 29 import org.eclipse.swt.custom.BusyIndicator; 30 import org.eclipse.swt.widgets.Display; 31 import org.eclipse.ui.IObjectActionDelegate; 32 import org.eclipse.ui.IWorkbenchPart; 33 34 public class MigrationAction implements IObjectActionDelegate { 35 36 private ISelection fSelection; 37 38 44 public void setActivePart(IAction action, IWorkbenchPart targetPart) { 45 } 46 47 52 public void run(IAction action) { 53 IPluginModelBase[] modelsToMigrate = getModelsToMigrate(); 54 if (modelsToMigrate.length == 0) { 55 MessageDialog 56 .openInformation( 57 this.getDisplay().getActiveShell(), 58 PDEUIMessages.MigrationAction_find, PDEUIMessages.MigrationAction_none); return; 60 } 61 62 if (fSelection instanceof IStructuredSelection) { 63 Object [] elems = ((IStructuredSelection) fSelection).toArray(); 64 ArrayList models = new ArrayList (elems.length); 65 66 PluginModelManager manager = PDECore.getDefault().getModelManager(); 67 for (int i = 0; i < elems.length; i++) { 68 Object elem = elems[i]; 69 IProject project = null; 70 71 if (elem instanceof IFile) { 72 IFile file = (IFile) elem; 73 project = file.getProject(); 74 } else if (elem instanceof IProject) { 75 project = (IProject) elem; 76 } else if (elem instanceof IJavaProject) { 77 project = ((IJavaProject) elem).getProject(); 78 } 79 if (project != null) { 80 IPluginModelBase model = manager.findModel(project); 81 if (model != null) { 82 models.add(model); 83 } 84 } 85 } 86 87 final IPluginModelBase[] modelArray = (IPluginModelBase[]) models 88 .toArray(new IPluginModelBase[models.size()]); 89 90 MigratePluginWizard wizard = new MigratePluginWizard( 91 modelsToMigrate, modelArray); 92 final Display display = getDisplay(); 93 final WizardDialog dialog = new WizardDialog(display 94 .getActiveShell(), wizard); 95 BusyIndicator.showWhile(display, new Runnable () { 96 public void run() { 97 dialog.open(); 98 } 99 }); 100 } 101 } 102 103 109 public void selectionChanged(IAction action, ISelection selection) { 110 fSelection = selection; 111 } 112 113 private Display getDisplay() { 114 Display display = Display.getCurrent(); 115 if (display == null) { 116 display = Display.getDefault(); 117 } 118 return display; 119 } 120 121 private IPluginModelBase[] getModelsToMigrate() { 122 Vector result = new Vector (); 123 IPluginModelBase[] models = PDECore.getDefault() 124 .getModelManager().getWorkspaceModels(); 125 for (int i = 0; i < models.length; i++) { 126 if (!models[i].getUnderlyingResource().isLinked() 127 && models[i].isLoaded() 128 && !(models[i] instanceof IBundlePluginModelBase) 129 && models[i].getPluginBase().getSchemaVersion() == null) 130 result.add(models[i]); 131 } 132 return (IPluginModelBase[]) result.toArray(new IPluginModelBase[result 133 .size()]); 134 } 135 136 } 137 | Popular Tags |