KickJava   Java API By Example, From Geeks To Geeks.

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


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.IJavaElement;
19 import org.eclipse.jdt.core.ILocalVariable;
20 import org.eclipse.jdt.core.IMethod;
21 import org.eclipse.jdt.core.IType;
22 import org.eclipse.jdt.core.ITypeParameter;
23 import org.eclipse.jdt.core.JavaModelException;
24 import org.eclipse.jdt.core.search.IJavaSearchScope;
25 import org.eclipse.jdt.core.search.SearchEngine;
26
27 import org.eclipse.jdt.ui.search.ElementQuerySpecification;
28 import org.eclipse.jdt.ui.search.QuerySpecification;
29
30 import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
31 import org.eclipse.jdt.internal.ui.JavaPluginImages;
32 import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor;
33 import org.eclipse.jdt.internal.ui.search.JavaSearchScopeFactory;
34 import org.eclipse.jdt.internal.ui.search.SearchMessages;
35
36 /**
37  * Finds references of the selected element in its hierarchy.
38  * The action is applicable to selections representing a Java element.
39  *
40  * <p>
41  * This class may be instantiated; it is not intended to be subclassed.
42  * </p>
43  *
44  * @since 2.0
45  */

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

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

63     public FindReferencesInHierarchyAction(JavaEditor editor) {
64         super(editor);
65     }
66     
67     Class JavaDoc[] getValidTypes() {
68         return new Class JavaDoc[] { ICompilationUnit.class, IType.class, IMethod.class, IField.class, ILocalVariable.class, ITypeParameter.class };
69     }
70     
71     void init() {
72         setText(SearchMessages.Search_FindHierarchyReferencesAction_label);
73         setToolTipText(SearchMessages.Search_FindHierarchyReferencesAction_tooltip);
74         setImageDescriptor(JavaPluginImages.DESC_OBJS_SEARCH_REF);
75         PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.FIND_REFERENCES_IN_HIERARCHY_ACTION);
76     }
77
78     QuerySpecification createQuery(IJavaElement element) throws JavaModelException, InterruptedException JavaDoc {
79         IType type= getType(element);
80         if (type == null) {
81             return super.createQuery(element);
82         }
83         JavaSearchScopeFactory factory= JavaSearchScopeFactory.getInstance();
84         IJavaSearchScope scope= SearchEngine.createHierarchyScope(type);
85         String JavaDoc description= factory.getHierarchyScopeDescription(type);
86         return new ElementQuerySpecification(element, getLimitTo(), scope, description);
87     }
88
89 }
90
Popular Tags