Lines 1-5
Link Here
|
1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2006, 2011 IBM Corporation and others. |
2 |
* Copyright (c) 2006, 2011, 2012 IBM Corporation and others. |
3 |
* All rights reserved. This program and the accompanying materials |
3 |
* All rights reserved. This program and the accompanying materials |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
5 |
* which accompanies this distribution, and is available at |
5 |
* which accompanies this distribution, and is available at |
Lines 10-15
Link Here
|
10 |
* Alex Blewitt (alex_blewitt@yahoo.com) - contributed a patch for: |
10 |
* Alex Blewitt (alex_blewitt@yahoo.com) - contributed a patch for: |
11 |
* o Add an 'Open Manifest' to projects to open the manifest editor |
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) |
12 |
* (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=133692) |
|
|
13 |
* Brian de Alwis - open manifest for the currently active editor |
13 |
*******************************************************************************/ |
14 |
*******************************************************************************/ |
14 |
package org.eclipse.pde.internal.ui.editor; |
15 |
package org.eclipse.pde.internal.ui.editor; |
15 |
|
16 |
|
Lines 17-23
import java.util.HashSet;
Link Here
|
17 |
import java.util.Iterator; |
18 |
import java.util.Iterator; |
18 |
import org.eclipse.core.commands.*; |
19 |
import org.eclipse.core.commands.*; |
19 |
import org.eclipse.core.resources.*; |
20 |
import org.eclipse.core.resources.*; |
20 |
import org.eclipse.core.runtime.IAdaptable; |
21 |
import org.eclipse.core.runtime.*; |
21 |
import org.eclipse.jface.dialogs.MessageDialog; |
22 |
import org.eclipse.jface.dialogs.MessageDialog; |
22 |
import org.eclipse.jface.viewers.ISelection; |
23 |
import org.eclipse.jface.viewers.ISelection; |
23 |
import org.eclipse.jface.viewers.IStructuredSelection; |
24 |
import org.eclipse.jface.viewers.IStructuredSelection; |
Lines 26-32
import org.eclipse.pde.internal.core.WorkspaceModelManager;
Link Here
|
26 |
import org.eclipse.pde.internal.core.project.PDEProject; |
27 |
import org.eclipse.pde.internal.core.project.PDEProject; |
27 |
import org.eclipse.pde.internal.ui.*; |
28 |
import org.eclipse.pde.internal.ui.*; |
28 |
import org.eclipse.swt.custom.BusyIndicator; |
29 |
import org.eclipse.swt.custom.BusyIndicator; |
29 |
import org.eclipse.ui.PartInitException; |
30 |
import org.eclipse.ui.*; |
30 |
import org.eclipse.ui.handlers.HandlerUtil; |
31 |
import org.eclipse.ui.handlers.HandlerUtil; |
31 |
import org.eclipse.ui.ide.IDE; |
32 |
import org.eclipse.ui.ide.IDE; |
32 |
import org.eclipse.ui.model.IWorkbenchAdapter; |
33 |
import org.eclipse.ui.model.IWorkbenchAdapter; |
Lines 41-51
public class OpenManifestHandler extends AbstractHandler {
Link Here
|
41 |
* @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent) |
42 |
* @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent) |
42 |
*/ |
43 |
*/ |
43 |
public Object execute(ExecutionEvent event) throws ExecutionException { |
44 |
public Object execute(ExecutionEvent event) throws ExecutionException { |
|
|
45 |
final HashSet projects = new HashSet(); |
46 |
if (HandlerUtil.getActivePart(event) instanceof IEditorPart) { |
47 |
IEditorInput input = ((IEditorPart) HandlerUtil.getActivePart(event)).getEditorInput(); |
48 |
IProject proj = getProject(input); |
49 |
if (proj != null && WorkspaceModelManager.isPluginProject(proj)) { |
50 |
projects.add(proj); |
51 |
} |
52 |
} |
44 |
ISelection selection = HandlerUtil.getCurrentSelection(event); |
53 |
ISelection selection = HandlerUtil.getCurrentSelection(event); |
45 |
if (selection instanceof IStructuredSelection) { |
54 |
if (selection instanceof IStructuredSelection) { |
46 |
IStructuredSelection ssel = (IStructuredSelection) selection; |
55 |
IStructuredSelection ssel = (IStructuredSelection) selection; |
47 |
Iterator it = ssel.iterator(); |
56 |
Iterator it = ssel.iterator(); |
48 |
final HashSet projects = new HashSet(); |
|
|
49 |
while (it.hasNext()) { |
57 |
while (it.hasNext()) { |
50 |
Object element = it.next(); |
58 |
Object element = it.next(); |
51 |
IProject proj = null; |
59 |
IProject proj = null; |
Lines 75-104
public class OpenManifestHandler extends AbstractHandler {
Link Here
|
75 |
if (proj != null && WorkspaceModelManager.isPluginProject(proj)) |
83 |
if (proj != null && WorkspaceModelManager.isPluginProject(proj)) |
76 |
projects.add(proj); |
84 |
projects.add(proj); |
77 |
} |
85 |
} |
78 |
if (projects.size() > 0) { |
86 |
} |
79 |
BusyIndicator.showWhile(PDEPlugin.getActiveWorkbenchShell().getDisplay(), new Runnable() { |
87 |
if (projects.size() > 0) { |
80 |
public void run() { |
88 |
BusyIndicator.showWhile(PDEPlugin.getActiveWorkbenchShell().getDisplay(), new Runnable() { |
81 |
Iterator it = projects.iterator(); |
89 |
public void run() { |
82 |
while (it.hasNext()) { |
90 |
Iterator it = projects.iterator(); |
83 |
IProject project = (IProject) it.next(); |
91 |
while (it.hasNext()) { |
84 |
IFile file = PDEProject.getManifest(project); |
92 |
IProject project = (IProject) it.next(); |
85 |
if (file == null || !file.exists()) |
93 |
IFile file = PDEProject.getManifest(project); |
86 |
file = PDEProject.getPluginXml(project); |
94 |
if (file == null || !file.exists()) |
87 |
if (file == null || !file.exists()) |
95 |
file = PDEProject.getPluginXml(project); |
88 |
file = PDEProject.getFragmentXml(project); |
96 |
if (file == null || !file.exists()) |
89 |
if (file == null || !file.exists()) |
97 |
file = PDEProject.getFragmentXml(project); |
90 |
MessageDialog.openError(PDEPlugin.getActiveWorkbenchShell(), PDEUIMessages.OpenManifestsAction_title, NLS.bind(PDEUIMessages.OpenManifestsAction_cannotFind, project.getName())); |
98 |
if (file == null || !file.exists()) |
91 |
else |
99 |
MessageDialog.openError(PDEPlugin.getActiveWorkbenchShell(), PDEUIMessages.OpenManifestsAction_title, NLS.bind(PDEUIMessages.OpenManifestsAction_cannotFind, project.getName())); |
92 |
try { |
100 |
else |
93 |
IDE.openEditor(PDEPlugin.getActivePage(), file, IPDEUIConstants.MANIFEST_EDITOR_ID); |
101 |
try { |
94 |
} catch (PartInitException e) { |
102 |
IDE.openEditor(PDEPlugin.getActivePage(), file, IPDEUIConstants.MANIFEST_EDITOR_ID); |
95 |
MessageDialog.openError(PDEPlugin.getActiveWorkbenchShell(), PDEUIMessages.OpenManifestsAction_title, NLS.bind(PDEUIMessages.OpenManifestsAction_cannotOpen, project.getName())); |
103 |
} catch (PartInitException e) { |
96 |
} |
104 |
MessageDialog.openError(PDEPlugin.getActiveWorkbenchShell(), PDEUIMessages.OpenManifestsAction_title, NLS.bind(PDEUIMessages.OpenManifestsAction_cannotOpen, project.getName())); |
97 |
} |
105 |
} |
98 |
} |
106 |
} |
99 |
}); |
107 |
} |
100 |
} else |
108 |
}); |
101 |
MessageDialog.openInformation(PDEPlugin.getActiveWorkbenchShell(), PDEUIMessages.OpenManifestsAction_title, PDEUIMessages.OpenManifestAction_noManifest); |
109 |
} else |
|
|
110 |
MessageDialog.openInformation(PDEPlugin.getActiveWorkbenchShell(), PDEUIMessages.OpenManifestsAction_title, PDEUIMessages.OpenManifestAction_noManifest); |
111 |
return null; |
112 |
} |
113 |
|
114 |
private IProject getProject(IEditorInput input) { |
115 |
IAdapterManager adapterManager = Platform.getAdapterManager(); |
116 |
Object o; |
117 |
if ((o = input.getAdapter(IResource.class)) != null || (o = adapterManager.getAdapter(input, IResource.class)) != null) { |
118 |
return ((IFile) o).getProject(); |
119 |
} |
120 |
if ((o = input.getAdapter(IProject.class)) != null || (o = adapterManager.getAdapter(input, IProject.class)) != null) { |
121 |
return (IProject) o; |
102 |
} |
122 |
} |
103 |
return null; |
123 |
return null; |
104 |
} |
124 |
} |