|
Added
Link Here
|
| 1 |
package org.eclipse.pde.internal.ui.util; |
| 2 |
import java.util.ArrayList; |
| 3 |
import java.util.Iterator; |
| 4 |
import org.eclipse.core.resources.IFile; |
| 5 |
import org.eclipse.core.resources.IProject; |
| 6 |
import org.eclipse.jface.action.IAction; |
| 7 |
import org.eclipse.jface.dialogs.MessageDialog; |
| 8 |
import org.eclipse.jface.viewers.ISelection; |
| 9 |
import org.eclipse.jface.viewers.IStructuredSelection; |
| 10 |
import org.eclipse.osgi.util.NLS; |
| 11 |
import org.eclipse.pde.internal.core.WorkspaceModelManager; |
| 12 |
import org.eclipse.pde.internal.ui.PDEPlugin; |
| 13 |
import org.eclipse.pde.internal.ui.PDEUIMessages; |
| 14 |
import org.eclipse.swt.custom.BusyIndicator; |
| 15 |
import org.eclipse.ui.IWorkbenchWindow; |
| 16 |
import org.eclipse.ui.IWorkbenchWindowActionDelegate; |
| 17 |
import org.eclipse.ui.PartInitException; |
| 18 |
import org.eclipse.ui.ide.IDE; |
| 19 |
public class OpenManifestAction implements IWorkbenchWindowActionDelegate { |
| 20 |
private ISelection fSelection; |
| 21 |
public OpenManifestAction() { |
| 22 |
super(); |
| 23 |
} |
| 24 |
public void dispose() { |
| 25 |
} |
| 26 |
public void init(IWorkbenchWindow window) { |
| 27 |
} |
| 28 |
public void run(IAction action) { |
| 29 |
if (fSelection instanceof IStructuredSelection) { |
| 30 |
IStructuredSelection ssel = (IStructuredSelection) fSelection; |
| 31 |
Iterator it = ssel.iterator(); |
| 32 |
final ArrayList projects = new ArrayList(); |
| 33 |
while (it.hasNext()) { |
| 34 |
Object element = it.next(); |
| 35 |
IProject proj = null; |
| 36 |
if (element instanceof IFile) |
| 37 |
proj = ((IFile) element).getProject(); |
| 38 |
else if (element instanceof IProject) |
| 39 |
proj = (IProject) element; |
| 40 |
if (proj != null |
| 41 |
&& (WorkspaceModelManager.hasBundleManifest(proj) |
| 42 |
|| WorkspaceModelManager.hasPluginManifest(proj))) |
| 43 |
projects.add(proj); |
| 44 |
} |
| 45 |
if (projects.size() > 0) { |
| 46 |
BusyIndicator.showWhile(PDEPlugin.getActiveWorkbenchShell() |
| 47 |
.getDisplay(), new Runnable() { |
| 48 |
public void run() { |
| 49 |
Iterator it = projects.iterator(); |
| 50 |
while (it.hasNext()) { |
| 51 |
IProject project = (IProject) it.next(); |
| 52 |
// TODO is there a nicer way to get this? |
| 53 |
IFile file = project |
| 54 |
.getFile("META-INF/MANIFEST.MF"); //$NON-NLS-1$ |
| 55 |
if (file == null || !file.exists()) |
| 56 |
file = project.getFile("plugin.xml"); //$NON-NLS-1$ |
| 57 |
if (file == null || !file.exists()) |
| 58 |
MessageDialog.openError(PDEPlugin |
| 59 |
.getActiveWorkbenchShell(), |
| 60 |
PDEUIMessages.OpenManifestsAction_title, |
| 61 |
NLS.bind(PDEUIMessages.OpenManifestsAction_cannotFind, project.getName())); |
| 62 |
else |
| 63 |
try { |
| 64 |
IDE.openEditor(PDEPlugin.getActivePage(), |
| 65 |
file); |
| 66 |
} catch (PartInitException e) { |
| 67 |
MessageDialog.openError(PDEPlugin |
| 68 |
.getActiveWorkbenchShell(), |
| 69 |
PDEUIMessages.OpenManifestsAction_title, |
| 70 |
NLS.bind(PDEUIMessages.OpenManifestsAction_cannotOpen, project.getName())); |
| 71 |
} |
| 72 |
} |
| 73 |
} |
| 74 |
}); |
| 75 |
} else |
| 76 |
// TODO Update message |
| 77 |
MessageDialog.openInformation(PDEPlugin |
| 78 |
.getActiveWorkbenchShell(), |
| 79 |
PDEUIMessages.OpenManifestsAction_title, |
| 80 |
PDEUIMessages.OpenManifestsAction_cannotFind); |
| 81 |
} |
| 82 |
} |
| 83 |
public void selectionChanged(IAction action, ISelection selection) { |
| 84 |
fSelection = selection; |
| 85 |
} |
| 86 |
} |