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:
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 class
DefaultEditorEventHandler.CursorMoveDelta
Specifies the direction at which the focus should move.
-
Field Summary
Fields Modifier and Type Field Description static int
KEYCODE_BUFFERED_SAVE
Default key code for triggering save in buffered mode.
static int
KEYCODE_CLOSE
Default key code for hiding the editor.
static int
KEYCODE_MOVE_HORIZONTAL
Default key code for moving cursor horizontally within the editor.
static int
KEYCODE_MOVE_VERTICAL
Default key code for moving the editor up or down.
static int
KEYCODE_OPEN
Default key code for showing the editor.
-
Constructor Summary
Constructors Constructor Description DefaultEditorEventHandler()
-
Method Summary
All Methods Modifier and Type Method Description void
confirmValidity(boolean isValid)
Confirms the valid status of the binder so as to determine whether to allow pending navigation action.
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.
protected int
findNextEditableColumnIndex(Grid<T> grid, int startingWith)
Finds index of the first editable column, starting at the specified index.
protected int
findPrevEditableColumnIndex(Grid<T> grid, int startingWith)
Finds index of the last editable column, searching backwards starting at the specified index.
protected DefaultEditorEventHandler.CursorMoveDelta
getDeltaFromKeyDownEvent(Grid.EditorDomEvent<T> event)
Returns the direction to which the cursor should move.
protected boolean
handleBufferedMoveEvent(Grid.EditorDomEvent<T> event)
Moves the editor to another column if the received event is a move event.
protected boolean
handleCloseEvent(Grid.EditorDomEvent<T> event)
Closes the editor if the received event is a close event.
boolean
handleEvent(Grid.EditorDomEvent<T> event)
Handles editor-related events in an appropriate way.
protected boolean
handleMoveEvent(Grid.EditorDomEvent<T> event)
Moves the editor to another row or another column if the received event is a move event.
protected boolean
handleOpenEvent(Grid.EditorDomEvent<T> event)
Opens the editor on the appropriate row if the received event is an open event.
protected boolean
isCloseEvent(Grid.EditorDomEvent<T> event)
Returns whether the given event should close the editor.
protected boolean
isEditable(Grid<T> grid, Grid.Column<?,T> column)
Checks whether the field within the given editor column is editable.
protected boolean
isOpenEvent(Grid.EditorDomEvent<T> event)
Returns whether the given event should open the editor.
protected boolean
isTouchOpenEvent(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:
-
KEYCODE_MOVE_VERTICAL
public static final int KEYCODE_MOVE_VERTICAL
Default key code for moving the editor up or down.
See Also:
-
KEYCODE_CLOSE
public static final int KEYCODE_CLOSE
Default key code for hiding the editor.
See Also:
-
KEYCODE_MOVE_HORIZONTAL
public static final int KEYCODE_MOVE_HORIZONTAL
Default key code for moving cursor horizontally within the editor.
See Also:
-
KEYCODE_BUFFERED_SAVE
public static final int KEYCODE_BUFFERED_SAVE
Default key code for triggering save in buffered mode.
See Also:
-
-
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 eventReturns:
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 is
KEYCODE_OPEN
.Parameters:
event
- the received eventReturns:
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 uses
isOpenEvent
.Parameters:
event
- the received eventReturns:
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 is
KEYCODE_MOVE_VERTICAL
, moves the editor one row up or down if the shift key is pressed or not, respectively. Keydown event with keycodeKEYCODE_MOVE_HORIZONTAL
moves the editor left or right if shift key is pressed or not, respectively.Parameters:
event
- the received eventReturns:
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
startingWith
itself. 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 investigateReturns:
true
if the field is editable,false
otherwise
-
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
startingWith
itself. 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 keycode
KEYCODE_MOVE_HORIZONTAL
. This moves the editor left or right if shift key is pressed or not, respectively.Parameters:
event
- the received eventReturns:
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 is
KEYCODE_CLOSE
.Parameters:
event
- the received eventReturns:
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 uses
isCloseEvent
.Parameters:
event
- the received eventReturns:
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.EventHandler
Handles editor-related events in an appropriate way. Opens, moves, or closes the editor based on the given event.
Specified by:
handleEvent
in interfaceGrid.Editor.EventHandler<T>
Parameters:
event
- the received eventReturns:
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.EventHandler
Confirms the valid status of the binder so as to determine whether to allow pending navigation action.
Specified by:
confirmValidity
in interfaceGrid.Editor.EventHandler<T>
Parameters:
isValid
-true
if the binder value is valid
-
-