Class GridContextMenuSupport

java.lang.Object
com.vaadin.browserless.internal.GridContextMenuSupport

public final class GridContextMenuSupport extends Object
Helpers for driving a GridContextMenu the way the grid's client-side connector does.

For internal use only.

  • Field Details

    • BEFORE_OPEN_EVENT

      public static final String BEFORE_OPEN_EVENT
      DOM event the grid fires on its target element to let the menu know that the user asked for it.
      See Also:
    • TARGET_ITEM_KEY_PROPERTY

      public static final String TARGET_ITEM_KEY_PROPERTY
      Grid element property holding the key of the row the context menu was opened on. Read by GridContextMenuItemClickEvent.getItem() and GridContextMenuOpenedEvent.getItem().
      See Also:
    • TARGET_COLUMN_ID_PROPERTY

      public static final String TARGET_COLUMN_ID_PROPERTY
      Grid element property holding the internal id of the column the context menu was opened on. Read by GridContextMenuOpenedEvent.getColumnId().
      See Also:
  • Method Details

    • getContextMenu

      public static GridContextMenu<?> getContextMenu(Grid<?> grid)
      Gets the context menu added to the given grid.

      A grid keeps no reference to its context menu, and the menu is not part of the component tree until it opens, so the only link from the grid back to the menu is the listener the menu registers on the grid element for "vaadin-context-menu-before-open".

      Parameters:
      grid - the grid whose context menu to get
      Returns:
      the context menu of the grid
      Throws:
      IllegalStateException - if the grid has no context menu, if it has several, or if the menu cannot be resolved
    • setTargetItem

      public static void setTargetItem(Grid<?> grid, String itemKey, String columnInternalId)
      Records the row and column the context menu is about, the way the grid does when the browser reports a context menu gesture.
      Parameters:
      grid - the grid the menu is attached to
      itemKey - key of the row the menu targets, or null for none
      columnInternalId - internal id of the column the menu targets, or null for none
    • getItemKey

      public static <Y> String getItemKey(Grid<Y> grid, Y item)
      Gets the key the grid uses for the given item.
      Type Parameters:
      Y - item type
      Parameters:
      grid - the grid holding the item
      item - the item to get the key for
      Returns:
      the key of the item
    • getColumnInternalId

      public static String getColumnInternalId(Grid<?> grid, String columnKey)
      Gets the internal id the grid uses for the column with the given key.
      Parameters:
      grid - the grid holding the column
      columnKey - the key of the column, as set with Grid.Column.setKey(String)
      Returns:
      the internal id of the column
      Throws:
      IllegalArgumentException - if the grid has no column with the given key
      IllegalStateException - if the column is not visible