You're viewing an older version of Vaadin JavaDoc. Please see version 24.7.0 for the latest.
com.vaadin.flow.component.spreadsheet.

Class SpreadsheetHistoryManager

  • java.lang.Object
    • com.vaadin.flow.component.spreadsheet.SpreadsheetHistoryManager
  • All Implemented Interfaces:

    Serializable

    public class SpreadsheetHistoryManager
    extends Object
    implements Serializable

    SpreadsheetHistoryManager is an utility class of the Spreadsheet add-on. This class handles remembering any actions done in the Spreadsheet. The purpose is to allow the user to undo and redo any action.

    Author:

    Vaadin Ltd.

    See Also:

    Serialized Form

    • Field Detail

      • historyIndex

        protected int historyIndex

        Current index within the history

      • commands

        protected final LinkedList<Command> commands

        All executed command in chronological order

      • spreadsheet

        protected final Spreadsheet spreadsheet

        Target Spreadsheet component

    • Constructor Detail

      • SpreadsheetHistoryManager

        public SpreadsheetHistoryManager​(Spreadsheet spreadsheet)

        Creates a new history manager for the given Spreadsheet.

        Parameters:

        spreadsheet - Target spreadsheet

    • Method Detail

      • clear

        public void clear()

        Clears the history.

      • addCommand

        public void addCommand​(Command command)

        Adds a command to the end of the command history. Discards commands after the current position (historyIndex) within the history.

        Parameters:

        command - Command to add as the latest command in history

      • getCommand

        public Command getCommand​(int historyIndex)

        Gets the Command at the given history index.

        Parameters:

        historyIndex - Index of Command to get, 0-based

        Returns:

        The command at the index or IndexOutOfBoundsException

      • canRedo

        public boolean canRedo()

        Determines if redo is possible at the moment. In practice tells if there is at least one Command available after the current history index.

        Returns:

        true if redo() possible, false otherwise.

      • canUndo

        public boolean canUndo()

        Determines if undo is possible at the moment. In practice tells if there is at least one Command available before the current history index.

        Returns:

        true if undo() possible, false otherwise.

      • redo

        public void redo()

        Does redo if possible. Changes the active sheet to match the one the command belongs to and updates the selection if needed.

      • undo

        public void undo()

        Does undo if possible. Changes the active sheet to match the one that the command belongs to and updates the selection if needed.

      • setHistorySize

        public void setHistorySize​(int historySize)

        Changes the history size. Discards possible commands that won't fit the size anymore.

        Parameters:

        historySize - New size for Command history

      • getHistorySize

        public int getHistorySize()

        Gets the current size of the Command history. The default size is 20 commands.

        Returns:

        Current size of history.

      • getHistoryIndex

        public int getHistoryIndex()

        Gets the current index within the Command history.

        Returns:

        Current history index, 0-based

      • makeSureCorrectSheetActive

        protected void makeSureCorrectSheetActive​(Command command)

        Ensures that the correct sheet is active, as recorded in the given Command.

        Parameters:

        command - Command to fetch the sheet from

      • changeSelection

        protected void changeSelection​(Command command)

        Applies the cell selection from the given Command.

        Parameters:

        command - Command to fetch the cell selection from.

      • discardAllAfter

        protected void discardAllAfter​(int index)

        Clears all history after the given history index NOT including the command at the given index.

        Parameters:

        index - History index to start the clearing from.