Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Plugin Development Environment (PDE) » TextEditor AnnotationModel not supporting multiple Documents ?
TextEditor AnnotationModel not supporting multiple Documents ? [message #1794211] Mon, 27 August 2018 14:26
Jakob Sachs is currently offline Jakob SachsFriend
Messages: 15
Registered: May 2018
Junior Member
I'm working on a custom Editor in Eclipse. My Editor extends org.eclipse.ui.editors.text.TextEditor and I've written my own IDocumentProvider.

This is necessary for this because between the input file, and the IDocuments there is a 1:n ratio (for every input file there are more than one documents being sourced from it). (I use a custom OutlinePage to switch between the documents)

My issue is the following:

When I open the editor, everything works fine, but when I try to add an Annotation (a Bookmark e.g.), it stays when I change to a different document.
This is odd because I set the new AnnotationModel every time when changing, and when I check the model after changing documents, it is not the same.

But somehow the little visual marker on the left side doesn't disappear and stays there when saving, changing documents or calling getSourceViewer().getTextWidget().redraw();. Somehow the AnnotationModel of the SourceViewer auto adds all the Markers to the new AnnotationModel.

The Marker

This is my code:

    public class MyEditor extends TextEditor implements DocumentChangeListener {
        public MyEditor() {
    	    documentProvider = new DocumentProvider(this);
    	public void doDocumentChange() {




    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<>();
    	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()));
    	public IAnnotationModel getAnnotationModel(Object element) {
    		return anMods.get(data.getCurrentDataPoint());
    	public IDocument getDocument(Object element) {
    		IDocument doc = docs.get(data.getCurrentDataPoint());
    		IAnnotationModel amodl = anMods.get(data.getCurrentDataPoint());
    		String[] TYPES = { IDocument.DEFAULT_CONTENT_TYPE };
    		partitioner = new FastPartitioner(new RuleBasedPartitionScanner(), TYPES);
    		return doc;

Any help is appreciated!
Previous Topic:File in the folder don't associated with the editor
Next Topic:Exporting Feature Fails - Photon 4.8.0
Goto Forum:

Current Time: Sat Jun 03 19:33:27 GMT 2023

Powered by FUDForum. Page generated in 0.02120 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top