Class SpreadsheetHistoryManager
java.lang.Object
com.vaadin.flow.component.spreadsheet.SpreadsheetHistoryManager
- All Implemented Interfaces:
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:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final LinkedList<Command> All executed command in chronological orderprotected intCurrent index within the historyprotected final SpreadsheetTarget Spreadsheet component -
Constructor Summary
ConstructorsConstructorDescriptionSpreadsheetHistoryManager(Spreadsheet spreadsheet) Creates a new history manager for the given Spreadsheet. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddCommand(Command command) Adds a command to the end of the command history.booleancanRedo()Determines if redo is possible at the moment.booleancanUndo()Determines if undo is possible at the moment.protected voidchangeSelection(Command command) Applies the cell selection from the given Command.voidclear()Clears the history.protected voiddiscardAllAfter(int index) Clears all history after the given history index NOT including the command at the given index.getCommand(int historyIndex) Gets the Command at the given history index.intGets the current index within the Command history.intGets the current size of the Command history.protected voidmakeSureCorrectSheetActive(Command command) Ensures that the correct sheet is active, as recorded in the given Command.voidredo()Does redo if possible.voidsetHistorySize(int historySize) Changes the history size.voidundo()Does undo if possible.
-
Field Details
-
historyIndex
protected int historyIndexCurrent index within the history -
commands
All executed command in chronological order -
spreadsheet
Target Spreadsheet component
-
-
Constructor Details
-
SpreadsheetHistoryManager
Creates a new history manager for the given Spreadsheet.- Parameters:
spreadsheet- Target spreadsheet
-
-
Method Details
-
clear
public void clear()Clears the history. -
addCommand
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
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
Ensures that the correct sheet is active, as recorded in the given Command.- Parameters:
command- Command to fetch the sheet from
-
changeSelection
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.
-