How to write a hyperlink to the eclipse console from the plugin

I would like to write the file location in the eclipse console as a hyperlink. When you click on it, it should open the file in an eclipse. I'm doing something similar right now (but the link is not showing)

console = new MessageConsole("myconsole", null);
console.activate();
ConsolePlugin.getDefault().getConsoleManager().addConsoles(new IConsole[]{ console });

IPath path = Path.fromOSString(filePath);
IFile file = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(path);
FileLink fileLink = new FileLink(file, null, 0, 0, 0);
console.addHyperlink(fileLink, 0, 0);

I probably shouldn't go to 0 for offset, filelength, etc.

Any help was appreciated.

+3
source share
2 answers

Well, it turns out that the code I wrote is good, with the exception of two minor changes, it should actually be

console = new MessageConsole("myconsole", null);
console.activate();
ConsolePlugin.getDefault().getConsoleManager().addConsoles(new IConsole[]{ console });

IPath path = Path.fromOSString(filePath);
IFile file = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(path);
FileLink fileLink = new FileLink(file, null, -1, -1, -1);
console.addHyperlink(fileLink, 10, 5); 

I was a little surprised that it was necessary to provide for an offset (10), which is calculated from the beginning of the console output. Why do you even want to calculate it yourself, but this is another discussion.

+4

(filename:linenumber), .

. Eclipse ?

+1

Source: https://habr.com/ru/post/1703900/


All Articles