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(int, E) 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
    • Method Detail

      • install

        public static <E> UndoRedoSupport install​(EventList<E> 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
      • 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.