KickJava   Java API By Example, From Geeks To Geeks.

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


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.ICompilationUnit;
17 import org.eclipse.jdt.core.IJavaElement;
18 import org.eclipse.jdt.core.IType;
19 import org.eclipse.jdt.core.JavaModelException;
20 import org.eclipse.jdt.core.search.IJavaSearchConstants;
21
22 import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
23 import org.eclipse.jdt.internal.ui.JavaPluginImages;
24 import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor;
25 import org.eclipse.jdt.internal.ui.search.SearchMessages;
26
27 /**
28  * Finds implementors of the selected element in the workspace.
29  * The action is applicable to selections representing a Java interface.
30  *
31  * <p>
32  * This class may be instantiated; it is not intended to be subclassed.
33  * </p>
34  *
35  * @since 2.0
36  */

37 public class FindImplementorsAction extends FindAction {
38
39     /**
40      * Creates a new <code>FindImplementorsAction</code>. The action
41      * requires that the selection provided by the site's selection provider is of type
42      * <code>org.eclipse.jface.viewers.IStructuredSelection</code>.
43      *
44      * @param site the site providing context information for this action
45      */

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

54     public FindImplementorsAction(JavaEditor editor) {
55         super(editor);
56     }
57
58     void init() {
59         setText(SearchMessages.Search_FindImplementorsAction_label);
60         setToolTipText(SearchMessages.Search_FindImplementorsAction_tooltip);
61         setImageDescriptor(JavaPluginImages.DESC_OBJS_SEARCH_DECL);
62         PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.FIND_IMPLEMENTORS_IN_WORKSPACE_ACTION);
63     }
64     
65     Class JavaDoc[] getValidTypes() {
66         return new Class JavaDoc[] { ICompilationUnit.class, IType.class};
67     }
68
69     boolean canOperateOn(IJavaElement element) {
70         if (!super.canOperateOn(element))
71             return false;
72
73         if (element.getElementType() == IJavaElement.TYPE)
74             try {
75                 return ((IType) element).isInterface();
76             } catch (JavaModelException ex) {
77                 return false;
78             }
79         // should not happen: handled by super.canOperateOn
80
return false;
81     }
82
83     int getLimitTo() {
84         return IJavaSearchConstants.IMPLEMENTORS;
85     }
86
87     String JavaDoc getOperationUnavailableMessage() {
88         return SearchMessages.JavaElementAction_operationUnavailable_interface;
89     }
90 }
91
92
Popular Tags