1 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 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 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 87 void setFocus() { 88 getControl().setFocus(); 89 } 90 91 boolean isInFocus() { 92 return getControl().isFocusControl(); 93 } 94 95 98 void addKeyListener(KeyListener keyListener) { 99 getControl().addKeyListener(keyListener); 100 } 101 102 109 private TreeRoot getTreeRoot(MethodWrapper root) { 110 TreeRoot dummyRoot = new TreeRoot(root); 111 112 return dummyRoot; 113 } 114 115 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 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 |