]>
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.jface.viewers.ISelection; | |
14 | import org.eclipse.jface.viewers.ISelectionProvider; | |
15 | ||
16 | import org.eclipse.ui.IWorkbenchSite; | |
17 | import org.eclipse.ui.PlatformUI; | |
18 | ||
19 | import org.eclipse.jdt.core.ICompilationUnit; | |
20 | import org.eclipse.jdt.core.IJavaElement; | |
21 | import org.eclipse.jdt.core.IType; | |
22 | import org.eclipse.jdt.core.JavaModelException; | |
23 | import org.eclipse.jdt.core.search.IJavaSearchConstants; | |
24 | ||
25 | import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; | |
26 | import org.eclipse.jdt.internal.ui.JavaPluginImages; | |
27 | import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor; | |
28 | import org.eclipse.jdt.internal.ui.search.SearchMessages; | |
29 | ||
30 | /** | |
31 | * Finds implementors of the selected element in the workspace. | |
32 | * The action is applicable to selections representing a Java interface. | |
33 | * | |
34 | * <p> | |
35 | * This class may be instantiated; it is not intended to be subclassed. | |
36 | * </p> | |
37 | * | |
38 | * @since 2.0 | |
39 | * | |
40 | * @noextend This class is not intended to be subclassed by clients. | |
41 | */ | |
42 | public class FindImplementorsAction extends FindAction { | |
43 | ||
44 | /** | |
45 | * Creates a new <code>FindImplementorsAction</code>. The action | |
46 | * requires that the selection provided by the site's selection provider is of type | |
47 | * <code>org.eclipse.jface.viewers.IStructuredSelection</code>. | |
48 | * | |
49 | * @param site the site providing context information for this action | |
50 | */ | |
51 | public FindImplementorsAction(IWorkbenchSite site) { | |
52 | super(site); | |
53 | } | |
54 | ||
55 | /** | |
56 | * Note: This constructor is for internal use only. Clients should not call this constructor. | |
57 | * @param editor the Java editor | |
58 | * | |
59 | * @noreference This constructor is not intended to be referenced by clients. | |
60 | */ | |
61 | public FindImplementorsAction(JavaEditor editor) { | |
62 | super(editor); | |
63 | } | |
64 | ||
65 | @Override | |
66 | void init() { | |
67 | setText(SearchMessages.Search_FindImplementorsAction_label); | |
68 | setToolTipText(SearchMessages.Search_FindImplementorsAction_tooltip); | |
69 | setImageDescriptor(JavaPluginImages.DESC_OBJS_SEARCH_DECL); | |
70 | PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.FIND_IMPLEMENTORS_IN_WORKSPACE_ACTION); | |
71 | } | |
72 | ||
73 | @Override | |
74 | Class<?>[] getValidTypes() { | |
75 | return new Class[] { ICompilationUnit.class, IType.class}; | |
76 | } | |
77 | ||
78 | @Override | |
79 | boolean canOperateOn(IJavaElement element) { | |
80 | if (!super.canOperateOn(element)) | |
81 | return false; | |
82 | ||
83 | if (element.getElementType() == IJavaElement.TYPE) | |
84 | try { | |
85 | return ((IType) element).isInterface(); | |
86 | } catch (JavaModelException ex) { | |
87 | return false; | |
88 | } | |
89 | // should not happen: handled by super.canOperateOn | |
90 | return false; | |
91 | } | |
92 | ||
93 | @Override | |
94 | int getLimitTo() { | |
95 | return IJavaSearchConstants.IMPLEMENTORS; | |
96 | } | |
97 | ||
98 | @Override | |
99 | String getOperationUnavailableMessage() { | |
100 | return SearchMessages.JavaElementAction_operationUnavailable_interface; | |
101 | } | |
102 | ||
103 | public void generated_3436703268163862170(ImplementorsSearchGroup implementorssearchgroup, IWorkbenchSite site, ISelectionProvider specialSelectionProvider) { | |
104 | setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_IMPLEMENTORS_IN_WORKSPACE); | |
105 | ||
106 | implementorssearchgroup.fFindImplementorsInProjectAction= new FindImplementorsInProjectAction(site); | |
107 | implementorssearchgroup.fFindImplementorsInProjectAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_IMPLEMENTORS_IN_PROJECT); | |
108 | ||
109 | implementorssearchgroup.fFindImplementorsInWorkingSetAction= new FindImplementorsInWorkingSetAction(site); | |
110 | implementorssearchgroup.fFindImplementorsInWorkingSetAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_IMPLEMENTORS_IN_WORKING_SET); | |
111 | ||
112 | // register the actions as selection listeners | |
113 | ISelectionProvider provider= specialSelectionProvider == null ? implementorssearchgroup.fSite.getSelectionProvider() : specialSelectionProvider; | |
114 | ISelection selection= provider.getSelection(); | |
115 | implementorssearchgroup.registerAction(this, provider, selection, specialSelectionProvider); | |
116 | implementorssearchgroup.registerAction(implementorssearchgroup.fFindImplementorsInProjectAction, provider, selection, specialSelectionProvider); | |
117 | implementorssearchgroup.registerAction(implementorssearchgroup.fFindImplementorsInWorkingSetAction, provider, selection, specialSelectionProvider); | |
118 | } | |
119 | } | |
120 |