Package com.vaadin.client.widget.grid
Class DefaultEditorEventHandler<T>
- java.lang.Object
-
- com.vaadin.client.widget.grid.DefaultEditorEventHandler<T>
-
- Type Parameters:
T- The row type of the grid. The row type is the POJO type from where the data is retrieved into the column cells.
- All Implemented Interfaces:
Grid.Editor.EventHandler<T>
public class DefaultEditorEventHandler<T> extends Object implements Grid.Editor.EventHandler<T>
The default handler for Grid editor events. Offers several overridable protected methods for easier customization.- Since:
- 7.6
- Author:
- Vaadin Ltd
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classDefaultEditorEventHandler.CursorMoveDeltaSpecifies the direction at which the focus should move.
-
Field Summary
Fields Modifier and Type Field Description static intKEYCODE_BUFFERED_SAVEDefault key code for triggering save in buffered mode.static intKEYCODE_CLOSEDefault key code for hiding the editor.static intKEYCODE_MOVE_HORIZONTALDefault key code for moving cursor horizontally within the editor.static intKEYCODE_MOVE_VERTICALDefault key code for moving the editor up or down.static intKEYCODE_OPENDefault key code for showing the editor.
-
Constructor Summary
Constructors Constructor Description DefaultEditorEventHandler()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidconfirmValidity(boolean isValid)Confirms the valid status of the binder so as to determine whether to allow pending navigation action.protected voideditRow(Grid.EditorDomEvent<T> event, int rowIndex, int colIndex)Opens the editor over the row with the given index and attempts to focus the editor widget in the given column index.protected intfindNextEditableColumnIndex(Grid<T> grid, int startingWith)Finds index of the first editable column, starting at the specified index.protected intfindPrevEditableColumnIndex(Grid<T> grid, int startingWith)Finds index of the last editable column, searching backwards starting at the specified index.protected DefaultEditorEventHandler.CursorMoveDeltagetDeltaFromKeyDownEvent(Grid.EditorDomEvent<T> event)Returns the direction to which the cursor should move.protected booleanhandleBufferedMoveEvent(Grid.EditorDomEvent<T> event)Moves the editor to another column if the received event is a move event.protected booleanhandleCloseEvent(Grid.EditorDomEvent<T> event)Closes the editor if the received event is a close event.booleanhandleEvent(Grid.EditorDomEvent<T> event)Handles editor-related events in an appropriate way.protected booleanhandleMoveEvent(Grid.EditorDomEvent<T> event)Moves the editor to another row or another column if the received event is a move event.protected booleanhandleOpenEvent(Grid.EditorDomEvent<T> event)Opens the editor on the appropriate row if the received event is an open event.protected booleanisCloseEvent(Grid.EditorDomEvent<T> event)Returns whether the given event should close the editor.protected booleanisEditable(Grid<T> grid, Grid.Column<?,T> column)Checks whether the field within the given editor column is editable.protected booleanisOpenEvent(Grid.EditorDomEvent<T> event)Returns whether the given event should open the editor.protected booleanisTouchOpenEvent(Grid.EditorDomEvent<T> event)Returns whether the given event is a touch event that should open the editor.
-
-
-
Field Detail
-
KEYCODE_OPEN
public static final int KEYCODE_OPEN
Default key code for showing the editor.- See Also:
- Constant Field Values
-
KEYCODE_MOVE_VERTICAL
public static final int KEYCODE_MOVE_VERTICAL
Default key code for moving the editor up or down.- See Also:
- Constant Field Values
-
KEYCODE_CLOSE
public static final int KEYCODE_CLOSE
Default key code for hiding the editor.- See Also:
- Constant Field Values
-
KEYCODE_MOVE_HORIZONTAL
public static final int KEYCODE_MOVE_HORIZONTAL
Default key code for moving cursor horizontally within the editor.- See Also:
- Constant Field Values
-
KEYCODE_BUFFERED_SAVE
public static final int KEYCODE_BUFFERED_SAVE
Default key code for triggering save in buffered mode.- See Also:
- Constant Field Values
-
-
Method Detail
-
isTouchOpenEvent
protected boolean isTouchOpenEvent(Grid.EditorDomEvent<T> event)
Returns whether the given event is a touch event that should open the editor.- Parameters:
event- the received event- Returns:
- whether the event is a touch open event
-
isOpenEvent
protected boolean isOpenEvent(Grid.EditorDomEvent<T> event)
Returns whether the given event should open the editor. The default implementation returns true if and only if the event is a doubleclick or if it is a keydown event and the keycode isKEYCODE_OPEN.- Parameters:
event- the received event- Returns:
- true if the event is an open event, false otherwise
-
handleOpenEvent
protected boolean handleOpenEvent(Grid.EditorDomEvent<T> event)
Opens the editor on the appropriate row if the received event is an open event. The default implementation usesisOpenEvent.- Parameters:
event- the received event- Returns:
- true if this method handled the event and nothing else should be done, false otherwise
-
getDeltaFromKeyDownEvent
protected DefaultEditorEventHandler.CursorMoveDelta getDeltaFromKeyDownEvent(Grid.EditorDomEvent<T> event)
Returns the direction to which the cursor should move.- Parameters:
event- the mouse event, not null.- Returns:
- the direction. May return null if the cursor should not move.
-
handleMoveEvent
protected boolean handleMoveEvent(Grid.EditorDomEvent<T> event)
Moves the editor to another row or another column if the received event is a move event. The default implementation moves the editor to the clicked row if the event is a click; otherwise, if the event is a keydown and the keycode isKEYCODE_MOVE_VERTICAL, moves the editor one row up or down if the shift key is pressed or not, respectively. Keydown event with keycodeKEYCODE_MOVE_HORIZONTALmoves the editor left or right if shift key is pressed or not, respectively.- Parameters:
event- the received event- Returns:
- true if this method handled the event and nothing else should be done, false otherwise
-
findNextEditableColumnIndex
protected int findNextEditableColumnIndex(Grid<T> grid, int startingWith)
Finds index of the first editable column, starting at the specified index.- Parameters:
grid- the current grid, not null.startingWith- start with this column. Index into theGrid.getVisibleColumns().- Returns:
- the index of the nearest visible column; may return the
startingWithitself. Returns -1 if there is no such column.
-
isEditable
protected boolean isEditable(Grid<T> grid, Grid.Column<?,T> column)
Checks whether the field within the given editor column is editable.- Parameters:
grid- the grid that is being editedcolumn- the column to investigate- Returns:
trueif the field is editable,falseotherwise
-
findPrevEditableColumnIndex
protected int findPrevEditableColumnIndex(Grid<T> grid, int startingWith)
Finds index of the last editable column, searching backwards starting at the specified index.- Parameters:
grid- the current grid, not null.startingWith- start with this column. Index into theGrid.getVisibleColumns().- Returns:
- the index of the nearest visible column; may return the
startingWithitself. Returns -1 if there is no such column.
-
handleBufferedMoveEvent
protected boolean handleBufferedMoveEvent(Grid.EditorDomEvent<T> event)
Moves the editor to another column if the received event is a move event. By default the editor is moved on a keydown event with keycodeKEYCODE_MOVE_HORIZONTAL. This moves the editor left or right if shift key is pressed or not, respectively.- Parameters:
event- the received event- Returns:
- true if this method handled the event and nothing else should be done, false otherwise
-
isCloseEvent
protected boolean isCloseEvent(Grid.EditorDomEvent<T> event)
Returns whether the given event should close the editor. The default implementation returns true if and only if the event is a keydown event and the keycode isKEYCODE_CLOSE.- Parameters:
event- the received event- Returns:
- true if the event is a close event, false otherwise
-
handleCloseEvent
protected boolean handleCloseEvent(Grid.EditorDomEvent<T> event)
Closes the editor if the received event is a close event. The default implementation usesisCloseEvent.- Parameters:
event- the received event- Returns:
- true if this method handled the event and nothing else should be done, false otherwise
-
editRow
protected void editRow(Grid.EditorDomEvent<T> event, int rowIndex, int colIndex)
Opens the editor over the row with the given index and attempts to focus the editor widget in the given column index. If the given indices are outside of the existing range, the closest value within the range is used.- Parameters:
event- the wrapped DOM eventrowIndex- index of the row to editcolIndex- index of the editor column to focus
-
handleEvent
public boolean handleEvent(Grid.EditorDomEvent<T> event)
Description copied from interface:Grid.Editor.EventHandlerHandles editor-related events in an appropriate way. Opens, moves, or closes the editor based on the given event.- Specified by:
handleEventin interfaceGrid.Editor.EventHandler<T>- Parameters:
event- the received event- Returns:
- true if the event was handled and nothing else should be done, false otherwise
-
confirmValidity
public void confirmValidity(boolean isValid)
Description copied from interface:Grid.Editor.EventHandlerConfirms the valid status of the binder so as to determine whether to allow pending navigation action.- Specified by:
confirmValidityin interfaceGrid.Editor.EventHandler<T>- Parameters:
isValid-trueif the binder value is valid
-
-