public void run() { TextViewer viewer = getTextViewer(); if (viewer == null) return; IDocument document = viewer.getDocument(); if (document == null) return; try { fLastLine = document.getLineOfOffset(document.getLength()) + 1; } catch (BadLocationException ex) { IStatus status = new Status( IStatus.ERROR, Q7UIPlugin.PLUGIN_ID, IStatus.OK, "Go to Line failed", ex); //$NON-NLS-1$ Q7UIPlugin.getDefault().getLog().log(status); return; } String title = DIALOG_TITLE; String message = MessageFormat.format(DIALOG_MESSAGE, new Integer(fLastLine)); String currentLineStr = ""; // $NON-NLS-1$ StyledText textWidget = viewer.getTextWidget(); int currentLine = textWidget.getLineAtOffset(textWidget.getCaretOffset()); if (currentLine > -1) currentLineStr = Integer.toString(currentLine + 1); InputDialog d = new InputDialog( viewer.getTextWidget().getShell(), title, message, currentLineStr, new NumberValidator()); if (d.open() == Window.OK) { try { int line = Integer.parseInt(d.getValue()); gotoLine(line - 1); } catch (NumberFormatException x) { } } }
private void gotoLine(int line) { TextViewer viewer = getTextViewer(); IDocument document = viewer.getDocument(); try { int start = document.getLineOffset(line); StyledText widget = viewer.getTextWidget(); widget.setRedraw(false); { viewer.revealRange(start, 0); viewer.setSelectedRange(start, 0); widget.setFocus(); } widget.setRedraw(true); } catch (BadLocationException e) { // ignore } }
/** @see ISelectionListener#selectionChanged(IWorkbenchPart, ISelection) */ public void selectionChanged(IWorkbenchPart part, ISelection selection) { if (!(selection instanceof IStructuredSelection)) return; Object element = ((IStructuredSelection) selection).getFirstElement(); long id = -1; String name = null; if (element instanceof BundleDescription) { id = ((BundleDescription) element).getBundleId(); name = ((BundleDescription) element).getSymbolicName(); } if (element instanceof BundleStats) { id = ((BundleStats) element).getId(); name = ((BundleStats) element).getSymbolicName(); } if (id == -1) return; PluginDependencyGraphNode node = (PluginDependencyGraphNode) getDependencyGraph().get(new Long(id)); String text = node == null ? NLS.bind(Messages.depend_noInformation, name) : node.toDeepString(); viewer.getDocument().set(text); viewer.refresh(); }
/** @see IWorkbenchPart#createPartControl */ public void createPartControl(Composite parent) { viewer = new TextViewer(parent, SWT.V_SCROLL | SWT.H_SCROLL | SWT.WRAP | SWT.READ_ONLY); viewer.setDocument(new Document()); IActionBars bars = getViewSite().getActionBars(); final GlobalAction clearOutputAction = new ClearTextAction(viewer.getDocument()); clearOutputAction.registerAsGlobalAction(bars); final GlobalAction selectAllAction = new SelectAllAction(viewer); selectAllAction.registerAsGlobalAction(bars); // Delete action shortcuts are not captured by the workbench // so we need our key binding service to handle Delete keystrokes for us this.viewer .getControl() .addKeyListener( new KeyAdapter() { public void keyPressed(KeyEvent e) { if (e.character == SWT.DEL) clearOutputAction.run(); } }); GlobalAction copyAction = new CopyTextSelectionAction(viewer); copyAction.registerAsGlobalAction(bars); bars.getToolBarManager().add(clearOutputAction); bars.updateActionBars(); // creates a context menu with actions and adds it to the viewer control MenuManager menuMgr = new MenuManager(); menuMgr.add(copyAction); menuMgr.add(clearOutputAction); Menu menu = menuMgr.createContextMenu(viewer.getControl()); viewer.getControl().setMenu(menu); getViewSite().getPage().addSelectionListener(this); }