ca.odell.glazedlists

Class UndoRedoSupport<E>


public final class UndoRedoSupport<E>
extends java.lang.Object

UndoRedoSupport, as the name suggests, will provide generic support for undoing and redoing groups of changes to an EventList. The granularity of each undoable edit is determined by the ListEvent from which it was generated.

Not every change described in a ListEvent results in an undoable edit. Specifically, a mutation of a list element IN PLACE does not produce an undoable edit. For example, an ObservableElementList which observes a change of an element, or a call to List.set with the same object at that index produce a ListEvent that does not have a corresponding UndoRedoSupport.Edit object. These ListEvents are ignored because they lack sufficient information to undo or redo the change.

In general UndoRedoSupport only makes sense for use with a BasicEventList or a trivial wrapper around a BasicEventList which does not affect the order or type of the elements, such as an ObservableElementList. Advanced transformations, such as SortedList or FilterList will not work as expected with this UndoRedoSupport class since their contents are controlled by information outside of themselves (Comparators and Matchers).

This class is agnostic to any particular GUI toolkit. As such it may be used in a headless environment or can also be bound to a specific toolkit.

Author:
James Lemieux

Nested Class Summary

static interface
UndoRedoSupport.Edit
Provides an easy interface to undo/redo a ListEvent in its entirety.
static interface
UndoRedoSupport.Listener
Implementations of this Listener interface should be registered with an UndoRedoSupport object via UndoRedoSupport.addUndoSupportListener(UndoRedoSupport.Listener).

Method Summary

static
UndoRedoSupport install(EventList source)
Installs support for undoing and redoing changes to the given source.
void
addUndoSupportListener(UndoRedoSupport.Listener l)
Add a UndoRedoSupport.Listener which will receive a callback when an undoable edit occurs on the given source EventList.
void
removeUndoSupportListener(UndoRedoSupport.Listener l)
Remove a UndoRedoSupport.Listener from receiving a callback when an undoable edit occurs on the given source EventList.
void
uninstall()
This method removes undo/redo support from the EventList it was installed on.

Method Details

UndoRedoSupport install

public static  UndoRedoSupport install(EventList source)
Installs support for undoing and redoing changes to the given source. To be notified of undoable changes, a UndoRedoSupport.Listener must be registered on the object that is returned by this method. That Listener object will typically add the UndoRedoSupport.Edit it is given over to whatever data structure is managing all undo/redo functions for the entire application.
Parameters:
source - the EventList on which to provide undo/redo capabilities
Returns:
an instance of UndoRedoSupport through which the undo/redo behaviour can be customized

addUndoSupportListener

public void addUndoSupportListener(UndoRedoSupport.Listener l)
Add a UndoRedoSupport.Listener which will receive a callback when an undoable edit occurs on the given source EventList.

removeUndoSupportListener

public void removeUndoSupportListener(UndoRedoSupport.Listener l)
Remove a UndoRedoSupport.Listener from receiving a callback when an undoable edit occurs on the given source EventList.

uninstall

public void uninstall()
This method removes undo/redo support from the EventList it was installed on. This method is useful when the EventList must outlive the UndoRedoSupport object itself. The UndoRedoSupport object will become available for garbage collection independently of the EventList it decorated with behaviour.

Glazed Lists, Copyright © 2003 publicobject.com, O'Dell Engineering.
Documentation build by pbuilder at 2009-07-14 22:05