@Override public void run() { try { Point selection= fTextViewer.getTextWidget().getSelection(); IDocument document= fTextViewer.getDocument(); fLastLine= document.getLineOfOffset(document.getLength()) + 1; int startLine= selection == null ? 1 : fTextViewer.getTextWidget().getLineAtOffset(selection.x) + 1; String title= ConsoleMessages.TextViewerGotoLineAction_Go_To_Line_1; String message= MessageFormat.format(ConsoleMessages.TextViewerGotoLineAction_Enter_line_number__8, new Object[] {Integer.valueOf(fLastLine)}); String value= Integer.toString(startLine); Shell activeShell= fTextViewer.getTextWidget().getShell(); InputDialog d= new InputDialog(activeShell, title, message, value, new NumberValidator()); if (d.open() == Window.OK) { try { int line= Integer.parseInt(d.getValue()); gotoLine(line - 1); } catch (NumberFormatException x) { ConsolePlugin.errorDialog(activeShell, ConsoleMessages.TextViewerGotoLineAction_Go_To_Line_1, ConsoleMessages.TextViewerGotoLineAction_Exceptions_occurred_attempt_to_go_to_line_2, x); // } } } catch (BadLocationException x) { ConsolePlugin.errorDialog(fTextViewer.getTextWidget().getShell(), ConsoleMessages.TextViewerGotoLineAction_Go_To_Line_1, ConsoleMessages.TextViewerGotoLineAction_Exceptions_occurred_attempt_to_go_to_line_2, x); // return; } } }
public void run() { try { Point selection= fTextViewer.getTextWidget().getSelection(); IDocument document= fTextViewer.getDocument(); fLastLine= document.getLineOfOffset(document.getLength()) + 1; int startLine= selection == null ? 1 : fTextViewer.getTextWidget().getLineAtOffset(selection.x) + 1; String title= ConsoleMessages.TextViewerGotoLineAction_Go_To_Line_1; String message= MessageFormat.format(ConsoleMessages.TextViewerGotoLineAction_Enter_line_number__8, new Object[] {new Integer(fLastLine)}); String value= Integer.toString(startLine); Shell activeShell= fTextViewer.getTextWidget().getShell(); InputDialog d= new InputDialog(activeShell, title, message, value, new NumberValidator()); if (d.open() == Window.OK) { try { int line= Integer.parseInt(d.getValue()); gotoLine(line - 1); } catch (NumberFormatException x) { ConsolePlugin.errorDialog(activeShell, ConsoleMessages.TextViewerGotoLineAction_Go_To_Line_1, ConsoleMessages.TextViewerGotoLineAction_Exceptions_occurred_attempt_to_go_to_line_2, x); // } } } catch (BadLocationException x) { ConsolePlugin.errorDialog(fTextViewer.getTextWidget().getShell(), ConsoleMessages.TextViewerGotoLineAction_Go_To_Line_1, ConsoleMessages.TextViewerGotoLineAction_Exceptions_occurred_attempt_to_go_to_line_2, x); // return; } } }
/** * Jumps to the line. */ protected void gotoLine(int line) { IDocument document= fTextViewer.getDocument(); try { int start= document.getLineOffset(line); int length= document.getLineLength(line); fTextViewer.getTextWidget().setSelection(start, start + length); fTextViewer.revealRange(start, length); } catch (BadLocationException x) { ConsolePlugin.errorDialog(fTextViewer.getTextWidget().getShell(), ConsoleMessages.TextViewerGotoLineAction_Go_To_Line_1, ConsoleMessages.TextViewerGotoLineAction_Exceptions_occurred_attempt_to_go_to_line_2, x); // } }
/** * Jumps to the line. */ protected void gotoLine(int line) { IDocument document= fTextViewer.getDocument(); try { int start= document.getLineOffset(line); int length= document.getLineLength(line); fTextViewer.getTextWidget().setSelection(start, start + length); fTextViewer.revealRange(start, length); } catch (BadLocationException x) { ConsolePlugin.errorDialog(fTextViewer.getTextWidget().getShell(), ConsoleMessages.TextViewerGotoLineAction_Go_To_Line_1, ConsoleMessages.TextViewerGotoLineAction_Exceptions_occurred_attempt_to_go_to_line_2, x); // } }