BeeSoft®
Since 1992
 

Content

 Welcome
 Products
       Abeona
       Gaia
       Hephaistos
       JavaGantt
             Features
             News
             Documentation
                   Programming domain objects
                   About JavaGantt model
                   Undo / Redo support
                   Localization support
                   Building a treetable
                   Painting a chart
                   Working with the time scale
                   JavaGantt actions
             License
             Download
             Purchase
 Services
       Promote your software
 Contact Us
 Links
      
  JavaGanttI®
© 2012 BeeSoft ®
 

Undo / Redo support

JavaGantt uses Swing undo package functionality to provide support for undo / redo operations.

There are two classes in eu.beesoft.gantt.undo package for that purpose:

  • UndoStep
  • StateEditableObject

StateEditableObject implements javax.swing.undo.StateEditable interface. Its constructor takes one object, and StateEditableObject can this object introspect and remember changed properties.

UndoStep is the descendant of javax.swing.undo.CompoundEdit class. It serves as a container of all operations for one undo / redo step. It offers two methods:

  • void registerObject (Object) - registers object to store / restore its state. If given object does not implement interface javax.swing.undo.StateEditable, the object is covered by StateEditableObject to make it eligibly for undo / redo operations. Then is object registered and its pre-state is obtained.
  • void end () - gets the post-edit state of the required objects and ends the edit.

If you want to process undo / redo, you have to:

  1. create an instance UndoStep
  2. call registerObject(Object) for each object that can be changed in executed action before any change occurs
  3. call end() after action finished
  4. obtain from JavaGantt an UndoManager instance
  5. on UndoManager instance invoke addEdit (UndoStep) method

Here is a code:


	// before any change occurs
	// object1 ... objectN are objects they could be changed
	UndoStep undo = new UndoStep ();
	undo.registerObject (object1);
	undo.registerObject (object2);
	...
	undo.registerObject (objectN);


	// action code here !
	...	

	// end of changes
	undo.end ();
	gantt.getUndoManager ().addEdit (undo);