Eclipse editor: show markers on a custom vertical ruler column

I asked a question before VerticalRulers , with this hint I added a second column to 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 column of the number to illustrate my problem. How to 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"; } 

enter image description here

+7
source share
1 answer

You just need to use a different constructor for AnnotationRulerColumn:

 AnnotationRulerColumn(int width, IAnnotationAccess annotationAccess) 

You can use IAnnotationAccess for the IAnnotationAccess argument:

 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 that you have defined an annotation type named "MARKER" for your marker. If not, be sure to use the annotation type name, NOT the marker type, for column1.addAnnotationType("MARKER"); . You can define your own annotation type and map it to a marker type with an extension point Annotation Types .

Your marker / annotation should appear on your own vertical ruler.

+3
source

All Articles