]> git.uio.no Git - ifi-stolz-refaktor.git/blame - case-study/jdt-before/ui/org/eclipse/jdt/internal/ui/callhierarchy/OpenLocationAction.java
Case Study: adding data and statistics
[ifi-stolz-refaktor.git] / case-study / jdt-before / ui / org / eclipse / jdt / internal / ui / callhierarchy / OpenLocationAction.java
CommitLineData
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 * Jesper Kamstrup Linnet (eclipse@kamstrup-linnet.dk) - initial API and implementation
10 * (report 36180: Callers/Callees view)
11 *******************************************************************************/
12package org.eclipse.jdt.internal.ui.callhierarchy;
13
14import java.util.Iterator;
15
16import org.eclipse.jface.util.OpenStrategy;
17import org.eclipse.jface.viewers.ISelection;
18import org.eclipse.jface.viewers.ISelectionChangedListener;
19import org.eclipse.jface.viewers.IStructuredSelection;
20import org.eclipse.jface.viewers.SelectionChangedEvent;
21
22import org.eclipse.ui.IWorkbenchSite;
23
24import org.eclipse.jdt.internal.corext.callhierarchy.CallLocation;
25import org.eclipse.jdt.internal.corext.callhierarchy.MethodWrapper;
26
27import org.eclipse.jdt.ui.actions.SelectionDispatchAction;
28
29class OpenLocationAction extends SelectionDispatchAction {
30 private CallHierarchyViewPart fPart;
31
32 public OpenLocationAction(CallHierarchyViewPart part, IWorkbenchSite site) {
33 super(site);
34 fPart= part;
35 LocationViewer viewer= fPart.getLocationViewer();
36 setText(CallHierarchyMessages.OpenLocationAction_label);
37 setToolTipText(CallHierarchyMessages.OpenLocationAction_tooltip);
38 setEnabled(!fPart.getSelection().isEmpty());
39
40 viewer.addSelectionChangedListener(new ISelectionChangedListener() {
41 public void selectionChanged(SelectionChangedEvent event) {
42 setEnabled(!event.getSelection().isEmpty());
43 }
44 });
45 }
46
47 private boolean checkEnabled(IStructuredSelection selection) {
48 if (selection.isEmpty()) {
49 return false;
50 }
51
52 for (Iterator<?> iter = selection.iterator(); iter.hasNext();) {
53 Object element = iter.next();
54
55 if (element instanceof MethodWrapper) {
56 continue;
57 } else if (element instanceof CallLocation) {
58 continue;
59 }
60
61 return false;
62 }
63
64 return true;
65 }
66
67 /* (non-Javadoc)
68 * @see org.eclipse.jdt.ui.actions.SelectionDispatchAction#getSelection()
69 */
70 @Override
71 public ISelection getSelection() {
72 return fPart.getSelection();
73 }
74
75 /* (non-Javadoc)
76 * Method declared on SelectionDispatchAction.
77 */
78 @Override
79 public void run(IStructuredSelection selection) {
80 if (!checkEnabled(selection))
81 return;
82
83 for (Iterator<?> iter= selection.iterator(); iter.hasNext();) {
84 boolean noError= CallHierarchyUI.openInEditor(iter.next(), getShell(), OpenStrategy.activateOnOpen());
85 if (! noError)
86 return;
87 }
88 }
89}