001: /*******************************************************************************
002: * Copyright (c) 2006, 2007 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: * Alex Blewitt (alex_blewitt@yahoo.com) - contributed a patch for:
011: * o Add an 'Open Manifest' to projects to open the manifest editor
012: * (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=133692)
013: *******************************************************************************/package org.eclipse.pde.internal.ui.editor;
014:
015: import java.util.ArrayList;
016: import java.util.Iterator;
017:
018: import org.eclipse.core.resources.IFile;
019: import org.eclipse.core.resources.IProject;
020: import org.eclipse.jface.action.IAction;
021: import org.eclipse.jface.dialogs.MessageDialog;
022: import org.eclipse.jface.viewers.ISelection;
023: import org.eclipse.jface.viewers.IStructuredSelection;
024: import org.eclipse.osgi.util.NLS;
025: import org.eclipse.pde.internal.core.WorkspaceModelManager;
026: import org.eclipse.pde.internal.ui.IPDEUIConstants;
027: import org.eclipse.pde.internal.ui.PDEPlugin;
028: import org.eclipse.pde.internal.ui.PDEUIMessages;
029: import org.eclipse.swt.custom.BusyIndicator;
030: import org.eclipse.ui.IWorkbenchWindow;
031: import org.eclipse.ui.IWorkbenchWindowActionDelegate;
032: import org.eclipse.ui.PartInitException;
033: import org.eclipse.ui.ide.IDE;
034:
035: public class OpenManifestAction implements
036: IWorkbenchWindowActionDelegate {
037:
038: private ISelection fSelection;
039:
040: public OpenManifestAction() {
041: super ();
042: }
043:
044: public void dispose() {
045: }
046:
047: public void init(IWorkbenchWindow window) {
048: }
049:
050: public void run(IAction action) {
051: if (fSelection instanceof IStructuredSelection) {
052: IStructuredSelection ssel = (IStructuredSelection) fSelection;
053: Iterator it = ssel.iterator();
054: final ArrayList projects = new ArrayList();
055: while (it.hasNext()) {
056: Object element = it.next();
057: IProject proj = null;
058: if (element instanceof IFile)
059: proj = ((IFile) element).getProject();
060: else if (element instanceof IProject)
061: proj = (IProject) element;
062: if (WorkspaceModelManager.isPluginProject(proj))
063: projects.add(proj);
064: }
065: if (projects.size() > 0) {
066: BusyIndicator.showWhile(PDEPlugin
067: .getActiveWorkbenchShell().getDisplay(),
068: new Runnable() {
069: public void run() {
070: Iterator it = projects.iterator();
071: while (it.hasNext()) {
072: IProject project = (IProject) it
073: .next();
074: IFile file = project
075: .getFile("META-INF/MANIFEST.MF"); //$NON-NLS-1$
076: if (file == null || !file.exists())
077: file = project
078: .getFile("plugin.xml"); //$NON-NLS-1$
079: if (file == null || !file.exists())
080: file = project
081: .getFile("fragment.xml"); //$NON-NLS-1$
082: if (file == null || !file.exists())
083: MessageDialog
084: .openError(
085: PDEPlugin
086: .getActiveWorkbenchShell(),
087: PDEUIMessages.OpenManifestsAction_title,
088: NLS
089: .bind(
090: PDEUIMessages.OpenManifestsAction_cannotFind,
091: project
092: .getName()));
093: else
094: try {
095: IDE
096: .openEditor(
097: PDEPlugin
098: .getActivePage(),
099: file,
100: IPDEUIConstants.MANIFEST_EDITOR_ID);
101: } catch (PartInitException e) {
102: MessageDialog
103: .openError(
104: PDEPlugin
105: .getActiveWorkbenchShell(),
106: PDEUIMessages.OpenManifestsAction_title,
107: NLS
108: .bind(
109: PDEUIMessages.OpenManifestsAction_cannotOpen,
110: project
111: .getName()));
112: }
113: }
114: }
115: });
116: } else
117: MessageDialog.openInformation(PDEPlugin
118: .getActiveWorkbenchShell(),
119: PDEUIMessages.OpenManifestsAction_title,
120: PDEUIMessages.OpenManifestAction_noManifest);
121: }
122: }
123:
124: public void selectionChanged(IAction action, ISelection selection) {
125: fSelection = selection;
126: }
127: }
|