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

https://i.stack.imgur.com/CPJM9.png

This is my code:

Editor:
    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.getCurrentDataPoint());
    	}
    
    
        @Override
    	public IDocument getDocument(Object element) {
    
    		IDocument doc = docs.get(data.getCurrentDataPoint());
    		IAnnotationModel amodl = anMods.get(data.getCurrentDataPoint());
    		amodl.connect(doc);
    		String[] TYPES = { IDocument.DEFAULT_CONTENT_TYPE };
    		partitioner = new FastPartitioner(new RuleBasedPartitionScanner(), TYPES);
    		partitioner.connect(doc);
    		doc.setDocumentPartitioner(partitioner);
    
    		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: Thu Apr 25 16:28:11 GMT 2024

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

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

Back to the top