Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
218 views
in Technique[技术] by (71.8m points)

java - Eclipse plugin print hyperlinks to console

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!

question from:https://stackoverflow.com/questions/65859088/eclipse-plugin-print-hyperlinks-to-console

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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());
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...