1 14 package org.eclipse.pde.internal.ui.editor; 15 16 import java.util.ArrayList ; 17 import java.util.Iterator ; 18 19 import org.eclipse.core.resources.IFile; 20 import org.eclipse.core.resources.IProject; 21 import org.eclipse.jface.action.IAction; 22 import org.eclipse.jface.dialogs.MessageDialog; 23 import org.eclipse.jface.viewers.ISelection; 24 import org.eclipse.jface.viewers.IStructuredSelection; 25 import org.eclipse.osgi.util.NLS; 26 import org.eclipse.pde.internal.core.WorkspaceModelManager; 27 import org.eclipse.pde.internal.ui.IPDEUIConstants; 28 import org.eclipse.pde.internal.ui.PDEPlugin; 29 import org.eclipse.pde.internal.ui.PDEUIMessages; 30 import org.eclipse.swt.custom.BusyIndicator; 31 import org.eclipse.ui.IWorkbenchWindow; 32 import org.eclipse.ui.IWorkbenchWindowActionDelegate; 33 import org.eclipse.ui.PartInitException; 34 import org.eclipse.ui.ide.IDE; 35 36 public class OpenManifestAction implements IWorkbenchWindowActionDelegate { 37 38 private ISelection fSelection; 39 40 public OpenManifestAction() { 41 super(); 42 } 43 44 public void dispose() { 45 } 46 47 public void init(IWorkbenchWindow window) { 48 } 49 50 public void run(IAction action) { 51 if (fSelection instanceof IStructuredSelection) { 52 IStructuredSelection ssel = (IStructuredSelection) fSelection; 53 Iterator it = ssel.iterator(); 54 final ArrayList projects = new ArrayList (); 55 while (it.hasNext()) { 56 Object element = it.next(); 57 IProject proj = null; 58 if (element instanceof IFile) 59 proj = ((IFile) element).getProject(); 60 else if (element instanceof IProject) 61 proj = (IProject) element; 62 if (WorkspaceModelManager.isPluginProject(proj)) 63 projects.add(proj); 64 } 65 if (projects.size() > 0) { 66 BusyIndicator.showWhile(PDEPlugin.getActiveWorkbenchShell() 67 .getDisplay(), new Runnable () { 68 public void run() { 69 Iterator it = projects.iterator(); 70 while (it.hasNext()) { 71 IProject project = (IProject) it.next(); 72 IFile file = project.getFile("META-INF/MANIFEST.MF"); if (file == null || !file.exists()) 74 file = project.getFile("plugin.xml"); if (file == null || !file.exists()) 76 file = project.getFile("fragment.xml"); if (file == null || !file.exists()) 78 MessageDialog.openError(PDEPlugin 79 .getActiveWorkbenchShell(), 80 PDEUIMessages.OpenManifestsAction_title, 81 NLS.bind(PDEUIMessages.OpenManifestsAction_cannotFind, project.getName())); 82 else 83 try { 84 IDE.openEditor(PDEPlugin.getActivePage(), file, IPDEUIConstants.MANIFEST_EDITOR_ID); 85 } catch (PartInitException e) { 86 MessageDialog.openError(PDEPlugin 87 .getActiveWorkbenchShell(), 88 PDEUIMessages.OpenManifestsAction_title, 89 NLS.bind(PDEUIMessages.OpenManifestsAction_cannotOpen, project.getName())); 90 } 91 } 92 } 93 }); 94 } else 95 MessageDialog.openInformation(PDEPlugin 96 .getActiveWorkbenchShell(), 97 PDEUIMessages.OpenManifestsAction_title, 98 PDEUIMessages.OpenManifestAction_noManifest); 99 } 100 } 101 public void selectionChanged(IAction action, ISelection selection) { 102 fSelection = selection; 103 } 104 } 105 | Popular Tags |