Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Which eclipse listener should I use to add annotations to an editor
Which eclipse listener should I use to add annotations to an editor [message #1019413] Fri, 15 March 2013 16:19 Go to next message
Stave Escura is currently offline Stave EscuraFriend
Messages: 6
Registered: March 2013
Junior Member
I'm not sure if this is the correct forum for this question. I thought about the JFace forum, but these question seems mostly an integration question.

I am an eclipse newbie. I have a long term goal which is to add my own annotations to the java editor: a bit like FindBugs. I want my own static code analysers, and to be able to add markers/annotations to resources.

So I have read a lot of excellent documentation, and undertaken a load of tutorials. The most helpful was probably www.ibm.com/developerworks/opensource/tutorials/os-ecl-commplgin2/section9.html. A lot of the Lars Vogel documents have been useful too. I can now make TextEditors with syntax highlighters. I am however struggling with the best approach for adding annotations.

I understand roughly how to do this: the text editor has a DocumentProvider. The DocumentProvider has an AnnotationModel. It is possible to add annotations to the annotation model.

My question is "where do I put this code" specifically the code that scans the text in the editor and updates the annotation model. It seems clear that this should be in response to a listener...but which one?

I have tried a ResourceChangeListener. This seems to only fire on a save option, rather than when text is typed. In addition I don't know how to get the editor from the resource. ("The" editor is probably a misnomer as presumably the resource can be open in multiple editors). I can find the current editor via IWorkbenchWindow activeWorkbenchWindow = workbench.getActiveWorkbenchWindow().getActivePage().getActiveEditor(), but this seems the wrong approach, as I want to update all relevant annotation models.

I have tried adding an ElementStateListener to the text editor. None of the events seem to be the one I want.

I've looked at DamageRepairers...these seem to nearly be what I want, except that long term I want to tie into the JavaEditor, so I don't want to change the default DamageRepair.

Thanks for all the help
Re: Which eclipse listener should I use to add annotations to an editor [message #1022115 is a reply to message #1019413] Thu, 21 March 2013 09:53 Go to previous messageGo to next message
Stave Escura is currently offline Stave EscuraFriend
Messages: 6
Registered: March 2013
Junior Member
OK since I posted the question I have found an OK solution.

In the question I was talking about adding annotations to the annotation model of the editor. While this works, I have found that it doesn't work too well: effectively I am fighting eclipse.

Instead (following this excellent tutorial www.ibm.com/developerworks/opensource/tutorials/os-eclipse-plugin-guide/index.html) I add the annotations to the resource, and the annotations are auto-magically added to the editor.

So when my plugin starts I run through the active resources, add annotations to them if needed, then add a resource changed listener which adds them as the resource is opened.
Re: Which eclipse listener should I use to add annotations to an editor [message #1064423 is a reply to message #1022115] Wed, 19 June 2013 08:25 Go to previous message
katie evans is currently offline katie evansFriend
Messages: 28
Registered: July 2012
Location: brisbane queensland austr...
Junior Member
Hi,
I am facing the same issue.
could you please help me with more details on
"So when my plugin starts I run through the active resources, add annotations to them if needed, then add a resource changed listener which adds them as the resource is opened."

Does this mean you have put code in activator ??

[Updated on: Wed, 19 June 2013 08:25]

Report message to a moderator

Previous Topic:Problem with MessageConsole and new line
Next Topic:Has ScrollBar different behaviour in SWT and RWT?
Goto Forum:
  


Current Time: Thu Apr 25 17:54:07 GMT 2024

Powered by FUDForum. Page generated in 0.02813 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top