| 1 19 20 21 package ca.mcgill.sable.soot.ui; 22 23 24 import org.eclipse.jface.text.*; 25 import org.eclipse.jface.action.*; 26 import org.eclipse.swt.widgets.*; 27 import org.eclipse.ui.part.*; 28 import org.eclipse.swt.*; 29 import org.eclipse.ui.*; 30 31 32 public class SootOutputView extends ViewPart implements ITextListener, IDocumentListener { 33 private TextViewer textViewer; 34 35 private Control control; 36 private Action selectAllAction; 37 private Action copyAction; 38 39 public SootOutputView() { 40 super(); 41 } 42 43 public void createPartControl(Composite parent) { 44 setTextViewer(new TextViewer(parent, getSWTStyles())); 45 getTextViewer().setEditable(false); 46 setControl(parent); 47 createActions(); 48 createContextMenu(); 49 hookGlobalActions(); 50 } 51 52 private void createActions() { 53 selectAllAction = new Action("selectAll"){ 54 public void run() { 55 selectAll(); 56 } 57 }; 58 copyAction = new Action("copy"){ 59 public void run() { 60 copy(); 61 } 62 }; 63 } 64 65 private void selectAll() { 66 getTextViewer().setSelection(new TextSelection(getTextViewer().getTopIndexStartOffset(), getTextViewer().getDocument().getLength())); 67 } 68 69 private void copy() { 70 getTextViewer().doOperation(ITextOperationTarget.COPY); 71 } 72 73 74 private void createContextMenu() { 75 MenuManager menuMgr = new MenuManager(); 77 menuMgr.setRemoveAllWhenShown(true); 78 menuMgr.addMenuListener(new IMenuListener() { 79 public void menuAboutToShow(IMenuManager mgr) { 80 fillContextMenu(mgr); 81 } 82 }); 83 84 Menu menu = menuMgr.createContextMenu(getTextViewer().getControl()); 86 getTextViewer().getControl().setMenu(menu); 87 88 getSite().registerContextMenu(menuMgr, getTextViewer()); 90 } 91 92 private void fillContextMenu(IMenuManager mgr) { 93 mgr.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS)); 94 mgr.add(new Separator()); 95 mgr.add(copyAction); 96 mgr.add(selectAllAction); 97 mgr.add(new Separator()); 98 99 } 100 101 private void hookGlobalActions() { 102 IActionBars bars = getViewSite().getActionBars(); 103 bars.setGlobalActionHandler(IWorkbenchActionConstants.COPY, copyAction); 104 bars.setGlobalActionHandler(IWorkbenchActionConstants.SELECT_ALL, selectAllAction); 105 106 } 107 108 109 110 private static int getSWTStyles() { 111 int styles= SWT.H_SCROLL | SWT.V_SCROLL; 112 return styles; 113 } 114 115 public void setFocus() { 116 getTextViewer().getControl().setFocus(); 117 } 118 119 120 121 125 public Control getControl() { 126 return control; 127 } 128 129 133 public void setControl(Control control) { 134 this.control = control; 135 } 136 137 public void textChanged(TextEvent e) { 138 139 } 140 141 public void documentAboutToBeChanged(DocumentEvent e) { 142 } 143 144 public void documentChanged(DocumentEvent e) { 145 146 } 147 148 152 public TextViewer getTextViewer() { 153 return textViewer; 154 } 155 156 160 public void setTextViewer(TextViewer textViewer) { 161 this.textViewer = textViewer; 162 } 163 164 } 165 | Popular Tags |