T - Type of item stored in the grid.@Tag(value="item-grid") public class ItemGrid<T> extends com.vaadin.flow.component.customfield.CustomField<T> implements com.vaadin.flow.data.binder.HasItems<T>, com.vaadin.flow.component.HasStyle, WithItemsMixin<T,ItemGrid<T>>, WithIdMixin<ItemGrid<T>>, WithHelperMixin<ItemGrid<T>>, WithHelperPositionableMixin<ItemGrid<T>>, WithValueMixin<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<com.vaadin.flow.component.customfield.CustomField<T>,T>,T,ItemGrid<T>>
com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<C extends com.vaadin.flow.component.Component,V>com.vaadin.flow.component.HasValue.ValueChangeEvent<V>, com.vaadin.flow.component.HasValue.ValueChangeListener<E extends com.vaadin.flow.component.HasValue.ValueChangeEvent<?>>| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_COLUMN_COUNT
Default number of columns.
|
static String |
DEFAULT_SELECTED_ITEM_CLASS_NAME
Style that by default indicates a selected item.
|
HELPER_ABOVE_THEME_VARIANT| Constructor and Description |
|---|
ItemGrid(CellGenerator<T> generator,
CellSelectionHandler<T> handler,
T... items)
Creates the component with given
CellGenerator, CellSelectionHandler and items. |
ItemGrid(CellGenerator<T> generator,
T... items)
Creates the component with given items and
CellGenerator, but with default CellSelectionHandler. |
ItemGrid(T... items)
Creates the component with given items, using default
CellGenerator and CellSelectionHandler. |
ItemGrid(T defaultValue,
CellGenerator<T> generator,
CellSelectionHandler<T> handler,
T... items)
Creates the component with given
CellGenerator, CellSelectionHandler and items, overriding default (empty) value. |
ItemGrid(T defaultValue,
Supplier<C> mainContainerSupplier,
CellGenerator<T> generator,
CellSelectionHandler<T> handler,
T... items)
Creates the component with given
CellGenerator, CellSelectionHandler and items, overriding default (empty) value. |
| Modifier and Type | Method and Description |
|---|---|
boolean |
arePaddingCellsClickable()
Checks whether the padding cells (if any present) are clickable.
|
protected CellInformation<T> |
buildPaddingCell(int row,
int column) |
protected CellInformation<T> |
buildValueCell(T item,
int row,
int column) |
protected void |
clickCell(CellInformation<T> information)
Reacts to cell being clicked in the browser.
|
static <V> com.vaadin.flow.component.Component |
defaultCellGenerator(V item,
int row,
int col)
Default
CellGenerator. |
static <V> void |
defaultCellSelectionHandler(CellSelectionEvent<V> event)
Default
CellSelectionHandler. |
static com.vaadin.flow.component.html.Div |
defaultMainContainerSupplier()
Default supplier for the main layout of the grid.
|
static com.vaadin.flow.component.html.Div |
defaultRowComponentGenerator(int rowNumber)
Default
RowComponentGenerator. |
protected T |
generateModelValue() |
Stream<com.vaadin.flow.component.Component> |
getCellComponents()
Returns a
Stream of all Components in the cells. |
CellGenerator<T> |
getCellGenerator()
Returns current
CellGenerator used to generate cells. |
List<CellInformation<T>> |
getCellInformation()
Returns a list with information about each cell.
|
Optional<CellInformation<T>> |
getCellInformation(int row,
int column)
Returns
CellInformation that corresponds to the cell of given coordinates. |
Optional<CellInformation<T>> |
getCellInformation(T value)
Returns
CellInformation that corresponds to the provided value. |
CellSelectionHandler<T> |
getCellSelectionHandler()
Returns current
CellSelectionHandler used to react to selection changes. |
List<CellInformation<T>> |
getColumnCellInformation(int column)
Returns a list with
CellInformation for each cell in given column. |
int |
getColumnCount()
Returns the current number of columns.
|
CellGenerator<T> |
getPaddingCellGenerator()
Returns the cell generator used for constructing padding cells.
|
List<CellInformation<T>> |
getRowCellInformation(int row)
Returns a list with
CellInformation for each cell in given row. |
RowComponentGenerator<?> |
getRowComponentGenerator()
Returns current
RowComponentGenerator. |
long |
getRowCount()
Returns the number of rows (even incomplete) currently in the grid.
|
RowPaddingStrategy |
getRowPaddingStrategy()
Returns current
RowPaddingStrategy. |
Optional<CellInformation<T>> |
getSelectedCellInformation()
Returns
CellInformation about currently selected cell. |
protected void |
registerClickEvents(CellInformation<T> information)
Adds a click listener to the dom element of the
Component inside given CellInformation. |
protected void |
repaintAllItems()
Repaints all current items.
|
protected void |
repaintAllItems(Collection<T> itemCollection)
Repaints all items in the collection.
|
void |
setCellGenerator(CellGenerator<T> cellGenerator)
Sets new
CellGenerator. |
void |
setCellSelectionHandler(CellSelectionHandler<T> cellSelectionHandler)
Sets new
CellSelectionHandler. |
void |
setColumnCount(int columnCount)
Sets the new number of columns.
|
void |
setItems(Collection<T> collection) |
void |
setPaddingCellGenerator(CellGenerator<T> paddingCellGenerator)
Sets cell generator for padding cells.
|
void |
setPaddingCellsClickable(boolean paddingCellsClickable)
Enables or disables click events on padding cells.
|
protected void |
setPresentationValue(T t) |
void |
setRowComponentGenerator(RowComponentGenerator<?> rowComponentGenerator)
Sets new
RowComponentGenerator invoked every time a new row for grid cells is needed. |
void |
setRowPaddingStrategy(RowPaddingStrategy rowPaddingStrategy)
Sets new
RowPaddingStrategy. |
int |
size()
Returns the number of cells.
|
ItemGrid<T> |
withCellGenerator(CellGenerator<T> generator)
Chains
setCellGenerator(CellGenerator) and returns itself. |
ItemGrid<T> |
withCellSelectionHandler(CellSelectionHandler<T> handler)
Chains
setCellSelectionHandler(CellSelectionHandler) and returns itself. |
ItemGrid<T> |
withColumnCount(int columnCount)
Chains
setColumnCount(int) and returns itself. |
ItemGrid<T> |
withPaddingCellGenerator(CellGenerator<T> paddingCellGenerator)
Chains
setPaddingCellGenerator(CellGenerator) and returns itself. |
ItemGrid<T> |
withPaddingCellsClickable(boolean paddingCellsClickable)
Chains
setPaddingCellsClickable(boolean) and returns itself. |
ItemGrid<T> |
withRowComponentGenerator(RowComponentGenerator<?> generator)
Chains
setRowComponentGenerator(RowComponentGenerator) and returns itself. |
ItemGrid<T> |
withRowPaddingStrategy(RowPaddingStrategy rowPaddingStrategy)
Chains
setRowPaddingStrategy(RowPaddingStrategy) and returns itself. |
add, getErrorMessage, getLabel, isInvalid, remove, setErrorMessage, setInvalid, setLabel, updateValueaddValueChangeListener, getEmptyValue, getValue, isEmpty, setModelValue, setValue, valueEqualsaddListener, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getLocale, getParent, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onAttach, onDetach, onEnabledStateChanged, set, setElement, setId, setVisibleclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitaddClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassNamewithItems, withItems, withItemswithIdwithHelperComponent, withHelperTextgetHelperComponent, getHelperText, setHelperComponent, setHelperTextwithHelperAbove, withHelperAbove, withHelperBelowisHelperAbove, setHelperAbove, setHelperAbove, setHelperBelowwithValueaddValueChangeListener, clear, getEmptyValue, getOptionalValue, getValue, isEmpty, isReadOnly, isRequiredIndicatorVisible, setReadOnly, setRequiredIndicatorVisible, setValuegetCssSize, getHeight, getHeightUnit, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getWidth, getWidthUnit, setHeight, setHeight, setHeightFull, setMaxHeight, setMaxHeight, setMaxWidth, setMaxWidth, setMinHeight, setMinHeight, setMinWidth, setMinWidth, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthFulladdFocusShortcut, blur, focus, getTabIndex, setTabIndexpublic static final int DEFAULT_COLUMN_COUNT
public static final String DEFAULT_SELECTED_ITEM_CLASS_NAME
setCellSelectionHandler(CellSelectionHandler) is used.@SafeVarargs public ItemGrid(T... items)
CellGenerator and CellSelectionHandler.items - Items to add to the component.@SafeVarargs public ItemGrid(CellGenerator<T> generator, T... items)
CellGenerator, but with default CellSelectionHandler.generator - CellGenerator to use.items - Items to add to the component.@SafeVarargs public ItemGrid(CellGenerator<T> generator, CellSelectionHandler<T> handler, T... items)
CellGenerator, CellSelectionHandler and items.generator - CellGenerator to use.handler - CellSelectionHandler to use.items - Items to add to the component.@SafeVarargs public ItemGrid(T defaultValue, CellGenerator<T> generator, CellSelectionHandler<T> handler, T... items)
CellGenerator, CellSelectionHandler and items, overriding default (empty) value.defaultValue - Default (empty) value.generator - CellGenerator to use.handler - CellSelectionHandler to use.items - Items to add to the component.@SafeVarargs public ItemGrid(T defaultValue, Supplier<C> mainContainerSupplier, CellGenerator<T> generator, CellSelectionHandler<T> handler, T... items)
CellGenerator, CellSelectionHandler and items, overriding default (empty) value.C - Type parameter to ensure mainContainerSupplier provides a Component that also HasComponents.defaultValue - Default (empty) value.mainContainerSupplier - Method to generate main container component.generator - CellGenerator to use.handler - CellSelectionHandler to use.items - Items to add to the component.public static <V> void defaultCellSelectionHandler(CellSelectionEvent<V> event)
CellSelectionHandler. It adds or removes DEFAULT_SELECTED_ITEM_CLASS_NAME to the element of the component.V - Value type.event - Event.public static com.vaadin.flow.component.html.Div defaultMainContainerSupplier()
Div.public static <V> com.vaadin.flow.component.Component defaultCellGenerator(V item,
int row,
int col)
V - Item type.item - Item to generate component for.row - Row in the grid.col - Column in the grid.Span: <span>item</span>.public static com.vaadin.flow.component.html.Div defaultRowComponentGenerator(int rowNumber)
RowComponentGenerator. It produces a Div.rowNumber - Number of the row to create.Div.protected final void repaintAllItems()
protected final CellInformation<T> buildPaddingCell(int row, int column)
protected final CellInformation<T> buildValueCell(T item, int row, int column)
protected void repaintAllItems(Collection<T> itemCollection)
itemCollection - Collection with items to repaint.protected void registerClickEvents(CellInformation<T> information)
Component inside given CellInformation.
This click listener will select or deselect a cell and update the value of this grid.
Note: when overriding this method, please remember to call super.information - Information. Never null.protected void clickCell(CellInformation<T> information)
arePaddingCellsClickable() is true.information - Information about the clicked cell.protected T generateModelValue()
generateModelValue in class com.vaadin.flow.component.customfield.CustomField<T>protected void setPresentationValue(T t)
setPresentationValue in class com.vaadin.flow.component.customfield.CustomField<T>public void setCellGenerator(CellGenerator<T> cellGenerator)
CellGenerator. Repaints all items.cellGenerator - Cell generator. If null is passed, defaultCellGenerator(Object, int, int) will be used.public CellGenerator<T> getCellGenerator()
CellGenerator used to generate cells.CellGenerator. Never null.public ItemGrid<T> withCellGenerator(CellGenerator<T> generator)
setCellGenerator(CellGenerator) and returns itself.generator - CellGenerator to use.setCellGenerator(CellGenerator)public void setCellSelectionHandler(CellSelectionHandler<T> cellSelectionHandler)
CellSelectionHandler. Repaints all items.cellSelectionHandler - Cell selection handler. If null is passed, defaultCellSelectionHandler(CellSelectionEvent) will be used.public CellSelectionHandler<T> getCellSelectionHandler()
CellSelectionHandler used to react to selection changes.CellSelectionHandler. Never null.public ItemGrid<T> withCellSelectionHandler(CellSelectionHandler<T> handler)
setCellSelectionHandler(CellSelectionHandler) and returns itself.handler - CellSelectionHandler to use.setCellSelectionHandler(CellSelectionHandler)public long getRowCount()
setItems(Collection),
HasItems.setItems(Object[]),
HasItems.setItems(Stream),
setColumnCount(int)public int getColumnCount()
public void setColumnCount(int columnCount)
columnCount - Number of columns. Values less than 1 are replaced with 1 instead,public ItemGrid<T> withColumnCount(int columnCount)
setColumnCount(int) and returns itself.columnCount - Number of columns.setColumnCount(int)public void setItems(Collection<T> collection)
setItems in interface com.vaadin.flow.data.binder.HasItems<T>public int size()
public List<CellInformation<T>> getCellInformation()
CellInformation. Never null. Changes to the resulting object do not affect the grid.public Optional<CellInformation<T>> getSelectedCellInformation()
CellInformation about currently selected cell.CellInformation, if any cell is currently selected.public Optional<CellInformation<T>> getCellInformation(T value)
CellInformation that corresponds to the provided value.value - A value to look for.CellInformation, if a cell corresponding to the provided value is available.HasItems.setItems(Object[]),
setItems(Collection),
HasItems.setItems(Stream)public Optional<CellInformation<T>> getCellInformation(int row, int column)
CellInformation that corresponds to the cell of given coordinates.row - Row number (0-based).column - Column number (0-based).CellInformation, if a cell corresponding to the given coordinates is available.setColumnCount(int),
getColumnCount(),
getRowCount()public List<CellInformation<T>> getRowCellInformation(int row)
CellInformation for each cell in given row.row - Row number, 0-based.public List<CellInformation<T>> getColumnCellInformation(int column)
CellInformation for each cell in given column.column - Column number, 0-based.public Stream<com.vaadin.flow.component.Component> getCellComponents()
Stream of all Components in the cells.Stream. Never null.setCellGenerator(CellGenerator)public void setRowComponentGenerator(RowComponentGenerator<?> rowComponentGenerator)
RowComponentGenerator invoked every time a new row for grid cells is needed.rowComponentGenerator - RowComponentGenerator to use. If null is passed, then defaultRowComponentGenerator(int) will be used.public RowComponentGenerator<?> getRowComponentGenerator()
RowComponentGenerator.RowComponentGenerator. Never null.public ItemGrid<T> withRowComponentGenerator(RowComponentGenerator<?> generator)
setRowComponentGenerator(RowComponentGenerator) and returns itself.generator - A RowComponentGenerator to use.setRowComponentGenerator(RowComponentGenerator)public void setRowPaddingStrategy(RowPaddingStrategy rowPaddingStrategy)
RowPaddingStrategy. Repaints all items.rowPaddingStrategy - An implementation of RowPaddingStrategy. If null is passed, RowPaddingStrategies.NO_PADDING will be used.RowPaddingStrategiespublic RowPaddingStrategy getRowPaddingStrategy()
RowPaddingStrategy.RowPaddingStrategy currently assigned to this object. Defaults to RowPaddingStrategies.NO_PADDING.RowPaddingStrategiespublic ItemGrid<T> withRowPaddingStrategy(RowPaddingStrategy rowPaddingStrategy)
setRowPaddingStrategy(RowPaddingStrategy) and returns itself.rowPaddingStrategy - A RowPaddingStrategy to use.setRowPaddingStrategy(RowPaddingStrategy),
RowPaddingStrategiespublic CellGenerator<T> getPaddingCellGenerator()
getCellGenerator() will be used.RowPaddingStrategy set.setRowPaddingStrategy(RowPaddingStrategy)public void setPaddingCellGenerator(CellGenerator<T> paddingCellGenerator)
null is passed, getCellGenerator() will be used.paddingCellGenerator - A generator for padding cells. Is used only when there is some RowPaddingStrategy set.setRowPaddingStrategy(RowPaddingStrategy)public ItemGrid<T> withPaddingCellGenerator(CellGenerator<T> paddingCellGenerator)
setPaddingCellGenerator(CellGenerator) and returns itself.paddingCellGenerator - A generator for padding cells.setPaddingCellGenerator(CellGenerator)public boolean arePaddingCellsClickable()
false.public void setPaddingCellsClickable(boolean paddingCellsClickable)
true, clicking a padding cell turns value to null.paddingCellsClickable - Whether or not to allow padding cells to react to clicks.public ItemGrid<T> withPaddingCellsClickable(boolean paddingCellsClickable)
setPaddingCellsClickable(boolean) and returns itself.paddingCellsClickable - Whether or not to allow padding cells to react to clicks.setPaddingCellsClickable(boolean)Copyright © 2023 Miki. All rights reserved.