KickJava   Java API By Example, From Geeks To Geeks.

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


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  * Finds implementors of the selected element in working sets.
33  * The action is applicable to selections representing a Java interface.
34  *
35  * <p>
36  * This class may be instantiated; it is not intended to be subclassed.
37  * </p>
38  *
39  * @since 2.0
40  */

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

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

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

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

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