]>
Commit | Line | Data |
---|---|---|
1b2798f6 EK |
1 | /******************************************************************************* |
2 | * Copyright (c) 2000, 2011 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 | * @noextend This class is not intended to be subclassed by clients. | |
42 | */ | |
43 | public class FindImplementorsInWorkingSetAction extends FindImplementorsAction { | |
44 | ||
45 | private IWorkingSet[] fWorkingSets; | |
46 | ||
47 | /** | |
48 | * Creates a new <code>FindImplementorsInWorkingSetAction</code>. The action | |
49 | * requires that the selection provided by the site's selection provider is of type | |
50 | * <code>org.eclipse.jface.viewers.IStructuredSelection</code>. The user will be | |
51 | * prompted to select the working sets. | |
52 | * | |
53 | * @param site the site providing context information for this action | |
54 | */ | |
55 | public FindImplementorsInWorkingSetAction(IWorkbenchSite site) { | |
56 | super(site); | |
57 | } | |
58 | ||
59 | /** | |
60 | * Creates a new <code>FindImplementorsInWorkingSetAction</code>. The action | |
61 | * requires that the selection provided by the site's selection provider is of type | |
62 | * <code>org.eclipse.jface.viewers.IStructuredSelection</code>. | |
63 | * | |
64 | * @param site the site providing context information for this action | |
65 | * @param workingSets the working sets to be used in the search | |
66 | */ | |
67 | public FindImplementorsInWorkingSetAction(IWorkbenchSite site, IWorkingSet[] workingSets) { | |
68 | this(site); | |
69 | fWorkingSets= workingSets; | |
70 | } | |
71 | ||
72 | /** | |
73 | * Note: This constructor is for internal use only. Clients should not call this constructor. | |
74 | * @param editor the Java editor | |
75 | * | |
76 | * @noreference This constructor is not intended to be referenced by clients. | |
77 | */ | |
78 | public FindImplementorsInWorkingSetAction(JavaEditor editor) { | |
79 | super(editor); | |
80 | } | |
81 | ||
82 | /** | |
83 | * Note: This constructor is for internal use only. Clients should not call this constructor. | |
84 | * @param editor the Java editor | |
85 | * @param workingSets the working sets to be used in the search | |
86 | * | |
87 | * @noreference This constructor is not intended to be referenced by clients. | |
88 | */ | |
89 | public FindImplementorsInWorkingSetAction(JavaEditor editor, IWorkingSet[] workingSets) { | |
90 | this(editor); | |
91 | fWorkingSets= workingSets; | |
92 | } | |
93 | ||
94 | @Override | |
95 | void init() { | |
96 | setText(SearchMessages.Search_FindImplementorsInWorkingSetAction_label); | |
97 | setToolTipText(SearchMessages.Search_FindImplementorsInWorkingSetAction_tooltip); | |
98 | setImageDescriptor(JavaPluginImages.DESC_OBJS_SEARCH_DECL); | |
99 | PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.FIND_IMPLEMENTORS_IN_WORKING_SET_ACTION); | |
100 | } | |
101 | ||
102 | @Override | |
103 | QuerySpecification createQuery(IJavaElement element) throws JavaModelException, InterruptedException { | |
104 | JavaSearchScopeFactory factory= JavaSearchScopeFactory.getInstance(); | |
105 | ||
106 | IWorkingSet[] workingSets= fWorkingSets; | |
107 | if (fWorkingSets == null) { | |
108 | workingSets= factory.queryWorkingSets(); | |
109 | if (workingSets == null) | |
110 | return super.createQuery(element); // workspace | |
111 | } | |
112 | SearchUtil.updateLRUWorkingSets(workingSets); | |
113 | IJavaSearchScope scope= factory.createJavaSearchScope(workingSets, JavaSearchScopeFactory.NO_PROJ); | |
114 | String description= factory.getWorkingSetScopeDescription(workingSets, JavaSearchScopeFactory.NO_PROJ); | |
115 | return new ElementQuerySpecification(element, getLimitTo(), scope, description); | |
116 | } | |
117 | ||
118 | } | |
119 |