Eclipse editor: show markers on custom column of vertical ruler

eclipse, eclipse-plugin, eclipse-rcp, editor

Solution

You just have to use a different constructor for AnnotationRulerColumn:

AnnotationRulerColumn(int width, IAnnotationAccess annotationAccess) 

You can use `DefaultMarkerAnnotationAccess` for the argument `IAnnotationAccess`:

protected IVerticalRuler createVerticalRuler(){
    IVerticalRuler ruler =  super.createVerticalRuler();
    CompositeRuler ruler2 = (CompositeRuler) ruler;
    column1 = new AnnotationRulerColumn(100, new DefaultMarkerAnnotationAccess());
    ruler2.addDecorator(0, column1);
    ruler2.addDecorator(2, createLineNumberRulerColumn());
    column1.addAnnotationType("MARKER");
    return ruler;
}

I assume you have defined an annotation type with the name "MARKER" for your marker. If not, make sure to use the name of an annotation type, NOT marker type, for `column1.addAnnotationType("MARKER");`. You can define your own annotation type and map it to a marker type with the extension point Annotation Types.

Your marker/annotation should then show up on your own vertical ruler.

Problem

I asked a question before about VerticalRulers, with this hint I added a second Column to the VerticalRuler and tried to add a Marker to it, but the Marker always appears on the standard Column, but not on mine. I added a second line number column to illustrate my problem. How do I change this behavior? Thanks for any help. ``` @Override protected IVerticalRuler createVerticalRuler(){ IVerticalRuler ruler = super.createVerticalRuler(); ruler2 = (CompositeRuler) ruler; column1 = new AnnotationRulerColumn(100); ruler2.addDecorator(0, column1); ruler2.addDecorator(2, createLineNumberRulerColumn()); column1.addAnnotationType("MARKER"); return ruler; } public String check_line(){ IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor(); IFileEditorInput input = (IFileEditorInput)editor.getEditorInput() ; IFile file = input.getFile(); IResource res = (IResource) file; try{ IMarker m = res.createMarker(IMarker.MARKER); m.setAttribute(IMarker.LINE_NUMBER,2); m.setAttribute(IMarker.MESSAGE, "lala"); m.setAttribute(IMarker.TEXT, "test"); m.setAttribute(IMarker.PRIORITY, IMarker.PRIORITY_HIGH); m.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_INFO); } catch (CoreException e) { ... } return "marker created"; } ```

Original source