This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 108845 - Explicit synchronization needed on DocumentModel
Summary: Explicit synchronization needed on DocumentModel
Status: RESOLVED FIXED
Alias: None
Product: xml
Classification: Unclassified
Component: Document Model (show other bugs)
Version: 5.x
Hardware: All All
: P2 blocker (vote)
Assignee: Marek Fukala
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-07-04 09:31 UTC by pbenes
Modified: 2007-09-25 01:31 UTC (History)
2 users (show)

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments
The change diff (5.06 KB, patch)
2007-07-04 09:49 UTC, Marek Fukala
Details | Diff
New diff (8.63 KB, patch)
2007-07-09 12:24 UTC, Marek Fukala
Details | Diff
New diff with the unit test (14.28 KB, patch)
2007-07-20 16:28 UTC, Marek Fukala
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description pbenes 2007-07-04 09:31:24 UTC
I am currently writing a visual editor for SVG images which are based on XML text. The editor makes it is possible to
edit SVG either as xml text or as visual content. To achieve good performance and fast response the DocumentModel is
used as internal model of XML file. Sometimes it is necessary to synchronize the model of text document with changes
done in the visual content. The existing synchronization algorithm waits for 2secs after last change in the text before
synchronization is started. This enforces either painful lags in in application responses or complicated workarounds. 

For this purpose it would be very nice to have possibility to force synchronization of model without waiting the 2secs
interval. Also I need to have information if the model is synchronized with text or not, to decide whether the model
update is needed.

Thanks.
Comment 1 Marek Fukala 2007-07-04 09:48:02 UTC
1) I have add three method to the DocumentModelListener:

    /** Called when the underlying javax.swing.Document has changed. */
    public void sourceChanged();
    
    /** Called when the DocumentModel update has started. */
    public void updateStarted();
    
    /** Called when the DocumentModel update has finished. */
    public void updateFinished();

which are called by the DocumentModel when necessary.

2) I have added a non-blocking DocumentModel.forceUpdate() method which starts the model update immediately. The client
is then supposed to listen on DocumentModelListener.updateFinished() to get know that the model is ready to be read.

I am attaching the changes in a diff, please test it and let me know about potential bottlenecks before I take this
change to the fast track review.

Thanks.
Comment 2 Marek Fukala 2007-07-04 09:49:04 UTC
Created attachment 44699 [details]
The change diff
Comment 3 pbenes 2007-07-06 00:06:33 UTC
The presented solution is probably feasible for my needs, but unfortunately the introduction of new methods to the
DocumentModelListener class is not backward compatible and thus breaks contract with other module(s). I have observed
problem with XmlFoldManager but there are probably more classes implementing this listener out there. For this reason I
could not finish the testing. Anyway I would propose some backward compatible variant of this change, possibly using new
listener class containg those three methods. This class could either extend the DocumentListener or can be separate with
its own add/remove/fire methods.
Comment 4 Marek Fukala 2007-07-09 10:28:05 UTC
Yes,I realized the backw. comp. problem after I post the comment. I'll make it backw. comp. and attach new patch soon. I
am sorry for that.
Comment 5 Marek Fukala 2007-07-09 12:23:45 UTC
Done, plese use the attached diff and confirm if the changes fulflis your needs.

Btw, I have changed the semantic of updateStarted() method and added one more method to the interface. Please read the
javadoc.

Comment 6 Marek Fukala 2007-07-09 12:24:27 UTC
Created attachment 44808 [details]
New diff
Comment 7 pbenes 2007-07-14 18:48:20 UTC
I have tested the new variant and it works very well. Please commit it into the CVS trunk after it passes the fast track
review (or whatever else the process requires). Thanks for help.
Comment 8 Marek Fukala 2007-07-20 12:28:54 UTC
I would like to ask for fasttrack review namely Pavel and Samaresh whether they agree with the change. 
Comment 9 pbenes 2007-07-20 13:30:30 UTC
I do agree with the change.
Comment 10 Jaroslav Tulach 2007-07-20 14:15:30 UTC
Y01 Write a test.
Comment 11 Marek Fukala 2007-07-20 16:27:10 UTC
Y01 fixed - new diff attached.
Comment 12 Marek Fukala 2007-07-20 16:28:40 UTC
Created attachment 45448 [details]
New diff with the unit test
Comment 13 Jaroslav Tulach 2007-07-20 17:17:39 UTC
Y02 You should probably increment spec version of your module and annotate new methods and class with @since tag.
Comment 14 Marek Fukala 2007-07-23 11:25:56 UTC
Y02 fixed. Changes commited to trunk.

Checking in nbproject/project.properties;
/cvs/xml/tageditorsupport/nbproject/project.properties,v  <--  project.properties
new revision: 1.14; previous revision: 1.13
done
Checking in test/unit/src/org/netbeans/modules/editor/structure/api/DocumentModelTest.java;
/cvs/xml/tageditorsupport/test/unit/src/org/netbeans/modules/editor/structure/api/DocumentModelTest.java,v  <-- 
DocumentModelTest.java
new revision: 1.5; previous revision: 1.4
done
RCS file: /cvs/xml/tageditorsupport/src/org/netbeans/modules/editor/structure/api/DocumentModelStateListener.java,v
done
Checking in src/org/netbeans/modules/editor/structure/api/DocumentModelStateListener.java;
/cvs/xml/tageditorsupport/src/org/netbeans/modules/editor/structure/api/DocumentModelStateListener.java,v  <-- 
DocumentModelStateListener.java
initial revision: 1.1
done
Checking in src/org/netbeans/modules/editor/structure/api/DocumentModel.java;
/cvs/xml/tageditorsupport/src/org/netbeans/modules/editor/structure/api/DocumentModel.java,v  <--  DocumentModel.java
new revision: 1.41; previous revision: 1.40
done
Checking in arch.xml;
/cvs/xml/tageditorsupport/arch.xml,v  <--  arch.xml
new revision: 1.7; previous revision: 1.6
done
Comment 15 Marek Fukala 2007-07-23 11:26:48 UTC
forgot to reassign
Comment 16 Marek Fukala 2007-07-23 11:28:31 UTC
fixed