KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > editor > OpenManifestAction


1 /*******************************************************************************
2  * Copyright (c) 2006, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  * Alex Blewitt (alex_blewitt@yahoo.com) - contributed a patch for:
11  * o Add an 'Open Manifest' to projects to open the manifest editor
12  * (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=133692)
13  *******************************************************************************/

14 package org.eclipse.pde.internal.ui.editor;
15
16 import java.util.ArrayList JavaDoc;
17 import java.util.Iterator JavaDoc;
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 JavaDoc it = ssel.iterator();
54             final ArrayList JavaDoc projects = new ArrayList JavaDoc();
55             while (it.hasNext()) {
56                 Object JavaDoc 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 JavaDoc() {
68                     public void run() {
69                         Iterator JavaDoc it = projects.iterator();
70                         while (it.hasNext()) {
71                             IProject project = (IProject) it.next();
72                             IFile file = project.getFile("META-INF/MANIFEST.MF"); //$NON-NLS-1$
73
if (file == null || !file.exists())
74                                 file = project.getFile("plugin.xml"); //$NON-NLS-1$
75
if (file == null || !file.exists())
76                                 file = project.getFile("fragment.xml"); //$NON-NLS-1$
77
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