KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > callhierarchy > OpenDeclarationAction


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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  * Jesper Kamstrup Linnet (eclipse@kamstrup-linnet.dk) - initial API and implementation
10  * (report 36180: Callers/Callees view)
11  *******************************************************************************/

12 package org.eclipse.jdt.internal.ui.callhierarchy;
13
14 import org.eclipse.jdt.core.IMember;
15 import org.eclipse.jdt.internal.corext.callhierarchy.MethodWrapper;
16 import org.eclipse.jdt.internal.ui.util.SelectionUtil;
17 import org.eclipse.jdt.ui.actions.OpenAction;
18 import org.eclipse.jface.viewers.ISelection;
19 import org.eclipse.ui.IWorkbenchSite;
20
21 /**
22  * This class is used for opening the declaration of an element from the call hierarchy view.
23  */

24 class OpenDeclarationAction extends OpenAction {
25     public OpenDeclarationAction(IWorkbenchSite site) {
26         super(site);
27     }
28
29     public boolean canActionBeAdded() {
30         // It is safe to cast to IMember since the selection has already been converted
31
IMember member = (IMember) SelectionUtil.getSingleElement(getSelection());
32         
33         if (member != null) {
34             return true;
35         }
36
37         return false;
38     }
39
40     public ISelection getSelection() {
41         return CallHierarchyUI.convertSelection(getSelectionProvider().getSelection());
42     }
43
44     public Object JavaDoc getElementToOpen(Object JavaDoc object) {
45         if (object instanceof MethodWrapper) {
46             return ((MethodWrapper) object).getMember();
47         }
48         return object;
49     }
50 }
51
Popular Tags