KickJava   Java API By Example, From Geeks To Geeks.

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


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

42 public class FindReferencesInWorkingSetAction extends FindReferencesAction {
43
44     private IWorkingSet[] fWorkingSets;
45     
46     /**
47      * Creates a new <code>FindReferencesInWorkingSetAction</code>. The action
48      * requires that the selection provided by the site's selection provider is of type
49      * <code>org.eclipse.jface.viewers.IStructuredSelection</code>. The user will
50      * be prompted to select the working sets.
51      *
52      * @param site the site providing context information for this action
53      */

54     public FindReferencesInWorkingSetAction(IWorkbenchSite site) {
55         this(site, null);
56     }
57
58     /**
59      * Creates a new <code>FindReferencesInWorkingSetAction</code>. The action
60      * requires that the selection provided by the site's selection provider is of type
61      * <code>org.eclipse.jface.viewers.IStructuredSelection</code>.
62      *
63      * @param site the site providing context information for this action
64      * @param workingSets the working sets to be used in the search
65      */

66     public FindReferencesInWorkingSetAction(IWorkbenchSite site, IWorkingSet[] workingSets) {
67         super(site);
68         fWorkingSets= workingSets;
69     }
70
71     /**
72      * Note: This constructor is for internal use only. Clients should not call this constructor.
73      * @param editor the Java editor
74      */

75     public FindReferencesInWorkingSetAction(JavaEditor editor) {
76         this(editor, null);
77     }
78
79     /**
80      * Note: This constructor is for internal use only. Clients should not call this constructor.
81      * @param editor the Java editor
82      * @param workingSets the working sets to be used in the search
83      */

84     public FindReferencesInWorkingSetAction(JavaEditor editor, IWorkingSet[] workingSets) {
85         super(editor);
86         fWorkingSets= workingSets;
87     }
88     
89     void init() {
90         setText(SearchMessages.Search_FindReferencesInWorkingSetAction_label);
91         setToolTipText(SearchMessages.Search_FindReferencesInWorkingSetAction_tooltip);
92         setImageDescriptor(JavaPluginImages.DESC_OBJS_SEARCH_REF);
93         PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.FIND_REFERENCES_IN_WORKING_SET_ACTION);
94     }
95
96     QuerySpecification createQuery(IJavaElement element) throws JavaModelException, InterruptedException JavaDoc {
97         JavaSearchScopeFactory factory= JavaSearchScopeFactory.getInstance();
98         
99         IWorkingSet[] workingSets= fWorkingSets;
100         if (fWorkingSets == null) {
101             workingSets= factory.queryWorkingSets();
102             if (workingSets == null)
103                 return super.createQuery(element); // in workspace
104
}
105         SearchUtil.updateLRUWorkingSets(workingSets);
106         IJavaSearchScope scope= factory.createJavaSearchScope(workingSets, true);
107         String JavaDoc description= factory.getWorkingSetScopeDescription(workingSets, true);
108         return new ElementQuerySpecification(element, getLimitTo(), scope, description);
109     }
110 }
111
Popular Tags