Reputation: 514
I want to print hyperlinks to the console in an eclipse plugin.
I saw How to write a hyperlink to an eclipse console from a plugin, but get BadLocationException
when calling myconsole.addHyperlink(fileLink, 10, 5)
. I discovered that the class PatternMatchEvent
has getLength()
and getOffset()
I need for MessageConsole.addHyperlink()
.
Is using the approach in above link still the way to do this (the question was asked almost 12 years ago) and if so, how do I proceed to get access to these methods?
Any help is appreciated!
Upvotes: 0
Views: 363
Reputation: 111216
You can only use PatternMatcherEvent
in a class implementing IPatternMatchListener
which has been added to the console as a pattern match listener.
If you are not using a listener, then you have to find the offset of where you want to put the hyperlink by searching the console text.
You should be able to get the console text using:
IDocument document = myConsole.getDocument();
String text = document.get();
Find the text you want to use for the link:
String hyperlinkText = .... text you want to add the hyperlink to ...
int offset = text.indexOf(hyperlinkText);
Add the link if the text was found:
if (offset >= 0) {
myconsole.addHyperlink(fileLink, offset, hyperlinkText.length());
}
Upvotes: 1