KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > search > PluginSearchActionGroup


1 /*******************************************************************************
2  * Copyright (c) 2005, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

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     /* (non-Javadoc)
41      * @see org.eclipse.ui.actions.ActionGroup#fillContextMenu(org.eclipse.jface.action.IMenuManager)
42      */

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 JavaDoc 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     /**
60      * @param object
61      * @param menu
62      */

63     private void addOpenSchemaAction(Object JavaDoc object, IMenuManager menu) {
64         if (object instanceof IPluginExtension) {
65             // From PDEOutlinePage
66
OpenSchemaAction action = new OpenSchemaAction();
67             action.setInput((IPluginExtension)object);
68             action.setEnabled(true);
69             menu.add(action);
70         } else if (object instanceof IPluginExtensionPoint) {
71             // From PluginSearchResultPage
72
// From ExtensionPointsSection
73
OpenSchemaAction action = new OpenSchemaAction();
74             IPluginExtensionPoint point = (IPluginExtensionPoint)object;
75             String JavaDoc pointID = point.getFullId();
76             // Ensure the extension point ID is fully qualified
77
if (pointID.indexOf('.') == -1) {
78                 // Point ID is not fully qualified
79
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 JavaDoc 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 JavaDoc object, IMenuManager menu) {
100         if (object instanceof IPluginExtensionPoint) {
101             IPluginExtensionPoint extPoint = (IPluginExtensionPoint)object;
102             String JavaDoc 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 JavaDoc point = ((IPluginExtension)object).getPoint();
110             IPluginExtensionPoint extPoint = PDEStateHelper.findExtensionPoint(point);
111             if (extPoint != null)
112                 menu.add(new ShowDescriptionAction(extPoint));
113         }
114     }
115
116     /**
117      * @param pointID
118      * @return
119      */

120     private String JavaDoc fullyQualifyPointID(String JavaDoc pointID) {
121         if (fModel instanceof IPluginModelBase) {
122             String JavaDoc basePointID = ((IPluginModelBase)fModel).getPluginBase().getId();
123             pointID = basePointID + '.' + pointID;
124         }
125         return pointID;
126     }
127
128     private void addFindReferencesAction(Object JavaDoc 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 JavaDoc object, IMenuManager menu) {
141         if (object instanceof ImportObject) {
142             object = ((ImportObject)object).getImport();
143         }
144         
145         if (object instanceof IPluginImport) {
146             String JavaDoc 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