1 11 package org.eclipse.ant.internal.ui; 12 13 import java.io.File ; 14 15 import org.eclipse.core.filesystem.EFS; 16 import org.eclipse.core.filesystem.IFileStore; 17 import org.eclipse.core.runtime.CoreException; 18 import org.eclipse.jface.text.BadLocationException; 19 import org.eclipse.jface.text.IDocument; 20 import org.eclipse.jface.text.IRegion; 21 import org.eclipse.ui.IEditorInput; 22 import org.eclipse.ui.IEditorPart; 23 import org.eclipse.ui.IWorkbenchPage; 24 import org.eclipse.ui.PartInitException; 25 import org.eclipse.ui.console.IHyperlink; 26 import org.eclipse.ui.ide.FileStoreEditorInput; 27 import org.eclipse.ui.texteditor.IDocumentProvider; 28 import org.eclipse.ui.texteditor.ITextEditor; 29 30 public class ExternalHyperlink implements IHyperlink { 31 32 private File fFile; 33 private int fLineNumber; 34 35 public ExternalHyperlink(File file, int lineNumber) { 36 super(); 37 fFile = file; 38 fLineNumber= lineNumber; 39 } 40 41 public void linkEntered() { 42 } 43 44 public void linkExited() { 45 } 46 47 public void linkActivated() { 48 IEditorInput input; 49 IFileStore fileStore; 50 try { 51 fileStore= EFS.getStore(fFile.toURI()); 52 input = new FileStoreEditorInput(fileStore); 53 } catch (CoreException e) { 54 AntUIPlugin.log(e); 56 return; 57 } 58 59 IWorkbenchPage activePage = AntUIPlugin.getActiveWorkbenchWindow().getActivePage(); 60 try { 61 IEditorPart editorPart= activePage.openEditor(input, "org.eclipse.ant.ui.internal.editor.AntEditor", true); if (fLineNumber > 0 && editorPart instanceof ITextEditor) { 63 ITextEditor textEditor = (ITextEditor)editorPart; 64 65 IDocumentProvider provider = textEditor.getDocumentProvider(); 66 try { 67 provider.connect(input); 68 } catch (CoreException e) { 69 AntUIPlugin.log(e); 71 return; 72 } 73 IDocument document = provider.getDocument(input); 74 try { 75 IRegion lineRegion= document.getLineInformation(fLineNumber); 76 textEditor.selectAndReveal(lineRegion.getOffset(), lineRegion.getLength()); 77 } catch (BadLocationException e) { 78 AntUIPlugin.log(e); 80 } 81 provider.disconnect(input); 82 } 83 84 } catch (PartInitException e) { 85 } 86 } 87 } | Popular Tags |