Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » TextEditor - need correct approach for dynamic update of regions and markers(Editor based on TextEditor - I want to dynamically update regions and markers on change of text)
TextEditor - need correct approach for dynamic update of regions and markers [message #514901] Wed, 17 February 2010 05:23 Go to next message
Ari Unikoski is currently offline Ari UnikoskiFriend
Messages: 8
Registered: January 2010
Junior Member
I am creating a text editor based on TextEditor.

I want to dynamically update regions and markers whenever the user changes the text.

I have got it almost working - but I am pretty sure there is something fundamentally wrong with what what I am doing. Currently, I am recalculating the regions and markers from within the documentChanged method of my document scanner, by calling the computePartioning method.

I think this is wrong - because I have created new regions, and deleted old ones, but I don't see how to tell the underlying document or editor about these changes.

And in addition, I see some strange behaviour, which leads me to suspect that I am on the wrong track. For example, when I make a change that should remove markers (of type IMarker.PROBLEM) the following happens:


  • the marker is indeed deleted
  • the remaining markers in the "problems" window are still correct - clicking on them jumps to the right place in the code
  • some of the round circular markers for the remaining markers, on the left hand side are in the wrong position
  • similarly, some of the red rectangular bookmarks on the right hand side are in the wrong position
  • some of the remaining errors loose the red squiggly line under the error


Another example of bad behaviour is when I change some text so that I change the type of formatting (i.e. the underlying region.) Usually it works fine, but occaisionally it doesn't do the change until I change some other part of the text.

If I exit and reload the document, they all come out correctly.

Below are some code snippets to show what I am currently doing:

public class TPLEditor extends TextEditor {

private ColorManager colorManager;
private IEditorInput input;


public TPLEditor() {
super();
colorManager = new ColorManager();
setSourceViewerConfiguration(new TPLConfiguration(colorManager));
setDocumentProvider(new TPLDocumentProvider(this));
}

.
.
.

Inside TPLDocumentProvider I have


public class TPLDocumentProvider extends FileDocumentProvider {
private TPLEditor editor;
public TPLDocumentProvider(TPLEditor tplEditor) {
super();
editor = tplEditor;
}

protected IDocument createDocument(Object element) throws CoreException {
IDocument document = super.createDocument(element);
if (document != null) {
NewDocumentScanner partitioner = NewDocumentScanner.getInstance();
partitioner.connect(document);
document.setDocumentPartitioner(partitioner);
partitioner.setEditor(editor);
}
return document;
}
}


and inside NewDocumentScanner I have:

public boolean documentChanged(DocumentEvent arg0) {

try {
document.computePartitioning(0, document.getLength());
} catch (BadLocationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return true;
}

I have been going around in circles for over a week now. Anyone who can point me in the right direction, suggest an article, etc, I would greatly appreciate it.
Re: TextEditor - need correct approach for dynamic update of regions and markers [message #515594 is a reply to message #514901] Fri, 19 February 2010 13:50 Go to previous message
Dani Megert is currently offline Dani MegertFriend
Messages: 3802
Registered: July 2009
Senior Member
Ari Unikoski wrote:
> I am creating a text editor based on TextEditor.
>
> I want to dynamically update regions and markers whenever the user
> changes the text.
You need to distinguish between markers (IMarker) and annotations
(org.eclipse.jface.text.source.Annotation) in the editor. Markers are
reflecting saved state i.e. they should never be updated while typing in
the editor. Each annotation gets connected to a document position
(org.eclipse.jface.text.Position) by adding it to the document's
annotation model. Each such position already updates its region
automatically for you. I suggest you take a look at those classes and
especially at org.eclipse.ui.texteditor.ResourceMarkerAnnotationModel.

Dani
>
> I have got it almost working - but I am pretty sure there is something
> fundamentally wrong with what what I am doing. Currently, I am
> recalculating the regions and markers from within the documentChanged
> method of my document scanner, by calling the computePartioning method.
>
> I think this is wrong - because I have created new regions, and
> deleted old ones, but I don't see how to tell the underlying document
> or editor about these changes.
>
> And in addition, I see some strange behaviour, which leads me to
> suspect that I am on the wrong track. For example, when I make a
> change that should remove markers (of type IMarker.PROBLEM) the
> following happens:
>
>
> the marker is indeed deleted
> the remaining markers in the "problems" window are still correct -
> clicking on them jumps to the right place in the code
> some of the round circular markers for the remaining markers, on the
> left hand side are in the wrong position
> similarly, some of the red rectangular bookmarks on the right hand
> side are in the wrong position
> some of the remaining errors loose the red squiggly line under the error
>
>
> Another example of bad behaviour is when I change some text so that I
> change the type of formatting (i.e. the underlying region.) Usually it
> works fine, but occaisionally it doesn't do the change until I change
> some other part of the text.
>
> If I exit and reload the document, they all come out correctly.
>
> Below are some code snippets to show what I am currently doing:
>
> public class TPLEditor extends TextEditor {
>
> private ColorManager colorManager;
> private IEditorInput input;
>
>
> public TPLEditor() {
> super();
> colorManager = new ColorManager();
> setSourceViewerConfiguration(new TPLConfiguration(colorManager));
> setDocumentProvider(new TPLDocumentProvider(this));
> }
>
Previous Topic:How to disable jdt UI contributions with org.eclipse.activities?
Next Topic:Show a subset of preference pages and options in RCP App
Goto Forum:
  


Current Time: Thu Mar 28 09:13:43 GMT 2024

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

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

Back to the top