Package com.vaadin.browserless.component
Class GridUtils
java.lang.Object
com.vaadin.browserless.component.GridUtils
Helpers the Grid testers use to read and drive a
Grid the way a user
would.
A grid renders its rows on the client, so the rows a test wants to assert on
do not exist as server-side objects until something asks the data provider
for them. _get(Grid, int) and _size(Grid) do that asking,
and the click and selection helpers fire the events a click or a checkbox
would.
For internal use only. May be renamed or removed in a future release; use
GridTester and TreeGridTester instead.
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> void_clickItem(Grid<T> grid, int rowIndex, int button, boolean ctrlKey, boolean shiftKey, boolean altKey, boolean metaKey) Simulates a user clicking on given row of given grid.static <T> voidSimulates a user deselecting given item in given grid.static <T> void_deselectAll(Grid<T> grid) Simulates a user unchecking the select all checkbox of given grid.static <T> void_doubleClickItem(Grid<T> grid, int rowIndex, int button, boolean ctrlKey, boolean shiftKey, boolean altKey, boolean metaKey) Simulates a user double-clicking on given row of given grid by firing anItemDoubleClickEvent.static <T> TReturns the item on given row of given grid.static <T> voidSimulates a user selecting given item in given grid.static <T> void_selectAll(Grid<T> grid) Simulates a user clicking the select all checkbox of given grid.static intReturns the number of items in given grid.static DataProvider<?, ?> getDataProvider(Component component) Returns the data provider currently set to given component, or null if the component has no data provider.static StringgetInternalId(Grid.Column<?> column) Returns the internal id of given column, which the client uses to refer to the column.
-
Method Details
-
_get
Returns the item on given row of given grid. Fails if the row index is invalid. The data provider is sorted according to givenGrid.getSortOrder()and filtered according to the current filter.For
TreeGridthis returns the x-th displayed row; skips children of collapsed nodes.- Type Parameters:
T- the item type- Parameters:
grid- the grid to readrowIndex- the row, 0..size - 1- Returns:
- the item at given row.
- Throws:
AssertionError- if the row index is out of bounds.
-
_size
Returns the number of items in given grid. ForTreeGridthis returns the number of displayed rows; children of collapsed nodes are not counted.- Parameters:
grid- the grid to read- Returns:
- the number of rows
-
_clickItem
public static <T> void _clickItem(Grid<T> grid, int rowIndex, int button, boolean ctrlKey, boolean shiftKey, boolean altKey, boolean metaKey) Simulates a user clicking on given row of given grid. Selects the item in single selection mode (or deselects it when it is already selected), then fires anItemClickEvent.- Type Parameters:
T- the item type- Parameters:
grid- the grid to clickrowIndex- the row index, 0 or higher.button- the id of the pressed mouse buttonctrlKey- whether the control key was pressedshiftKey- whether the shift key was pressedaltKey- whether the alt key was pressedmetaKey- whether the meta key was pressed- Throws:
IllegalStateException- if the grid was not editable.
-
_doubleClickItem
public static <T> void _doubleClickItem(Grid<T> grid, int rowIndex, int button, boolean ctrlKey, boolean shiftKey, boolean altKey, boolean metaKey) Simulates a user double-clicking on given row of given grid by firing anItemDoubleClickEvent.- Type Parameters:
T- the item type- Parameters:
grid- the grid to clickrowIndex- the row index, 0 or higher.button- the id of the pressed mouse buttonctrlKey- whether the control key was pressedshiftKey- whether the shift key was pressedaltKey- whether the alt key was pressedmetaKey- whether the meta key was pressed- Throws:
IllegalStateException- if the grid was not editable.
-
getDataProvider
Returns the data provider currently set to given component, or null if the component has no data provider.- Parameters:
component- the component to read- Returns:
- the data provider, or null
-
_select
Simulates a user selecting given item in given grid. In single selection mode the previously selected item is deselected first.- Type Parameters:
T- the item type- Parameters:
grid- the grid to select initem- the item to select- Throws:
IllegalStateException- if the grid was not editable.
-
_selectAll
Simulates a user clicking the select all checkbox of given grid.- Type Parameters:
T- the item type- Parameters:
grid- the grid to select in- Throws:
IllegalStateException- if the grid was not editable, is not in multi selection mode or the select all checkbox is not visible.
-
_deselect
Simulates a user deselecting given item in given grid.- Type Parameters:
T- the item type- Parameters:
grid- the grid to deselect initem- the item to deselect- Throws:
IllegalStateException- if the grid was not editable or the item is not selected.
-
_deselectAll
Simulates a user unchecking the select all checkbox of given grid.- Type Parameters:
T- the item type- Parameters:
grid- the grid to deselect in- Throws:
IllegalStateException- if the grid was not editable, is not in multi selection mode or the select all checkbox is not visible.
-
getInternalId
Returns the internal id of given column, which the client uses to refer to the column.- Parameters:
column- the column to read- Returns:
- the column's internal id
-