KickJava   Java API By Example, From Geeks To Geeks.

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


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.IJavaElement;
17 import org.eclipse.jdt.core.JavaModelException;
18 import org.eclipse.jdt.core.search.IJavaSearchScope;
19
20 import org.eclipse.jdt.ui.search.ElementQuerySpecification;
21 import org.eclipse.jdt.ui.search.QuerySpecification;
22
23 import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
24 import org.eclipse.jdt.internal.ui.JavaPluginImages;
25 import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor;
26 import org.eclipse.jdt.internal.ui.search.JavaSearchScopeFactory;
27 import org.eclipse.jdt.internal.ui.search.SearchMessages;
28
29 /**
30  * Finds field read accesses of the selected element in the enclosing project.
31  * The action is applicable to selections representing a Java field.
32  *
33  * <p>
34  * This class may be instantiated; it is not intended to be subclassed.
35  * </p>
36  *
37  * @since 3.0
38  */

39 public class FindReadReferencesInProjectAction extends FindReadReferencesAction {
40
41     /**
42      * Creates a new <code>FindReadReferencesInProjectAction</code>. The action
43      * requires that the selection provided by the site's selection provider is of type
44      * <code>IStructuredSelection</code>.
45      *
46      * @param site the site providing context information for this action
47      */

48     public FindReadReferencesInProjectAction(IWorkbenchSite site) {
49         super(site);
50     }
51
52     /**
53      * Note: This constructor is for internal use only. Clients should not call this constructor.
54      * @param editor the Java editor
55      */

56     public FindReadReferencesInProjectAction(JavaEditor editor) {
57         super(editor);
58     }
59
60     void init() {
61         setText(SearchMessages.Search_FindReadReferencesInProjectAction_label);
62         setToolTipText(SearchMessages.Search_FindReadReferencesInProjectAction_tooltip);
63         setImageDescriptor(JavaPluginImages.DESC_OBJS_SEARCH_REF);
64         PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.FIND_READ_REFERENCES_IN_PROJECT_ACTION);
65     }
66     
67     QuerySpecification createQuery(IJavaElement element) throws JavaModelException {
68         JavaSearchScopeFactory factory= JavaSearchScopeFactory.getInstance();
69         JavaEditor editor= getEditor();
70         
71         IJavaSearchScope scope;
72         String JavaDoc description;
73         boolean isInsideJRE= factory.isInsideJRE(element);
74         if (editor != null) {
75             scope= factory.createJavaProjectSearchScope(editor.getEditorInput(), isInsideJRE);
76             description= factory.getProjectScopeDescription(editor.getEditorInput(), isInsideJRE);
77         } else {
78             scope= factory.createJavaProjectSearchScope(element.getJavaProject(), isInsideJRE);
79             description= factory.getProjectScopeDescription(element.getJavaProject(), isInsideJRE);
80         }
81         return new ElementQuerySpecification(element, getLimitTo(), scope, description);
82     }
83
84 }
85
Popular Tags