views:

218

answers:

1

I'm writing an eclipse plugin with a hyperlinked console, but I see BadLocationExceptions when creating the hyperlinks.

To create the hyperlink, I followed the instructions on the related question How to write a hyperlink to an eclipse console from a plugin.

Background: The issue appears to be that the underlying document is updated asynchronously to requests that write to the console (e.g. via a MessageOutputStream), so attempting to create a hyperlink immediately after a write won't work because the offset and length indices provided in the request are invalid.

To try to fix this, I created a DocumentListener on the underlying document, so I could detect when the console is updated and create the HyperLink at that point. But the listener is provided with events that correspond to bulk updates to the console - so I can't easily detect if the console has been updated yet. The only choice seems to be to search the console document for the string I want to hyperlink, which seems quite inefficient.

So the question is: when is the correct time to create a HyperLink, after writing to the console? Are there any proven mechanisms that guarantee the underlying document will have been updated when I issue my hyperlink creation request? An example of code that writes to the console then creates a HyperLink would be great.

Not sure of the exact version of eclipse (I'm writing this from home before heading into work) - but I do know that I'm using MessageConsole.addHyperlink() to issue the request.

A: 

I am in exactly the same situation, and came to the same conclusion: I add the hyperlink in a document listener, then remove the document listener. Note that you have no other option than searching for the string, because the console can be cleared by the user! In my case, it is not a severe performance penalty, so I'm happy with this solution.

thSoft