1 package net.sourceforge.phpdt.internal.launching;
3 import net.sourceforge.phpdt.core.JavaModelException;
4 import net.sourceforge.phpeclipse.phpeditor.EditorUtility;
6 import org.eclipse.core.resources.IFile;
7 import org.eclipse.core.resources.ResourcesPlugin;
8 import org.eclipse.core.runtime.IPath;
9 import org.eclipse.core.runtime.Path;
10 import org.eclipse.debug.ui.console.IConsole;
11 import org.eclipse.debug.ui.console.IConsoleLineTracker;
12 import org.eclipse.jface.text.BadLocationException;
13 import org.eclipse.jface.text.IDocument;
14 import org.eclipse.jface.text.IRegion;
15 import org.eclipse.ui.IEditorPart;
16 import org.eclipse.ui.PartInitException;
17 import org.eclipse.ui.texteditor.ITextEditor;
19 public class ConsoleLineTracker implements IConsoleLineTracker {
21 private static class JavadocConsoleHyperLink /*
22 * TODO XXX Disabled for 3.1
27 private IPath fExternalPath;
29 private int fLineNumber;
31 public JavadocConsoleHyperLink(IPath externalPath, int lineNumber) {
32 fExternalPath = externalPath;
33 fLineNumber = lineNumber;
39 * @see org.eclipse.debug.ui.console.IConsoleHyperlink#linkEntered()
41 public void linkEntered() {
47 * @see org.eclipse.debug.ui.console.IConsoleHyperlink#linkExited()
49 public void linkExited() {
55 * @see org.eclipse.debug.ui.console.IConsoleHyperlink#linkActivated()
57 public void linkActivated() {
59 IFile[] files = ResourcesPlugin.getWorkspace().getRoot()
60 .findFilesForLocation(fExternalPath);
61 if (files.length > 0) {
62 for (int i = 0; i < files.length; i++) {
63 IFile curr = files[0];
64 IEditorPart part = EditorUtility.openInEditor(curr,
67 if (part instanceof ITextEditor) {
68 revealLine((ITextEditor) part, fLineNumber);
74 } catch (BadLocationException e) {
75 PHPLaunchingPlugin.log(e);
76 } catch (PartInitException e) {
77 PHPLaunchingPlugin.log(e);
78 } catch (JavaModelException e) {
79 PHPLaunchingPlugin.log(e);
83 private void revealLine(ITextEditor editor, int lineNumber)
84 throws BadLocationException {
85 IDocument document = editor.getDocumentProvider().getDocument(
86 editor.getEditorInput());
87 IRegion region = document.getLineInformation(lineNumber - 1);
88 editor.selectAndReveal(region.getOffset(), 0);
93 private IConsole fConsole;
95 public ConsoleLineTracker() {
102 * @see org.eclipse.debug.ui.console.IConsoleLineTracker#init(org.eclipse.debug.ui.console.IConsole)
104 public void init(IConsole console) {
111 * @see org.eclipse.debug.ui.console.IConsoleLineTracker#lineAppended(org.eclipse.jface.text.IRegion)
113 public void lineAppended(IRegion line) {
115 int offset = line.getOffset();
116 int length = line.getLength();
117 String text = fConsole.getDocument().get(offset, length);
119 int index1 = text.indexOf(':');
126 int index2 = text.indexOf(':', index1 + 1);
127 while ((index2 != -1) && (path == null)) {
128 if (index1 < index2) {
130 String substr = text.substring(index1 + 1, index2);
131 lineNumber = Integer.parseInt(substr);
132 path = new Path(text.substring(0, index1));
133 } catch (NumberFormatException e) {
138 index2 = text.indexOf(':', index1 + 1);
141 if (lineNumber != -1) {
142 // JavadocConsoleHyperLink link = new JavadocConsoleHyperLink(
143 // path, lineNumber);
144 // TODO XXX Disabled for 3.1 fConsole.addLink(link,
145 // line.getOffset(), index1);
148 } catch (BadLocationException e) {
156 * @see org.eclipse.debug.ui.console.IConsoleLineTracker#dispose()
158 public void dispose() {