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 // TODO XXX Disabled for 3.1 import org.eclipse.debug.ui.console.IConsoleHyperlink;
12 import org.eclipse.debug.ui.console.IConsoleLineTracker;
13 import org.eclipse.jface.text.BadLocationException;
14 import org.eclipse.jface.text.IDocument;
15 import org.eclipse.jface.text.IRegion;
16 import org.eclipse.ui.IEditorPart;
17 import org.eclipse.ui.PartInitException;
18 import org.eclipse.ui.texteditor.ITextEditor;
21 public class ConsoleLineTracker implements IConsoleLineTracker {
23 private static class JavadocConsoleHyperLink /* TODO XXX Disabled for 3.1 implements IConsoleHyperlink */ {
25 private IPath fExternalPath;
26 private int fLineNumber;
28 public JavadocConsoleHyperLink(IPath externalPath, int lineNumber) {
29 fExternalPath= externalPath;
30 fLineNumber= lineNumber;
34 * @see org.eclipse.debug.ui.console.IConsoleHyperlink#linkEntered()
36 public void linkEntered() {
40 * @see org.eclipse.debug.ui.console.IConsoleHyperlink#linkExited()
42 public void linkExited() {
46 * @see org.eclipse.debug.ui.console.IConsoleHyperlink#linkActivated()
48 public void linkActivated() {
50 IFile[] files= ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(fExternalPath);
51 if (files.length > 0) {
52 for (int i = 0; i < files.length; i++) {
54 IEditorPart part= EditorUtility.openInEditor(curr, true);
56 if (part instanceof ITextEditor) {
57 revealLine((ITextEditor) part, fLineNumber);
63 } catch (BadLocationException e) {
64 PHPLaunchingPlugin.log(e);
65 } catch (PartInitException e) {
66 PHPLaunchingPlugin.log(e);
67 } catch (JavaModelException e) {
68 PHPLaunchingPlugin.log(e);
72 private void revealLine(ITextEditor editor, int lineNumber) throws BadLocationException {
73 IDocument document= editor.getDocumentProvider().getDocument(editor.getEditorInput());
74 IRegion region= document.getLineInformation(lineNumber - 1);
75 editor.selectAndReveal(region.getOffset(), 0);
81 private IConsole fConsole;
83 public ConsoleLineTracker() {
88 * @see org.eclipse.debug.ui.console.IConsoleLineTracker#init(org.eclipse.debug.ui.console.IConsole)
90 public void init(IConsole console) {
95 * @see org.eclipse.debug.ui.console.IConsoleLineTracker#lineAppended(org.eclipse.jface.text.IRegion)
97 public void lineAppended(IRegion line) {
99 int offset = line.getOffset();
100 int length = line.getLength();
101 String text = fConsole.getDocument().get(offset, length);
103 int index1= text.indexOf(':');
110 int index2= text.indexOf(':', index1 + 1);
111 while ((index2 != -1) && (path == null)) {
112 if (index1 < index2) {
114 String substr= text.substring(index1 + 1, index2);
115 lineNumber= Integer.parseInt(substr);
116 path= new Path(text.substring(0, index1));
117 } catch (NumberFormatException e) {
122 index2= text.indexOf(':', index1 + 1);
125 if (lineNumber != -1) {
126 JavadocConsoleHyperLink link= new JavadocConsoleHyperLink(path, lineNumber);
127 // TODO XXX Disabled for 3.1 fConsole.addLink(link, line.getOffset(), index1);
130 } catch (BadLocationException e) {
138 * @see org.eclipse.debug.ui.console.IConsoleLineTracker#dispose()
140 public void dispose() {