Eclipse编辑器:在垂直标尺的自定义列上显示标记 [英] Eclipse editor: show markers on custom column of vertical ruler

查看:546
本文介绍了Eclipse编辑器:在垂直标尺的自定义列上显示标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我曾询问过关于VerticalRulers的。



您的标记/注释应该显示在您的自己的垂直标尺。


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";
}

解决方案

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.

这篇关于Eclipse编辑器:在垂直标尺的自定义列上显示标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆