1 11 package org.eclipse.pde.internal.ui.editor.feature; 12 13 import org.eclipse.core.resources.IFile; 14 import org.eclipse.core.resources.IProject; 15 import org.eclipse.core.resources.IResource; 16 import org.eclipse.jface.viewers.ISelectionProvider; 17 import org.eclipse.jface.viewers.IStructuredSelection; 18 import org.eclipse.pde.core.plugin.IPluginBase; 19 import org.eclipse.pde.core.plugin.IPluginModelBase; 20 import org.eclipse.pde.internal.core.feature.FeatureChild; 21 import org.eclipse.pde.internal.core.feature.FeaturePlugin; 22 import org.eclipse.pde.internal.core.ifeature.IFeature; 23 import org.eclipse.pde.internal.core.ifeature.IFeatureChild; 24 import org.eclipse.pde.internal.core.ifeature.IFeatureData; 25 import org.eclipse.pde.internal.ui.PDEPlugin; 26 import org.eclipse.pde.internal.ui.PDEUIMessages; 27 import org.eclipse.pde.internal.ui.editor.plugin.ManifestEditor; 28 import org.eclipse.ui.IWorkbenchPage; 29 import org.eclipse.ui.PartInitException; 30 import org.eclipse.ui.actions.SelectionProviderAction; 31 import org.eclipse.ui.ide.IDE; 32 33 public class OpenReferenceAction extends SelectionProviderAction { 34 public OpenReferenceAction(ISelectionProvider provider) { 35 super(provider, PDEUIMessages.Actions_open_label); 36 } 37 38 public void run() { 39 IStructuredSelection sel = (IStructuredSelection) getSelection(); 40 Object obj = sel.getFirstElement(); 41 42 if (obj instanceof FeaturePlugin) { 43 IPluginBase base = ((FeaturePlugin)obj).getPluginBase(); 44 if (base != null) 45 ManifestEditor.openPluginEditor((IPluginModelBase)base.getModel()); 46 } else if (obj instanceof IFeatureData) { 47 IFeatureData data = (IFeatureData) obj; 48 String id = data.getId(); 49 IResource resource = data.getModel().getUnderlyingResource(); 50 if (resource != null) { 51 IProject project = resource.getProject(); 52 IFile file = project.getFile(id); 53 if (file != null && file.exists()) { 54 IWorkbenchPage page = PDEPlugin.getActivePage(); 55 try { 56 IDE.openEditor(page, file, true); 57 } catch (PartInitException e) { 58 } 59 } 60 } 61 } else if (obj instanceof IFeatureChild) { 62 IFeatureChild included = (IFeatureChild) obj; 63 IFeature feature = ((FeatureChild) included).getReferencedFeature(); 64 FeatureEditor.openFeatureEditor(feature); 65 } 66 } 67 68 public void selectionChanged(IStructuredSelection selection) { 69 setEnabled(!selection.isEmpty()); 70 } 71 } 72 | Popular Tags |