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 83740 - BaseDocumentEvent prevents managing undoable edits in a reasonable way
Summary: BaseDocumentEvent prevents managing undoable edits in a reasonable way
Status: RESOLVED FIXED
Alias: None
Product: editor
Classification: Unclassified
Component: -- Other -- (show other bugs)
Version: 5.x
Hardware: All All
: P1 blocker (vote)
Assignee: issues@editor
URL:
Keywords:
Depends on:
Blocks: 81655 83624
  Show dependency tree
 
Reported: 2006-08-30 07:29 UTC by Nathan Fiedler
Modified: 2007-11-05 13:44 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Nathan Fiedler 2006-08-30 07:29:13 UTC
In fixing issue 8692, a change was made to BaseDocument and BaseDocumentEvent
that asserts that the last edit made will be the first edit undone. While quite
sensible, this fails to be useful and does not have anything to do with the bug
fix itself. In fact, it blocks a perfectly reasonable use of the document and
hinders managing its undoable edits.

For the XML Schema editor in the Enterprise Pack, we have a model that is backed
by a text file, which is stored in memory in a BaseDocument instance. The
document is editable by the user via a CloneableEditor. The model is editable
directly via a graphical interface, and changes made to the model are flushed to
the document. Because the model employs a fast tree-based undo/redo support, we
want to manage the model's undoable edits as well as the document's undoable
edits (otherwise, syncing the model with the text is very expensive). This is
described here:

   http://xml.netbeans.org/specs/undo/

As such, we have an undo queue with both document edits and model edits. When
the model edits are undone, they operate on the model and subsequently flush the
change back to the document. The document edits related to this model change are
discarded, as they are not relevant. Anything the model does to the document is
assumed to be perfect and does not need to be 'undone', unlike edits made by the
user.

Because the model flushed its change to the document when its edit was undone,
the BaseDocument lastModifyUndoEdit reference was changed. Subsequently, undoing
any document edit made by the user prior to the model change will result in a
CannotUndoException. As you can imagine, this is a disaster for us. After
spending three weeks developing this undo/redo solution, following Yarda's
explicit directions, we have been crippled by an assertion that, at best,
catches a problem that may never occur.

Another reason why the assertion is of little or no value is that it does not
guard against concurrent changes *after* the last edit is undone. So it only
catches the mistake the first time, but after that all sorts of awful things
could be done. It is of no use and it prevents our perfectly reasonable attempts
at using BaseDocument from succeeding. After all, we are the controller of the
document, we should be allowed to manage the undoable edits and document
contents as we see fit.
Comment 1 Nathan Fiedler 2006-09-05 23:22:57 UTC
Raising to P1, as the team agreed that this blocks our progress in this area.
Either this needs to be fixed or we need someone in NetBeans to explain how to
work around the issue.
Comment 2 Miloslav Metelka 2006-09-06 10:08:53 UTC
OK, I will remove the assertion. It was useful when the CloneableEditorSupport
did the adding of the undoable events asynchronously to prevent BaseDocument <->
UndoManager deadlocks - to ensure that there will not be undo called prior
physical adding of the undoable edit to the UndoManager (or more precisely
CES.getUndoRedo()). However Yarda has changed the UM in CES to first write-lock
the document to avoid the deadlocks and restored synchronous adding of the UEs.

I hope that you reuse the UM from CES.getUndoRedo() for your solution -
otherwise you would have two active UMs which would be problematic.
Comment 3 Miloslav Metelka 2006-09-06 11:35:26 UTC
Fixed in trunk:
Checking in BaseDocumentEvent.java;
/cvs/editor/libsrc/org/netbeans/editor/BaseDocumentEvent.java,v  <-- 
BaseDocumentEvent.java
new revision: 1.26; previous revision: 1.25

I will integrate into release55 branch as well.
Comment 5 Miloslav Metelka 2006-09-08 15:46:19 UTC
Integrated into release55:
Checking in libsrc/org/netbeans/editor/BaseDocumentEvent.java;
/cvs/editor/libsrc/org/netbeans/editor/BaseDocumentEvent.java,v  <-- 
BaseDocumentEvent.java
new revision: 1.24.40.2; previous revision: 1.24.40.1