KickJava   Java API By Example, From Geeks To Geeks.

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


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.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.IJavaSearchScope;
28
29 import org.eclipse.jdt.ui.search.ElementQuerySpecification;
30 import org.eclipse.jdt.ui.search.QuerySpecification;
31
32 import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
33 import org.eclipse.jdt.internal.ui.JavaPluginImages;
34 import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor;
35 import org.eclipse.jdt.internal.ui.search.JavaSearchScopeFactory;
36 import org.eclipse.jdt.internal.ui.search.SearchMessages;
37
38 /**
39  * Finds references to the selected element in the enclosing project
40  * of the selected element.
41  * The action is applicable to selections representing a Java element.
42  *
43  * <p>
44  * This class may be instantiated; it is not intended to be subclassed.
45  * </p>
46  *
47  * @since 3.0
48  */

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

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

66     public FindReferencesInProjectAction(JavaEditor editor) {
67         super(editor);
68     }
69     
70     Class JavaDoc[] getValidTypes() {
71         return new Class JavaDoc[] { IField.class, IMethod.class, IType.class, ICompilationUnit.class, IPackageDeclaration.class, IImportDeclaration.class, IPackageFragment.class, ILocalVariable.class, ITypeParameter.class };
72     }
73     
74     void init() {
75         setText(SearchMessages.Search_FindReferencesInProjectAction_label);
76         setToolTipText(SearchMessages.Search_FindReferencesInProjectAction_tooltip);
77         setImageDescriptor(JavaPluginImages.DESC_OBJS_SEARCH_REF);
78         PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.FIND_REFERENCES_IN_PROJECT_ACTION);
79     }
80
81     QuerySpecification createQuery(IJavaElement element) throws JavaModelException {
82         JavaSearchScopeFactory factory= JavaSearchScopeFactory.getInstance();
83         JavaEditor editor= getEditor();
84         
85         IJavaSearchScope scope;
86         String JavaDoc description;
87         boolean isInsideJRE= factory.isInsideJRE(element);
88         if (editor != null) {
89             scope= factory.createJavaProjectSearchScope(editor.getEditorInput(), isInsideJRE);
90             description= factory.getProjectScopeDescription(editor.getEditorInput(), isInsideJRE);
91         } else {
92             scope= factory.createJavaProjectSearchScope(element.getJavaProject(), isInsideJRE);
93             description= factory.getProjectScopeDescription(element.getJavaProject(), isInsideJRE);
94         }
95         return new ElementQuerySpecification(element, getLimitTo(), scope, description);
96     }
97     
98 }
99
Popular Tags