KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.Iterator JavaDoc;
15
16 import org.eclipse.jface.viewers.ISelection;
17 import org.eclipse.jface.viewers.IStructuredSelection;
18
19 import org.eclipse.ui.IWorkbenchSite;
20
21 import org.eclipse.jdt.ui.actions.SelectionDispatchAction;
22
23 import org.eclipse.jdt.internal.corext.callhierarchy.CallLocation;
24 import org.eclipse.jdt.internal.corext.callhierarchy.MethodWrapper;
25
26 class OpenLocationAction extends SelectionDispatchAction {
27     private CallHierarchyViewPart fPart;
28
29     public OpenLocationAction(CallHierarchyViewPart part, IWorkbenchSite site) {
30         super(site);
31         fPart= part;
32         setText(CallHierarchyMessages.OpenLocationAction_label);
33         setToolTipText(CallHierarchyMessages.OpenLocationAction_tooltip);
34     }
35
36     private boolean checkEnabled(IStructuredSelection selection) {
37         if (selection.isEmpty()) {
38             return false;
39         }
40
41         for (Iterator JavaDoc iter = selection.iterator(); iter.hasNext();) {
42             Object JavaDoc element = iter.next();
43
44             if (element instanceof MethodWrapper) {
45                 continue;
46             } else if (element instanceof CallLocation) {
47                 continue;
48             }
49
50             return false;
51         }
52
53         return true;
54     }
55
56     /* (non-Javadoc)
57      * @see org.eclipse.jdt.ui.actions.SelectionDispatchAction#getSelection()
58      */

59     public ISelection getSelection() {
60         return fPart.getSelection();
61     }
62     
63     /* (non-Javadoc)
64      * Method declared on SelectionDispatchAction.
65      */

66     public void run(IStructuredSelection selection) {
67         if (!checkEnabled(selection)) {
68             return;
69         }
70         for (Iterator JavaDoc iter= selection.iterator(); iter.hasNext();) {
71             boolean noError= CallHierarchyUI.openInEditor(iter.next(), getShell(), getDialogTitle());
72             if (! noError)
73                 return;
74         }
75     }
76
77     private String JavaDoc getDialogTitle() {
78         return CallHierarchyMessages.OpenLocationAction_error_title;
79     }
80 }
81
Popular Tags