Class GridUtils

java.lang.Object
com.vaadin.browserless.component.GridUtils

public final class GridUtils extends Object
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 Type
    Method
    Description
    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.
    static <T> void
    _deselect(Grid<T> grid, T item)
    Simulates 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 an ItemDoubleClickEvent.
    static <T> T
    _get(Grid<T> grid, int rowIndex)
    Returns the item on given row of given grid.
    static <T> void
    _select(Grid<T> grid, T item)
    Simulates 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 int
    _size(Grid<?> grid)
    Returns the number of items in given grid.
    static DataProvider<?,?>
    Returns the data provider currently set to given component, or null if the component has no data provider.
    static String
    Returns the internal id of given column, which the client uses to refer to the column.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • _get

      public static <T> T _get(Grid<T> grid, int rowIndex)
      Returns the item on given row of given grid. Fails if the row index is invalid. The data provider is sorted according to given Grid.getSortOrder() and filtered according to the current filter.

      For TreeGrid this returns the x-th displayed row; skips children of collapsed nodes.

      Type Parameters:
      T - the item type
      Parameters:
      grid - the grid to read
      rowIndex - the row, 0..size - 1
      Returns:
      the item at given row.
      Throws:
      AssertionError - if the row index is out of bounds.
    • _size

      public static int _size(Grid<?> grid)
      Returns the number of items in given grid. For TreeGrid this 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 an ItemClickEvent.
      Type Parameters:
      T - the item type
      Parameters:
      grid - the grid to click
      rowIndex - the row index, 0 or higher.
      button - the id of the pressed mouse button
      ctrlKey - whether the control key was pressed
      shiftKey - whether the shift key was pressed
      altKey - whether the alt key was pressed
      metaKey - 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 an ItemDoubleClickEvent.
      Type Parameters:
      T - the item type
      Parameters:
      grid - the grid to click
      rowIndex - the row index, 0 or higher.
      button - the id of the pressed mouse button
      ctrlKey - whether the control key was pressed
      shiftKey - whether the shift key was pressed
      altKey - whether the alt key was pressed
      metaKey - whether the meta key was pressed
      Throws:
      IllegalStateException - if the grid was not editable.
    • getDataProvider

      public static DataProvider<?,?> getDataProvider(Component component)
      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

      public static <T> void _select(Grid<T> grid, T item)
      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 in
      item - the item to select
      Throws:
      IllegalStateException - if the grid was not editable.
    • _selectAll

      public static <T> void _selectAll(Grid<T> grid)
      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

      public static <T> void _deselect(Grid<T> grid, T item)
      Simulates a user deselecting given item in given grid.
      Type Parameters:
      T - the item type
      Parameters:
      grid - the grid to deselect in
      item - the item to deselect
      Throws:
      IllegalStateException - if the grid was not editable or the item is not selected.
    • _deselectAll

      public static <T> void _deselectAll(Grid<T> grid)
      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

      public static String getInternalId(Grid.Column<?> column)
      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