Undo question

I have an editor that is based on JGoView for SWT. Besides the JGoDocument, it also maintains a template file that stores diagram’s information. Something like:<?:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />


100, 100

When a node is added/removed/moved on the diagram, the template file is updated accordingly. Now the editor needs to support undo/redo. I want to keep the template file in sync after undo's and redo's. Any suggestions?

What you want to do is when a transaction ends, or when there is an undo or a redo, is to scan through the list of UndoableEdits and make the needed changes to your XML DOM.

One way to do that is to define a JGoDocumentListener that looks for the JGoDocumentEvents: FINISHED_TRANSACTION, FINISHED_UNDO, and FINISHED_REDO. The JGoDocumentEvent.getObject() will be a CompoundEdit of UndoableEdits. For regular transactions and redo, you'll want to scan this list in the forward direction, for undo, backwards.
Another way to do that is to install a custom JGoUndoManager that notices the same three events. This is the approach taken by the UpdateDemo example. Note how the logChanges method iterates over the JGoCompoundEdit and calls logChange on each one. The logChange method then figures out if the particular JGoDocumentChangedEdit represents something that requires some updating elsewhere -- in your case updating your XML DOM.

With Demo1, if I drop a red rectangle in canvas, and click undo, the rectangle disappears as expected. But if I drop a multiport node in canvas, and undo it, the multiport node stays. Is there something wrong with multiport? I am using JGoSWT 5.1.<?:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Hmmm, I’ll investigate as soon as I get a chance.