Eclipse编辑器:AnnotationModel不更新?

时间:2018-08-22 12:55:07

标签: eclipse eclipse-plugin pde

我正在使用Eclipse中的自定义编辑器。我的编辑器扩展了org.eclipse.ui.editors.text.TextEditor,我已经编写了自己的IDocumentProvider

这是必要的,因为在输入文件和IDocument之间存在1:n的比率(每个输入文件都有多个源文件)。 (我使用自定义OutlinePage在文档之间进行切换)

我的问题如下:

当我打开编辑器时,一切正常,但是当我尝试添加注释(例如书签)时,当我切换到其他文档时它保持不变。 这很奇怪,因为每次更改时我都会设置新的AnnotationModel,并且在更改文档后检查模型时,它是不一样的。

但是在保存,更改文档或致电getSourceViewer().getTextWidget().redraw();时,左侧的可视小标记以某种方式不会消失并停留在该位置。

标记

The Marker

这是我的代码:

编辑器:

public class MyEditor extends TextEditor implements DocumentChangeListener {

    public MyEditor() {
        super();
        documentProvider = new DocumentProvider(this);
        setDocumentProvider(documentProvider);
    }

    @Override
    public void doDocumentChange() {

 getSourceViewer().setDocument(documentProvider.getDocument(getEditorInput()),
                documentProvider.getAnnotationModel(getEditorInput()));
        getSourceViewer().getTextWidget().redraw();
    }


    ...

}

DocumentProvider:

public class DocumentProvider implements IDocumentProvider, IDocumentProviderExtension, IDocumentProviderExtension2,
        IDocumentProviderExtension3, IDocumentProviderExtension4, IDocumentProviderExtension5 {
    private EditorPart ed;
    private FileEditorInput input;

    private MyData data;
    private FastPartitioner partitioner;

    private HashMap<Statement, IDocument> docs;
    private HashMap<Statement, IAnnotationModel> anMods;
    private IProgressMonitor progressMonitor;

    public DocumentProvider(EditorPart editor) {
        this.ed = editor;

        docs = new HashMap<>();
        anMods = new HashMap<>();
    }


    @Override
    public void connect(Object element) throws CoreException {

        element = (FileEditorInput) element;

        data = MyData.getInstance();
        File file = ((FileEditorInput) element).getPath().toFile();
        data.readFile(file, true);

        for (DataPoint dp : data.getDataPoints()) {

            docs.put(dp, new Document(dp.getSomeText()));
            anMods.put(dp, new ResourceMarkerAnnotationModel(((FileEditorInput) element).getFile()));

            }


    }

    @Override
    public IAnnotationModel getAnnotationModel(Object element) {

        return anMods.get(data.getCurrentAnalysis1Statement());
    }


    @Override
    public IDocument getDocument(Object element) {

        IDocument doc = docs.get(data.getFirstDataPoint());
        IAnnotationModel amodl = anMods.get(data.getFirstDataPoint());
        amodl.connect(doc);
        String[] TYPES = { IDocument.DEFAULT_CONTENT_TYPE };
        partitioner = new FastPartitioner(new RuleBasedPartitionScanner(), TYPES);
        partitioner.connect(doc);
        doc.setDocumentPartitioner(partitioner);

        return doc;
    }
}

感谢您的帮助!

0 个答案:

没有答案