KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > ui > actions > FindReferencesAction


1 /*******************************************************************************
2  * Copyright (c) 2000, 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.jdt.ui.actions;
12
13 import org.eclipse.ui.IWorkbenchSite;
14 import org.eclipse.ui.PlatformUI;
15
16 import org.eclipse.jdt.core.ICompilationUnit;
17 import org.eclipse.jdt.core.IField;
18 import org.eclipse.jdt.core.IImportDeclaration;
19 import org.eclipse.jdt.core.IJavaElement;
20 import org.eclipse.jdt.core.ILocalVariable;
21 import org.eclipse.jdt.core.IMethod;
22 import org.eclipse.jdt.core.IPackageDeclaration;
23 import org.eclipse.jdt.core.IPackageFragment;
24 import org.eclipse.jdt.core.IType;
25 import org.eclipse.jdt.core.ITypeParameter;
26 import org.eclipse.jdt.core.JavaModelException;
27 import org.eclipse.jdt.core.search.IJavaSearchConstants;
28 import org.eclipse.jdt.core.search.IJavaSearchScope;
29
30 import org.eclipse.jdt.ui.search.ElementQuerySpecification;
31 import org.eclipse.jdt.ui.search.QuerySpecification;
32
33 import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
34 import org.eclipse.jdt.internal.ui.JavaPluginImages;
35 import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor;
36 import org.eclipse.jdt.internal.ui.search.JavaSearchScopeFactory;
37 import org.eclipse.jdt.internal.ui.search.SearchMessages;
38 import org.eclipse.jdt.internal.ui.search.SearchUtil;
39
40 /**
41  * Finds references of the selected element in the workspace.
42  * The action is applicable to selections representing a Java element.
43  *
44  * <p>
45  * This class may be instantiated; it is not intended to be subclassed.
46  * </p>
47  *
48  * @since 2.0
49  */

50 public class FindReferencesAction extends FindAction {
51
52     /**
53      * Creates a new <code>FindReferencesAction</code>. The action
54      * requires that the selection provided by the site's selection provider is of type
55      * <code>org.eclipse.jface.viewers.IStructuredSelection</code>.
56      *
57      * @param site the site providing context information for this action
58      */

59     public FindReferencesAction(IWorkbenchSite site) {
60         super(site);
61     }
62
63     /**
64      * Note: This constructor is for internal use only. Clients should not call this constructor.
65      * @param editor the Java editor
66      */

67     public FindReferencesAction(JavaEditor editor) {
68         super(editor);
69     }
70     
71     Class JavaDoc[] getValidTypes() {
72         return new Class JavaDoc[] { ICompilationUnit.class, IType.class, IMethod.class, IField.class, IPackageDeclaration.class, IImportDeclaration.class, IPackageFragment.class, ILocalVariable.class, ITypeParameter.class };
73     }
74     
75     void init() {
76         setText(SearchMessages.Search_FindReferencesAction_label);
77         setToolTipText(SearchMessages.Search_FindReferencesAction_tooltip);
78         setImageDescriptor(JavaPluginImages.DESC_OBJS_SEARCH_REF);
79         PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.FIND_REFERENCES_IN_WORKSPACE_ACTION);
80     }
81
82     int getLimitTo() {
83         return IJavaSearchConstants.REFERENCES;
84     }
85     
86     QuerySpecification createQuery(IJavaElement element) throws JavaModelException, InterruptedException JavaDoc {
87         JavaSearchScopeFactory factory= JavaSearchScopeFactory.getInstance();
88         boolean isInsideJRE= factory.isInsideJRE(element);
89         
90         IJavaSearchScope scope= factory.createWorkspaceScope(isInsideJRE);
91         String JavaDoc description= factory.getWorkspaceScopeDescription(isInsideJRE);
92         return new ElementQuerySpecification(element, getLimitTo(), scope, description);
93     }
94
95     public void run(IJavaElement element) {
96         SearchUtil.warnIfBinaryConstant(element, getShell());
97         super.run(element);
98     }
99 }
100
Popular Tags