Eclipse: how to implement actions for annotation markers?

In the text editor, the markers are displayed on the vertical ruler. In Java source editor (CompilationUnitEditor class), you can click a problem marker, then a suggestion list will pop up. It’s pretty user friendly, isn’t it?

Then, how to implement our own clickable annotation marker? Generally the following steps address the issue:

  1. Add the extension org.eclipse.ui.editorActions.
  2. Add an editorContribution sub node. Config the contribution.
  3. Implement an AbstractRulerActionDelegate for the contribution. In its createAction method, return your customized action.
  4. Implement your customized action by extending SelectMarkerRulerAction. In the action, you may be interested to traverse through annotation model, to invoke the appropriate commands.

Examples are best tutorials.  Therefore, let’s take a look at Java source editor in org.eclipse.jdt.ui, step bey step:

1. The editorActions contribution in JDT UI plug-in:

Pay attention to actionID and targetID.

2. The AbstractRulerActionDelegate. It uses template pattern to let you create your own action:

3. The SelectMarkerRulerAction. It is needed to access the annotation model. If you don’t need to access annotation model, of course you can use other actions. The Java editor version is JavaSelectAnnotationRulerAction. It contains complicated relations. Therefore, to make it simple, here I paste my simple version:

Hope the example above helps.

This entry was posted in eclipse, java and tagged , , , , , , , . Bookmark the permalink.

One Response to Eclipse: how to implement actions for annotation markers?

  1. Pingback: Eclipse: How to add actions for marker clicking | People Mountains People Sea

Leave a Reply

Your email address will not be published. Required fields are marked *

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.