KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

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

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