Code Jockey
Code Jockey

Reputation: 6721

How do I create a custom hyperlink functionality in Eclipse

I would like to know how to create and implement a custom hyperlink in the Eclipse UI - I do not want to make a complete custom editor, if at all possible - just add to my current ability to ctrl+click on an series of characters and automatically navigate straight to a matching reference.

I am not incredibly familiar with making Eclipse plugins, but I'm guessing that will be required.

I am good with regular expressions, if that helps.

I imagine it would be possible with some sort of declarative syntax (text that matches this pattern links to any lines that look like this in these files, or something)

Two of the things I've wanted to do are find a jsp file based upon a function that returns a string that matches one of those jsp files OR find one or more JavaScript functions in source code that use a particular name (these seem like they might be more complex than a declarative syntax would support)

If there are already one or more plugins that allow me to declare a "rule" like that, that would also work, but one or more tutorials on the topic would be excellent - Thanks!

Upvotes: 2

Views: 2184

Answers (3)

valentin
valentin

Reputation: 175

The maarten's answer is partially correct, but you also need to override getHyperlinkDetectorTargets() method of your TextSourceViewerConfiguration child (CustomSourceViewerConfiguration in the maarten's case). Something like that:

@Override
protected Map<String, IAdaptable> getHyperlinkDetectorTargets(
    ISourceViewer sourceViewer) {
    Map<String, IAdaptable> targets = 
        super.getHyperlinkDetectorTargets(sourceViewer);
        targets.put("editortest.editors.MyEditor", edit); 
        return targets;
    }

editortest.editors.MyEditor here is an ID of the target defined in org.eclipse.ui.workbench.texteditor.hyperlinkDetectorTargets. This solution works with the newest Eclipse Oxygen.

Upvotes: 0

maarten
maarten

Reputation: 465

For who finds this just like I did but still didn't get it to work:

When working with extension points to define HyperlinkDetectors for your CustomTextEditor be sure to have your CustomSourceViewerConfiguration extend TextSourceViewerConfiguration, not just SourceViewerConfiguration.

Because this is the class that contains the call to the registry with HyperlinkDetectors configured via the extension point. To activate them this class needs an IPreferenceStore so you must also initialize your CustomSourceViewerConfiguration with an IPreferenceStore in the constructor and call super(iPrefStore);

Upvotes: 1

Bananeweizen
Bananeweizen

Reputation: 22070

You want to implement a hyperlink detector. You have to create an Eclipse plugin, which implements that extension point. The "class" attribute of that extension point needs to point to a class which implements IHyperlinkDetector. Your best bet is probably to extend the AbstractHyperlinkDetector.

There is also a small tutorial by IBM. Be careful, it is from 2006, there might have been minor API changes since then.

Upvotes: 2

Related Questions