001: /*******************************************************************************
002: * Copyright (c) 2005, 2007 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.pde.internal.ui.search;
011:
012: import org.eclipse.core.resources.IResource;
013: import org.eclipse.jface.action.IMenuManager;
014: import org.eclipse.jface.viewers.ISelection;
015: import org.eclipse.jface.viewers.IStructuredSelection;
016: import org.eclipse.pde.core.IBaseModel;
017: import org.eclipse.pde.core.plugin.IPlugin;
018: import org.eclipse.pde.core.plugin.IPluginBase;
019: import org.eclipse.pde.core.plugin.IPluginExtension;
020: import org.eclipse.pde.core.plugin.IPluginExtensionPoint;
021: import org.eclipse.pde.core.plugin.IPluginImport;
022: import org.eclipse.pde.core.plugin.IPluginModelBase;
023: import org.eclipse.pde.internal.core.PDECore;
024: import org.eclipse.pde.internal.core.plugin.ImportObject;
025: import org.eclipse.pde.internal.ui.editor.actions.OpenSchemaAction;
026: import org.eclipse.pde.internal.ui.search.dependencies.DependencyExtentAction;
027: import org.eclipse.ui.actions.ActionContext;
028: import org.eclipse.ui.actions.ActionGroup;
029:
030: public class PluginSearchActionGroup extends ActionGroup {
031:
032: private IBaseModel fModel;
033:
034: public void setBaseModel(IBaseModel model) {
035: fModel = model;
036: }
037:
038: /* (non-Javadoc)
039: * @see org.eclipse.ui.actions.ActionGroup#fillContextMenu(org.eclipse.jface.action.IMenuManager)
040: */
041: public void fillContextMenu(IMenuManager menu) {
042: ActionContext context = getContext();
043: ISelection selection = context.getSelection();
044: if (selection instanceof IStructuredSelection) {
045: IStructuredSelection sSelection = (IStructuredSelection) selection;
046: if (sSelection.size() == 1) {
047: Object object = sSelection.getFirstElement();
048: addShowDescriptionAction(object, menu);
049: addOpenSchemaAction(object, menu);
050: addFindDeclarationsAction(object, menu);
051: addFindReferencesAction(object, menu);
052: addDependencyExtentAction(object, menu);
053: }
054: }
055: }
056:
057: /**
058: * @param object
059: * @param menu
060: */
061: private void addOpenSchemaAction(Object object, IMenuManager menu) {
062: if (object instanceof IPluginExtension) {
063: // From PDEOutlinePage
064: OpenSchemaAction action = new OpenSchemaAction();
065: action.setInput((IPluginExtension) object);
066: action.setEnabled(true);
067: menu.add(action);
068: } else if (object instanceof IPluginExtensionPoint) {
069: // From PluginSearchResultPage
070: // From ExtensionPointsSection
071: OpenSchemaAction action = new OpenSchemaAction();
072: IPluginExtensionPoint point = (IPluginExtensionPoint) object;
073: String pointID = point.getFullId();
074: // Ensure the extension point ID is fully qualified
075: if (pointID.indexOf('.') == -1) {
076: // Point ID is not fully qualified
077: action.setInput(fullyQualifyPointID(pointID));
078: } else {
079: action.setInput(point);
080: }
081: action.setEnabled(true);
082: menu.add(action);
083: }
084: }
085:
086: private void addFindDeclarationsAction(Object object,
087: IMenuManager menu) {
088: if (object instanceof ImportObject)
089: object = ((ImportObject) object).getImport();
090:
091: if (object instanceof IPluginBase
092: || object instanceof IPluginExtension
093: || object instanceof IPluginImport) {
094: menu.add(new FindDeclarationsAction(object));
095: }
096: }
097:
098: private void addShowDescriptionAction(Object object,
099: IMenuManager menu) {
100: if (object instanceof IPluginExtensionPoint) {
101: IPluginExtensionPoint extPoint = (IPluginExtensionPoint) object;
102: String pointID = extPoint.getFullId();
103: if (pointID.indexOf('.') == -1) {
104: // Point ID is not fully qualified
105: 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 = PDECore.getDefault()
111: .getExtensionsRegistry().findExtensionPoint(point);
112: if (extPoint != null)
113: menu.add(new ShowDescriptionAction(extPoint));
114: }
115: }
116:
117: /**
118: * @param pointID
119: * @return
120: */
121: private String fullyQualifyPointID(String pointID) {
122: if (fModel instanceof IPluginModelBase) {
123: String basePointID = ((IPluginModelBase) fModel)
124: .getPluginBase().getId();
125: pointID = basePointID + '.' + pointID;
126: }
127: return pointID;
128: }
129:
130: private void addFindReferencesAction(Object object,
131: IMenuManager menu) {
132: if (object instanceof IPluginModelBase) {
133: object = ((IPluginModelBase) object).getPluginBase();
134: } else if (object instanceof ImportObject) {
135: object = ((ImportObject) object).getImport();
136: }
137: if (object instanceof IPluginExtensionPoint
138: || object instanceof IPluginImport
139: || (object instanceof IPlugin))
140: menu.add(new FindReferencesAction(object));
141: }
142:
143: private void addDependencyExtentAction(Object object,
144: IMenuManager menu) {
145: if (object instanceof ImportObject) {
146: object = ((ImportObject) object).getImport();
147: }
148:
149: if (object instanceof IPluginImport) {
150: String id = ((IPluginImport) object).getId();
151: IResource resource = ((IPluginImport) object).getModel()
152: .getUnderlyingResource();
153: if (resource != null) {
154: menu.add(new DependencyExtentAction(resource
155: .getProject(), id));
156: }
157: }
158: }
159:
160: }
|