KickJava   Java API By Example, From Geeks To Geeks.

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


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 declarations of the selected element in the enclosing project
31  * of the selected element.
32  * The action is applicable to selections representing a Java element.
33  *
34  * <p>
35  * This class may be instantiated; it is not intended to be subclassed.
36  * </p>
37  *
38  * @since 3.0
39  */

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

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

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