summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian de Alwis2012-09-10 12:10:22 (EDT)
committer Curtis Windatt2012-09-10 12:10:22 (EDT)
commit681416dc20c22431f23e420b4a49d555b305dd38 (patch)
tree52faeddcfc3705574d7810826047f7cb2925a018
parent6274078c24b501ed8f02933fa00801544565e6dd (diff)
downloadeclipse.pde.ui-681416dc20c22431f23e420b4a49d555b305dd38.zip
eclipse.pde.ui-681416dc20c22431f23e420b4a49d555b305dd38.tar.gz
eclipse.pde.ui-681416dc20c22431f23e420b4a49d555b305dd38.tar.bz2
Bug 387251 - OpenManifestHandler should open manifest for current editor if the active partv20120910-161022I20120911-1000
-rw-r--r--ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/OpenManifestHandler.java74
1 files changed, 47 insertions, 27 deletions
diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/OpenManifestHandler.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/OpenManifestHandler.java
index a45391c..088a5a1 100644
--- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/OpenManifestHandler.java
+++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/OpenManifestHandler.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2011 IBM Corporation and others.
+ * Copyright (c) 2006, 2011, 2012 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -10,6 +10,7 @@
* Alex Blewitt (alex_blewitt@yahoo.com) - contributed a patch for:
* o Add an 'Open Manifest' to projects to open the manifest editor
* (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=133692)
+ * Brian de Alwis - open manifest for the currently active editor
*******************************************************************************/
package org.eclipse.pde.internal.ui.editor;
@@ -17,7 +18,7 @@ import java.util.HashSet;
import java.util.Iterator;
import org.eclipse.core.commands.*;
import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.*;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
@@ -26,7 +27,7 @@ import org.eclipse.pde.internal.core.WorkspaceModelManager;
import org.eclipse.pde.internal.core.project.PDEProject;
import org.eclipse.pde.internal.ui.*;
import org.eclipse.swt.custom.BusyIndicator;
-import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.*;
import org.eclipse.ui.handlers.HandlerUtil;
import org.eclipse.ui.ide.IDE;
import org.eclipse.ui.model.IWorkbenchAdapter;
@@ -41,11 +42,18 @@ public class OpenManifestHandler extends AbstractHandler {
* @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
*/
public Object execute(ExecutionEvent event) throws ExecutionException {
+ final HashSet projects = new HashSet();
+ if (HandlerUtil.getActivePart(event) instanceof IEditorPart) {
+ IEditorInput input = ((IEditorPart) HandlerUtil.getActivePart(event)).getEditorInput();
+ IProject proj = getProject(input);
+ if (proj != null && WorkspaceModelManager.isPluginProject(proj)) {
+ projects.add(proj);
+ }
+ }
ISelection selection = HandlerUtil.getCurrentSelection(event);
if (selection instanceof IStructuredSelection) {
IStructuredSelection ssel = (IStructuredSelection) selection;
Iterator it = ssel.iterator();
- final HashSet projects = new HashSet();
while (it.hasNext()) {
Object element = it.next();
IProject proj = null;
@@ -75,30 +83,42 @@ public class OpenManifestHandler extends AbstractHandler {
if (proj != null && WorkspaceModelManager.isPluginProject(proj))
projects.add(proj);
}
- if (projects.size() > 0) {
- BusyIndicator.showWhile(PDEPlugin.getActiveWorkbenchShell().getDisplay(), new Runnable() {
- public void run() {
- Iterator it = projects.iterator();
- while (it.hasNext()) {
- IProject project = (IProject) it.next();
- IFile file = PDEProject.getManifest(project);
- if (file == null || !file.exists())
- file = PDEProject.getPluginXml(project);
- if (file == null || !file.exists())
- file = PDEProject.getFragmentXml(project);
- if (file == null || !file.exists())
- MessageDialog.openError(PDEPlugin.getActiveWorkbenchShell(), PDEUIMessages.OpenManifestsAction_title, NLS.bind(PDEUIMessages.OpenManifestsAction_cannotFind, project.getName()));
- else
- try {
- IDE.openEditor(PDEPlugin.getActivePage(), file, IPDEUIConstants.MANIFEST_EDITOR_ID);
- } catch (PartInitException e) {
- MessageDialog.openError(PDEPlugin.getActiveWorkbenchShell(), PDEUIMessages.OpenManifestsAction_title, NLS.bind(PDEUIMessages.OpenManifestsAction_cannotOpen, project.getName()));
- }
- }
+ }
+ if (projects.size() > 0) {
+ BusyIndicator.showWhile(PDEPlugin.getActiveWorkbenchShell().getDisplay(), new Runnable() {
+ public void run() {
+ Iterator it = projects.iterator();
+ while (it.hasNext()) {
+ IProject project = (IProject) it.next();
+ IFile file = PDEProject.getManifest(project);
+ if (file == null || !file.exists())
+ file = PDEProject.getPluginXml(project);
+ if (file == null || !file.exists())
+ file = PDEProject.getFragmentXml(project);
+ if (file == null || !file.exists())
+ MessageDialog.openError(PDEPlugin.getActiveWorkbenchShell(), PDEUIMessages.OpenManifestsAction_title, NLS.bind(PDEUIMessages.OpenManifestsAction_cannotFind, project.getName()));
+ else
+ try {
+ IDE.openEditor(PDEPlugin.getActivePage(), file, IPDEUIConstants.MANIFEST_EDITOR_ID);
+ } catch (PartInitException e) {
+ MessageDialog.openError(PDEPlugin.getActiveWorkbenchShell(), PDEUIMessages.OpenManifestsAction_title, NLS.bind(PDEUIMessages.OpenManifestsAction_cannotOpen, project.getName()));
+ }
}
- });
- } else
- MessageDialog.openInformation(PDEPlugin.getActiveWorkbenchShell(), PDEUIMessages.OpenManifestsAction_title, PDEUIMessages.OpenManifestAction_noManifest);
+ }
+ });
+ } else
+ MessageDialog.openInformation(PDEPlugin.getActiveWorkbenchShell(), PDEUIMessages.OpenManifestsAction_title, PDEUIMessages.OpenManifestAction_noManifest);
+ return null;
+ }
+
+ private IProject getProject(IEditorInput input) {
+ IAdapterManager adapterManager = Platform.getAdapterManager();
+ Object o;
+ if ((o = input.getAdapter(IResource.class)) != null || (o = adapterManager.getAdapter(input, IResource.class)) != null) {
+ return ((IFile) o).getProject();
+ }
+ if ((o = input.getAdapter(IProject.class)) != null || (o = adapterManager.getAdapter(input, IProject.class)) != null) {
+ return (IProject) o;
}
return null;
}