KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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.pde.core.plugin.IPlugin;
14 import org.eclipse.pde.core.plugin.IPluginExtensionPoint;
15 import org.eclipse.pde.core.plugin.IPluginImport;
16 import org.eclipse.pde.core.plugin.IPluginModelBase;
17 import org.eclipse.pde.internal.core.search.PluginSearchInput;
18 import org.eclipse.pde.internal.core.search.PluginSearchScope;
19 import org.eclipse.pde.internal.ui.PDEPluginImages;
20 import org.eclipse.pde.internal.ui.PDEUIMessages;
21 import org.eclipse.search.ui.ISearchQuery;
22
23
24 public class FindReferencesAction extends BaseSearchAction {
25     
26     private Object JavaDoc fSelectedObject;
27     private String JavaDoc fPluginID;
28     
29     public FindReferencesAction(Object JavaDoc object) {
30         this(object, null);
31     }
32     
33     public FindReferencesAction(Object JavaDoc object, String JavaDoc pluginID) {
34         super(PDEUIMessages.SearchAction_references);
35         fSelectedObject = object;
36         fPluginID = pluginID;
37         initialize();
38     }
39     
40     private void initialize() {
41         setImageDescriptor(PDEPluginImages.DESC_PSEARCH_OBJ);
42     }
43
44     protected ISearchQuery createSearchQuery() {
45         PluginSearchInput input = new PluginSearchInput();
46         if (fSelectedObject instanceof IPlugin) {
47             input.setSearchElement(PluginSearchInput.ELEMENT_PLUGIN);
48             input.setSearchString(((IPlugin) fSelectedObject).getId());
49         } else if (fSelectedObject instanceof IPluginExtensionPoint) {
50             input.setSearchElement(PluginSearchInput.ELEMENT_EXTENSION_POINT);
51             IPluginModelBase model = ((IPluginExtensionPoint) fSelectedObject).getPluginModel();
52             String JavaDoc id = model.getPluginBase().getId();
53             if (id == null || id.trim().length() == 0)
54                 id = fPluginID;
55             if (id == null || id.trim().length() == 0)
56                 id = "*"; //$NON-NLS-1$
57
input.setSearchString(
58                         id
59                         + "." //$NON-NLS-1$
60
+ ((IPluginExtensionPoint) fSelectedObject).getId());
61         } else if (fSelectedObject instanceof IPluginImport) {
62             input.setSearchElement(PluginSearchInput.ELEMENT_PLUGIN);
63             input.setSearchString(((IPluginImport) fSelectedObject).getId());
64         }
65         input.setSearchLimit(PluginSearchInput.LIMIT_REFERENCES);
66         input.setSearchScope(new PluginSearchScope());
67         return new PluginSearchQuery(input);
68     }
69
70 }
71
Popular Tags