org.eclipse.ui.console.IHyperlink Java Examples

The following examples show how to use org.eclipse.ui.console.IHyperlink. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ErrorLineMatcher.java    From corrosion with Eclipse Public License 2.0 6 votes vote down vote up
private static IHyperlink makeHyperlink(IFile file, int lineNumber, int lineOffset) {
	return new IHyperlink() {
		@Override
		public void linkExited() {
			// ignore
		}

		@Override
		public void linkEntered() {
			// ignore
		}

		@Override
		public void linkActivated() {
			IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
			try {
				IEditorPart editorPart = IDE.openEditor(page, file);
				jumpToPosition(editorPart, lineNumber, lineOffset);
			} catch (PartInitException e) {
				// nothing to do here
			}
		}
	};
}
 
Example #2
Source File: PyOpenLastConsoleHyperlink.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
@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);
    }
}
 
Example #3
Source File: PythonConsoleLineTracker.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
@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) {
            if (length <= 0) {
                // Log.log("Trying to create link with invalid len: " + length);
                return;
            }
            console.addLink(link, offset, length);
        }

        @Override
        public String getContents(int offset, int length) throws BadLocationException {
            return console.getDocument().get(offset, length);
        }
    };
}
 
Example #4
Source File: PyUnitView.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
@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);
}
 
Example #5
Source File: PyUnitView.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
@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();
                }
            }
        }
    }
}
 
Example #6
Source File: ErrorLineMatcher.java    From corrosion with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void matchFound(PatternMatchEvent event) {
	try {
		int offset = event.getOffset();
		int length = event.getLength();
		IProcess process = (IProcess) console.getAttribute(IDebugUIConstants.ATTR_CONSOLE_PROCESS);
		if (process != null) {
			ILaunch launch = process.getLaunch();
			String projectAttribute = RustLaunchDelegateTools.PROJECT_ATTRIBUTE;
			String launchConfigurationType = launch.getLaunchConfiguration().getType().getIdentifier();
			if (launchConfigurationType.equals(RustLaunchDelegateTools.CORROSION_DEBUG_LAUNCH_CONFIG_TYPE)) {
				// support debug launch configs
				projectAttribute = ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME;
			}
			String projectName = launch.getLaunchConfiguration().getAttribute(projectAttribute, ""); //$NON-NLS-1$
			if (projectName.trim().isEmpty()) {
				return; // can't determine project so prevent error down
			}
			IWorkspaceRoot myWorkspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
			IProject myProject = myWorkspaceRoot.getProject(projectName);
			String errorString = console.getDocument().get(event.getOffset(), event.getLength());
			String[] coordinates = errorString.split(":"); //$NON-NLS-1$
			IHyperlink link = makeHyperlink(myProject.getFile(coordinates[0]), Integer.parseInt(coordinates[1]),
					Integer.parseInt(coordinates[2]));
			console.addHyperlink(link, offset, length);
		}
	} catch (BadLocationException | CoreException e) {
		// ignore
	}
}
 
Example #7
Source File: PatternToHyperlinkConverter.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
@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);
    }
  }
}
 
Example #8
Source File: XdsConsoleViewer.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
public void handleEvent(Event event) {
    IHyperlink hyperlink = getHyperlink();
    if (hyperlink instanceof IHyperlink2) {
        if (event.button == 1) {
            ((IHyperlink2) hyperlink).linkActivated(event);
        }
    }
}
 
Example #9
Source File: PydevConsole.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 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);
    }
}
 
Example #10
Source File: InformationPresenterWithLineTracker.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
@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();
    }
}
 
Example #11
Source File: PydevConsole.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * IConsole: Add a link to the console
 */
public void addLink(IConsoleHyperlink link, int offset, int length) {
    this.addLink((IHyperlink) link, offset, length);
}
 
Example #12
Source File: ScriptConsoleViewerWrapper.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
public IHyperlink getHyperlink() {
    return viewer.getHyperlink();
}
 
Example #13
Source File: ScriptConsoleViewerWrapper.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
public IHyperlink getHyperlink(int offset) {
    return viewer.getHyperlink(offset);
}
 
Example #14
Source File: PythonConsoleLineTrackerTest.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void addLink(IHyperlink link, int offset, int length) {
    linkRegions.add(new Region(offset, length));
}
 
Example #15
Source File: ILinkContainer.java    From Pydev with Eclipse Public License 1.0 votes vote down vote up
void addLink(IHyperlink link, int offset, int length);