KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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.swt.SWT;
15 import org.eclipse.swt.events.KeyListener;
16 import org.eclipse.swt.layout.GridData;
17 import org.eclipse.swt.widgets.Composite;
18 import org.eclipse.swt.widgets.Menu;
19 import org.eclipse.swt.widgets.Tree;
20
21 import org.eclipse.jface.action.IMenuListener;
22 import org.eclipse.jface.action.MenuManager;
23 import org.eclipse.jface.viewers.IOpenListener;
24 import org.eclipse.jface.viewers.ISelectionProvider;
25 import org.eclipse.jface.viewers.OpenEvent;
26 import org.eclipse.jface.viewers.StructuredSelection;
27 import org.eclipse.jface.viewers.TreeViewer;
28
29 import org.eclipse.ui.IWorkbenchPartSite;
30
31 import org.eclipse.jdt.internal.corext.callhierarchy.MethodWrapper;
32
33 import org.eclipse.jdt.internal.ui.viewsupport.ColoredViewersManager;
34
35 class CallHierarchyViewer extends TreeViewer {
36     private CallHierarchyViewPart fPart;
37
38     private OpenLocationAction fOpen;
39
40     private CallHierarchyContentProvider fContentProvider;
41
42     /**
43      * @param parent the parent composite
44      * @param part the call hierarchy view part
45      */

46     CallHierarchyViewer(Composite parent, CallHierarchyViewPart part) {
47         super(new Tree(parent, SWT.MULTI));
48
49         fPart = part;
50
51         getControl().setLayoutData(new GridData(GridData.FILL_BOTH));
52         setUseHashlookup(true);
53         setAutoExpandLevel(2);
54         fContentProvider = new CallHierarchyContentProvider(fPart);
55         setContentProvider(fContentProvider);
56         setLabelProvider(new CallHierarchyLabelProvider());
57
58         fOpen= new OpenLocationAction(part, part.getSite());
59         addOpenListener(new IOpenListener() {
60             public void open(OpenEvent event) {
61                 fOpen.run();
62             }
63         });
64         
65         ColoredViewersManager.install(this);
66
67         clearViewer();
68     }
69
70     /**
71      * @param wrapper
72      */

73     void setMethodWrapper(MethodWrapper wrapper) {
74         setInput(getTreeRoot(wrapper));
75
76         setFocus();
77         setSelection(new StructuredSelection(wrapper), true);
78     }
79
80     CallHierarchyViewPart getPart() {
81         return fPart;
82     }
83
84     /**
85      *
86      */

87     void setFocus() {
88         getControl().setFocus();
89     }
90
91     boolean isInFocus() {
92         return getControl().isFocusControl();
93     }
94
95     /**
96      * @param keyListener
97      */

98     void addKeyListener(KeyListener keyListener) {
99         getControl().addKeyListener(keyListener);
100     }
101
102     /**
103      * Wraps the root of a MethodWrapper tree in a dummy root in order to show
104      * it in the tree.
105      *
106      * @param root The root of the MethodWrapper tree.
107      * @return A new MethodWrapper which is a dummy root above the specified root.
108      */

109     private TreeRoot getTreeRoot(MethodWrapper root) {
110         TreeRoot dummyRoot = new TreeRoot(root);
111
112         return dummyRoot;
113     }
114
115     /**
116      * Attaches a contextmenu listener to the tree
117      * @param menuListener the menu listener
118      * @param viewSite the view site
119      * @param selectionProvider the selection provider
120      */

121     void initContextMenu(IMenuListener menuListener, IWorkbenchPartSite viewSite, ISelectionProvider selectionProvider) {
122         MenuManager menuMgr= new MenuManager();
123         menuMgr.setRemoveAllWhenShown(true);
124         menuMgr.addMenuListener(menuListener);
125         Menu menu= menuMgr.createContextMenu(getTree());
126         getTree().setMenu(menu);
127         viewSite.registerContextMenu(menuMgr, selectionProvider);
128     }
129
130     /**
131      *
132      */

133     void clearViewer() {
134         setInput(TreeRoot.EMPTY_ROOT);
135     }
136     
137     void cancelJobs() {
138         if (fPart == null)
139             return;
140         fContentProvider.cancelJobs(fPart.getCurrentMethodWrapper());
141     }
142 }
143
Popular Tags