@SuppressWarnings("restriction") private void processIOConsole(IOConsole ioConsole) { IDocument document = ioConsole.getDocument(); try { Position[] positions = document.getPositions(ConsoleHyperlinkPosition.HYPER_LINK_CATEGORY); Arrays.sort(positions, new Comparator<Position>() { @Override public int compare(Position o1, Position o2) { return Integer.compare(o1.getOffset(), o2.getOffset()); } }); if (positions.length > 0) { Position p = positions[positions.length - 1]; if (p instanceof ConsoleHyperlinkPosition) { ConsoleHyperlinkPosition consoleHyperlinkPosition = (ConsoleHyperlinkPosition) p; IHyperlink hyperLink = consoleHyperlinkPosition.getHyperLink(); hyperLink.linkActivated(); } } } catch (BadPositionCategoryException e) { Log.log(e); } }
@Override public void init(final IConsole console) { IProcess process = console.getProcess(); if (process != null) { ILaunch launch = process.getLaunch(); if (launch != null) { initLaunchConfiguration(launch.getLaunchConfiguration()); } } this.linkContainer = new ILinkContainer() { @Override public void addLink(IHyperlink link, int offset, int length) { console.addLink(link, offset, length); } @Override public String getContents(int offset, int length) throws BadLocationException { return console.getDocument().get(offset, length); } }; }
@Override public void addLink(IHyperlink link, int offset, int length) { if (testOutputText == null) { return; } StyleRangeWithCustomData range = new StyleRangeWithCustomData(); range.underline = true; try { range.underlineStyle = SWT.UNDERLINE_LINK; } catch (Throwable e) { //Ignore (not available on earlier versions of eclipse) } //Set the proper color if it's available. TextAttribute textAttribute = ColorManager.getDefault().getHyperlinkTextAttribute(); if (textAttribute != null) { range.foreground = textAttribute.getForeground(); } else { range.foreground = JFaceColors.getHyperlinkText(Display.getDefault()); } range.start = offset; range.length = length + 1; range.customData = link; testOutputText.setStyleRange(range); }
@Override public void mouseUp(MouseEvent e) { Widget w = e.widget; if (w instanceof StyledText) { StyledText styledText = (StyledText) w; int offset = styledText.getCaretOffset(); if (offset >= 0 && offset < styledText.getCharCount()) { StyleRange styleRangeAtOffset = styledText.getStyleRangeAtOffset(offset); if (styleRangeAtOffset instanceof StyleRangeWithCustomData) { StyleRangeWithCustomData styleRangeWithCustomData = (StyleRangeWithCustomData) styleRangeAtOffset; Object l = styleRangeWithCustomData.customData; if (l instanceof IHyperlink) { ((IHyperlink) l).linkActivated(); } } } } }
@Override public void matchFound(PatternMatchEvent event) { int offset = event.getOffset(); int length = event.getLength(); int prefix = 0; try { String text = fConsole.getDocument().get(offset, length); IHyperlink link = new EclecticTraceHyperLink(fConsole); fConsole.addHyperlink(link, offset, length); } catch (BadLocationException e) { e.printStackTrace(); throw new RuntimeException(e); // IStatus status = new Status(IStatus.ERROR, "org.eclectic.debug.ui", 0, "Cannot set link for " + event, e); // throw new CoreException(status); } }
@Override public void matchFound(PatternMatchEvent event) { // remove the brackets int offset = event.getOffset() + 1; int length = event.getLength() - 2; try { String name = console.getDocument().get(offset, length); EObject ref = findBestReference(name); if (ref != null) { IHyperlink hyperlink = new AgreeConsoleHyperLink(ref); console.addHyperlink(hyperlink, offset, length); } } catch (BadLocationException e) { e.printStackTrace(); } }
@Override public void matchFound(PatternMatchEvent event) { if (event.getSource() instanceof TextConsole) { try { final TextConsole console = (TextConsole) event.getSource(); final int start = event.getOffset(); final int length = event.getLength(); IHyperlink link = new BrowserSupportBasedHyperlink(console.getDocument().get(start, length)); console.addHyperlink(link, start, length); } catch (BadLocationException e) { logger.log(Level.SEVERE, "Cannot create hyperlink", e); } } }
@Override public void matchFound(PatternMatchEvent event) { try { String fileReferenceText = console.getDocument().get(event.getOffset(), event.getLength()); int separatorIndex = fileReferenceText.lastIndexOf(":"); String absoluteFilePath = fileReferenceText.substring(0, separatorIndex); //String workspacePath = ResourcesPlugin.getWorkspace().getRoot().getLocation().toString(); //if (absoluteFilePath.startsWith(workspacePath)) { //String relativeFilePath = absoluteFilePath.substring(workspacePath.length()); //IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(relativeFilePath)); // this way can work, but only for files in the workspace :( int lineNumber = Integer.parseInt(fileReferenceText.substring(separatorIndex + 1)); //FileLink hyperlink = new FileLink(file, null, -1, -1, lineNumber); // a link to a file in the workspace IHyperlink hyperlink = makeHyperlink(absoluteFilePath, lineNumber); // a link to any file console.addHyperlink(hyperlink, event.getOffset(), event.getLength()); } } catch (Exception exception) { throw new RuntimeException(exception); } }
private static IHyperlink makeHyperlink(String absoluteFilePath, int lineNumber) { return new IHyperlink() { @Override public void linkExited() { } @Override public void linkEntered() { } @Override public void linkActivated() { IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); try { IEditorPart editorPart = IDE.openEditorOnFileStore(page, EFS.getStore(new File(absoluteFilePath).toURI())); goToLine(editorPart, lineNumber); } catch (Exception exception) { throw new RuntimeException(exception); } } }; }
/** * IConsole: Add a link to the console */ public void addLink(IHyperlink link, int offset, int length) { try { super.addHyperlink(link, offset, length); } catch (BadLocationException e) { Log.log(e); } }
@Override protected void onHandleClick(Object data) { if (data instanceof IHyperlink) { //The order is important (when activating it'll do a hide automatically, //but we want to do a hide without focusing the previous editor). this.hideInformationControl(false, false); ((IHyperlink) data).linkActivated(); } }
public void lineAppended(IRegion line) { try { int offset = line.getOffset(); int length = line.getLength(); String text = console.getDocument().get(offset, length); if (fErrorMatcher.match(text) || fWarningMatcher.match(text) || fBreakPointMatcher.match(text)) { Matcher m = fLineNumberMatcher.matcher(text); if (m.find()) { String lineNumber = text.substring(m.start(), m.end()); String file = text.substring(0, m.start()); Matcher m2 = fLineNumber.matcher(lineNumber); if (m2.find()) { String lineNo = lineNumber.substring(m2.start(), m2.end()); IHyperlink link = new DLabProConsoleHyperlink(lineNo, file, console); console.addLink(link, offset, m.end()); } } } } catch (BadLocationException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
/** * IConsole: Add a link to the console */ public void addLink(IConsoleHyperlink link, int offset, int length) { this.addLink((IHyperlink) link, offset, length); }
public IHyperlink getHyperlink() { return viewer.getHyperlink(); }
public IHyperlink getHyperlink(int offset) { return viewer.getHyperlink(offset); }
void addLink(IHyperlink link, int offset, int length);