1 12 package org.eclipse.jdt.internal.ui.callhierarchy; 13 14 import java.util.ArrayList ; 15 16 import org.eclipse.swt.SWT; 17 import org.eclipse.swt.dnd.Clipboard; 18 import org.eclipse.swt.events.FocusEvent; 19 import org.eclipse.swt.events.FocusListener; 20 import org.eclipse.swt.widgets.Composite; 21 import org.eclipse.swt.widgets.Menu; 22 import org.eclipse.swt.widgets.Table; 23 import org.eclipse.swt.widgets.TableColumn; 24 25 import org.eclipse.jface.action.IAction; 26 import org.eclipse.jface.action.IMenuListener; 27 import org.eclipse.jface.action.MenuManager; 28 import org.eclipse.jface.viewers.ArrayContentProvider; 29 import org.eclipse.jface.viewers.ColumnLayoutData; 30 import org.eclipse.jface.viewers.ColumnPixelData; 31 import org.eclipse.jface.viewers.ColumnWeightData; 32 import org.eclipse.jface.viewers.TableLayout; 33 import org.eclipse.jface.viewers.TableViewer; 34 35 import org.eclipse.ui.IActionBars; 36 import org.eclipse.ui.IViewSite; 37 import org.eclipse.ui.IWorkbenchPartSite; 38 import org.eclipse.ui.actions.ActionFactory; 39 40 41 42 class LocationViewer extends TableViewer { 43 private final String columnHeaders[] = { 44 CallHierarchyMessages.LocationViewer_ColumnIcon_header, 45 CallHierarchyMessages.LocationViewer_ColumnLine_header, 46 CallHierarchyMessages.LocationViewer_ColumnInfo_header}; 47 48 private ColumnLayoutData columnLayouts[] = { 49 new ColumnPixelData(18, false, true), 50 new ColumnWeightData(60), 51 new ColumnWeightData(300)}; 52 53 54 LocationViewer(Composite parent) { 55 super(createTable(parent)); 56 57 setContentProvider(new ArrayContentProvider()); 58 setLabelProvider(new LocationLabelProvider()); 59 setInput(new ArrayList ()); 60 61 createColumns(); 62 } 63 64 67 private static Table createTable(Composite parent) { 68 return new Table(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI | SWT.FULL_SELECTION); 69 } 70 71 private void createColumns() { 72 TableLayout layout = new TableLayout(); 73 getTable().setLayout(layout); 74 getTable().setHeaderVisible(true); 75 for (int i = 0; i < columnHeaders.length; i++) { 76 layout.addColumnData(columnLayouts[i]); 77 TableColumn tc = new TableColumn(getTable(), SWT.NONE,i); 78 tc.setResizable(columnLayouts[i].resizable); 79 tc.setText(columnHeaders[i]); 80 } 81 } 82 83 86 void initContextMenu(IMenuListener menuListener, String popupId, IWorkbenchPartSite viewSite) { 87 MenuManager menuMgr= new MenuManager(); 88 menuMgr.setRemoveAllWhenShown(true); 89 menuMgr.addMenuListener(menuListener); 90 Menu menu= menuMgr.createContextMenu(getControl()); 91 getControl().setMenu(menu); 92 viewSite.registerContextMenu(popupId, menuMgr, this); 93 } 94 95 98 LocationCopyAction initCopyAction(final IViewSite viewSite, final Clipboard clipboard) { 99 final LocationCopyAction copyAction= new LocationCopyAction(viewSite, clipboard, this); 100 101 getTable().addFocusListener(new FocusListener() { 102 IAction fViewCopyHandler; 103 public void focusLost(FocusEvent e) { 104 if (fViewCopyHandler != null) { 105 IActionBars actionBars= viewSite.getActionBars(); 106 actionBars.setGlobalActionHandler(ActionFactory.COPY.getId(), fViewCopyHandler); 107 actionBars.updateActionBars(); 108 fViewCopyHandler= null; 109 } 110 } 111 112 public void focusGained(FocusEvent e) { 113 IActionBars actionBars= viewSite.getActionBars(); 114 fViewCopyHandler= actionBars.getGlobalActionHandler(ActionFactory.COPY.getId()); 115 actionBars.setGlobalActionHandler(ActionFactory.COPY.getId(), copyAction); 116 actionBars.updateActionBars(); 117 } 118 }); 119 120 return copyAction; 121 } 122 123 126 void clearViewer() { 127 setInput(""); } 129 } 130 | Popular Tags |