1 11 package org.eclipse.pde.internal.ui.view; 12 13 import org.eclipse.core.resources.IFile; 14 import org.eclipse.core.resources.IProject; 15 import org.eclipse.jdt.core.IJavaProject; 16 import org.eclipse.jface.action.IAction; 17 import org.eclipse.jface.viewers.ISelection; 18 import org.eclipse.jface.viewers.IStructuredSelection; 19 import org.eclipse.pde.core.plugin.IPluginModelBase; 20 import org.eclipse.pde.core.plugin.IPluginObject; 21 import org.eclipse.pde.internal.core.PDECore; 22 import org.eclipse.pde.internal.ui.IPDEUIConstants; 23 import org.eclipse.pde.internal.ui.PDEPlugin; 24 import org.eclipse.ui.IViewPart; 25 import org.eclipse.ui.IWorkbenchPage; 26 import org.eclipse.ui.IWorkbenchWindow; 27 import org.eclipse.ui.IWorkbenchWindowActionDelegate; 28 import org.eclipse.ui.PartInitException; 29 30 public class OpenDependenciesAction implements IWorkbenchWindowActionDelegate { 31 private ISelection fSelection; 32 35 public void run(IAction action) { 36 if (fSelection instanceof IStructuredSelection) { 37 IStructuredSelection ssel = (IStructuredSelection) fSelection; 38 openDependencies(ssel.getFirstElement()); 39 } 40 } 41 42 private void openDependencies(Object el) { 43 if (el instanceof IFile) { 44 el = ((IFile)el).getProject(); 45 } 46 if (el instanceof IJavaProject) { 47 el = ((IJavaProject)el).getProject(); 48 } 49 if (el instanceof IProject) { 50 el = PDECore.getDefault().getModelManager().findModel((IProject) el); 51 } 52 if (el instanceof IPluginObject) { 53 el = ((IPluginObject)el).getModel(); 54 } 55 if (el instanceof IPluginModelBase) { 56 openDependencies((IPluginModelBase)el); 57 } 58 } 59 60 public static void openDependencies(IPluginModelBase model) { 61 IWorkbenchPage page = PDEPlugin.getActivePage(); 62 try { 63 IViewPart view = page.showView(IPDEUIConstants.DEPENDENCIES_VIEW_ID); 64 ((DependenciesView)view).openTo(model); 65 } 66 catch (PartInitException e) { 67 PDEPlugin.logException(e); 68 } 69 } 70 71 74 public void dispose() { 75 } 76 77 80 public void init(IWorkbenchWindow window) { 81 } 82 83 86 public void selectionChanged(IAction action, ISelection selection) { 87 fSelection = selection; 88 } 89 } 90 | Popular Tags |