Class UndoRedoHandler


  • public final class UndoRedoHandler
    extends java.lang.Object
    This is the global undo/redo handler for all DataSets.

    If you want to change a data set, you can use add(Command) to execute a command on it and make that command undoable.

    • Constructor Detail

      • UndoRedoHandler

        private UndoRedoHandler()
        Constructs a new UndoRedoHandler.
    • Method Detail

      • getInstance

        public static UndoRedoHandler getInstance()
        Returns the unique instance.
        Returns:
        the unique instance
        Since:
        14134
      • getUndoCommands

        public java.util.List<CommandgetUndoCommands()
        Returns all commands that were made on the dataset, that can be undone.
        Returns:
        all commands that were made on the dataset, that can be undone
        Since:
        14281, 16567 (signature)
      • getRedoCommands

        public java.util.List<CommandgetRedoCommands()
        Returns all commands that were made and undone on the dataset, that can be redone.
        Returns:
        all commands that were made and undone on the dataset, that can be redone.
        Since:
        14281, 16567 (signature)
      • getLastCommand

        public Command getLastCommand()
        Gets the last command that was executed on the command stack.
        Returns:
        That command or null if there is no such command.
        Since:
        #12316
      • hasUndoCommands

        public boolean hasUndoCommands()
        Determines if commands can be undone.
        Returns:
        true if at least a command can be undone
        Since:
        14281
      • hasRedoCommands

        public boolean hasRedoCommands()
        Determines if commands can be redone.
        Returns:
        true if at least a command can be redone
        Since:
        14281
      • addNoRedraw

        public void addNoRedraw​(Command c)
        Executes the command and add it to the intern command queue.
        Parameters:
        c - The command to execute. Must not be null.
      • addNoRedraw

        public void addNoRedraw​(Command c,
                                boolean execute)
        Executes the command and add it to the intern command queue.
        Parameters:
        c - The command to execute. Must not be null.
        execute - true: Execute, else it is assumed that the command was already executed
        Since:
        14845
      • afterAdd

        public void afterAdd​(Command cmd)
        Fires a commands change event after adding a command.
        Parameters:
        cmd - command added
        Since:
        13729
      • afterAdd

        public void afterAdd​(java.util.List<? extends Command> cmds)
        Fires a commands change event after adding a list of commands.
        Parameters:
        cmds - commands added
        Since:
        14381
      • add

        public void add​(Command c,
                        boolean execute)
        Executes the command only if wanted and add it to the intern command queue.
        Parameters:
        c - The command to execute. Must not be null.
        execute - true: Execute, else it is assumed that the command was already executed
      • add

        public void add​(Command c)
        Executes the command and add it to the intern command queue.
        Parameters:
        c - The command to execute. Must not be null.
      • undo

        public void undo()
        Undoes the last added command.
      • undo

        public void undo​(int num)
        Undoes multiple commands.
        Parameters:
        num - The number of commands to undo
      • redo

        public void redo()
        Redoes the last undoed command.
      • redo

        public void redo​(int num)
        Redoes multiple commands.
        Parameters:
        num - The number of commands to redo
      • fireCommandsChanged

        private void fireCommandsChanged()
        Fires a command change to all listeners.
      • clean

        public void clean()
        Resets the undo/redo list.
      • clean

        public void clean​(DataSet dataSet)
        Resets all commands that affect the given dataset.
        Parameters:
        dataSet - The data set that was affected.
        Since:
        12718