1 11 package org.eclipse.pde.internal.ui.search; 12 13 import org.eclipse.core.resources.IResource; 14 import org.eclipse.jface.action.IMenuManager; 15 import org.eclipse.jface.viewers.ISelection; 16 import org.eclipse.jface.viewers.IStructuredSelection; 17 import org.eclipse.pde.core.IBaseModel; 18 import org.eclipse.pde.core.plugin.IPlugin; 19 import org.eclipse.pde.core.plugin.IPluginBase; 20 import org.eclipse.pde.core.plugin.IPluginExtension; 21 import org.eclipse.pde.core.plugin.IPluginExtensionPoint; 22 import org.eclipse.pde.core.plugin.IPluginImport; 23 import org.eclipse.pde.core.plugin.IPluginModelBase; 24 import org.eclipse.pde.internal.core.PDEStateHelper; 25 import org.eclipse.pde.internal.core.plugin.ImportObject; 26 import org.eclipse.pde.internal.ui.editor.actions.OpenSchemaAction; 27 import org.eclipse.pde.internal.ui.search.dependencies.DependencyExtentAction; 28 import org.eclipse.ui.actions.ActionContext; 29 import org.eclipse.ui.actions.ActionGroup; 30 31 32 public class PluginSearchActionGroup extends ActionGroup { 33 34 private IBaseModel fModel; 35 36 public void setBaseModel(IBaseModel model) { 37 fModel = model; 38 } 39 40 43 public void fillContextMenu(IMenuManager menu) { 44 ActionContext context = getContext(); 45 ISelection selection = context.getSelection(); 46 if (selection instanceof IStructuredSelection) { 47 IStructuredSelection sSelection = (IStructuredSelection) selection; 48 if (sSelection.size() == 1) { 49 Object object = sSelection.getFirstElement(); 50 addShowDescriptionAction(object, menu); 51 addOpenSchemaAction(object, menu); 52 addFindDeclarationsAction(object, menu); 53 addFindReferencesAction(object, menu); 54 addDependencyExtentAction(object, menu); 55 } 56 } 57 } 58 59 63 private void addOpenSchemaAction(Object object, IMenuManager menu) { 64 if (object instanceof IPluginExtension) { 65 OpenSchemaAction action = new OpenSchemaAction(); 67 action.setInput((IPluginExtension)object); 68 action.setEnabled(true); 69 menu.add(action); 70 } else if (object instanceof IPluginExtensionPoint) { 71 OpenSchemaAction action = new OpenSchemaAction(); 74 IPluginExtensionPoint point = (IPluginExtensionPoint)object; 75 String pointID = point.getFullId(); 76 if (pointID.indexOf('.') == -1) { 78 action.setInput(fullyQualifyPointID(pointID)); 80 } else { 81 action.setInput(point); 82 } 83 action.setEnabled(true); 84 menu.add(action); 85 } 86 } 87 88 private void addFindDeclarationsAction(Object object, IMenuManager menu) { 89 if (object instanceof ImportObject) 90 object = ((ImportObject)object).getImport(); 91 92 if (object instanceof IPluginBase 93 || object instanceof IPluginExtension 94 || object instanceof IPluginImport) { 95 menu.add(new FindDeclarationsAction(object)); 96 } 97 } 98 99 private void addShowDescriptionAction(Object object, IMenuManager menu) { 100 if (object instanceof IPluginExtensionPoint) { 101 IPluginExtensionPoint extPoint = (IPluginExtensionPoint)object; 102 String pointID = extPoint.getFullId(); 103 if (pointID.indexOf('.') == -1) { 104 pointID = fullyQualifyPointID(pointID); 106 } 107 menu.add(new ShowDescriptionAction(extPoint, pointID)); 108 } else if (object instanceof IPluginExtension) { 109 String point = ((IPluginExtension)object).getPoint(); 110 IPluginExtensionPoint extPoint = PDEStateHelper.findExtensionPoint(point); 111 if (extPoint != null) 112 menu.add(new ShowDescriptionAction(extPoint)); 113 } 114 } 115 116 120 private String fullyQualifyPointID(String pointID) { 121 if (fModel instanceof IPluginModelBase) { 122 String basePointID = ((IPluginModelBase)fModel).getPluginBase().getId(); 123 pointID = basePointID + '.' + pointID; 124 } 125 return pointID; 126 } 127 128 private void addFindReferencesAction(Object object, IMenuManager menu) { 129 if (object instanceof IPluginModelBase) { 130 object = ((IPluginModelBase)object).getPluginBase(); 131 } else if (object instanceof ImportObject) { 132 object = ((ImportObject) object).getImport(); 133 } 134 if (object instanceof IPluginExtensionPoint 135 || object instanceof IPluginImport 136 || (object instanceof IPlugin)) 137 menu.add(new FindReferencesAction(object)); 138 } 139 140 private void addDependencyExtentAction(Object object, IMenuManager menu) { 141 if (object instanceof ImportObject) { 142 object = ((ImportObject)object).getImport(); 143 } 144 145 if (object instanceof IPluginImport) { 146 String id = ((IPluginImport)object).getId(); 147 IResource resource = ((IPluginImport)object).getModel().getUnderlyingResource(); 148 if (resource != null) { 149 menu.add(new DependencyExtentAction(resource.getProject(), id)); 150 } 151 } 152 } 153 154 } 155 | Popular Tags |