這是一個老問題,但我有這個問題,這樣做:
我有一個編輯器(org.eclipse.ui.texteditor.AbstractDecoratedTextEditor)。在此編輯器類我實現了這個方法:
@Override
protected IVerticalRulerColumn createAnnotationRulerColumn(CompositeRuler ruler) {
AnnotationRulerColumn column = new MyAnnotationRulerColumn(VERTICAL_RULER_WIDTH, getAnnotationAccess(), this);
return column;
}
和類MyAnnotationRulerColumn被有些人認爲這樣的:
import org.eclipse.debug.ui.actions.ToggleBreakpointAction;
import org.eclipse.jface.text.source.AnnotationRulerColumn;
import org.eclipse.jface.text.source.IAnnotationAccess;
import org.eclipse.jface.text.source.IVerticalRulerInfo;
public class MyAnnotationRulerColumn extends AnnotationRulerColumn {
private MyEditor editor;
public MyAnnotationRulerColumn(int width, IAnnotationAccess annotationAccess, MyEditor part) {
super(width, annotationAccess);
this.editor = part;
}
@Override
protected void mouseDoubleClicked(int rulerLine) {
if (editor != null) {
IVerticalRulerInfo rulerInfo= (IVerticalRulerInfo) editor.getAdapter(IVerticalRulerInfo.class);
ToggleBreakpointAction action = new ToggleBreakpointAction(editor, null, rulerInfo);
action.update();
action.run();
}
}
}