Class ItemGrid<T>
java.lang.Object
com.vaadin.flow.component.Component
com.vaadin.flow.component.AbstractField<com.vaadin.flow.component.customfield.CustomField<T>,T>
com.vaadin.flow.component.customfield.CustomField<T>
org.vaadin.miki.superfields.itemgrid.ItemGrid<T>
- Type Parameters:
T- Type of item stored in the grid.
- All Implemented Interfaces:
com.vaadin.flow.component.AttachNotifier,com.vaadin.flow.component.BlurNotifier<com.vaadin.flow.component.customfield.CustomField<T>>,com.vaadin.flow.component.DetachNotifier,com.vaadin.flow.component.Focusable<com.vaadin.flow.component.customfield.CustomField<T>>,com.vaadin.flow.component.FocusNotifier<com.vaadin.flow.component.customfield.CustomField<T>>,com.vaadin.flow.component.HasElement,com.vaadin.flow.component.HasEnabled,com.vaadin.flow.component.HasHelper,com.vaadin.flow.component.HasLabel,com.vaadin.flow.component.HasSize,com.vaadin.flow.component.HasStyle,com.vaadin.flow.component.HasTheme,com.vaadin.flow.component.HasValidation,com.vaadin.flow.component.HasValue<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<com.vaadin.flow.component.customfield.CustomField<T>,,T>, T> com.vaadin.flow.component.HasValueAndElement<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<com.vaadin.flow.component.customfield.CustomField<T>,,T>, T> com.vaadin.flow.component.shared.HasTooltip,com.vaadin.flow.component.shared.HasValidationProperties,com.vaadin.flow.data.binder.HasItems<T>,Serializable,HasHelperPositionable,HasId,WithHelperMixin<ItemGrid<T>>,WithHelperPositionableMixin<ItemGrid<T>>,WithIdMixin<ItemGrid<T>>,WithItemsMixin<T,,ItemGrid<T>> WithValueMixin<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<com.vaadin.flow.component.customfield.CustomField<T>,T>, T, ItemGrid<T>>
@Tag("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>>
Grid of items, with defined number of columns.
Each cell in the grid corresponds to a single element from the underlying collection of data.
Note: currently this is not lazy-loading the data and not reacting to changes in the underlying data set.
- Since:
- 2020-04-14
- Author:
- miki
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class com.vaadin.flow.component.AbstractField
com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<C extends com.vaadin.flow.component.Component,V extends Object> Nested classes/interfaces inherited from interface com.vaadin.flow.component.BlurNotifier
com.vaadin.flow.component.BlurNotifier.BlurEvent<C extends com.vaadin.flow.component.Component>Nested classes/interfaces inherited from interface com.vaadin.flow.component.FocusNotifier
com.vaadin.flow.component.FocusNotifier.FocusEvent<C extends com.vaadin.flow.component.Component>Nested classes/interfaces inherited from interface com.vaadin.flow.component.HasValue
com.vaadin.flow.component.HasValue.ValueChangeEvent<V extends Object>, com.vaadin.flow.component.HasValue.ValueChangeListener<E extends com.vaadin.flow.component.HasValue.ValueChangeEvent<?>> -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intDefault number of columns.static final StringStyle that by default indicates a selected item.Fields inherited from interface org.vaadin.miki.markers.HasHelperPositionable
HELPER_ABOVE_THEME_VARIANT -
Constructor Summary
ConstructorsConstructorDescriptionItemGrid(CellGenerator<T> generator, CellSelectionHandler<T> handler, T... items) Creates the component with givenCellGenerator,CellSelectionHandlerand items.ItemGrid(CellGenerator<T> generator, T... items) Creates the component with given items andCellGenerator, but with defaultCellSelectionHandler.Creates the component with given items, using defaultCellGeneratorandCellSelectionHandler.ItemGrid(T defaultValue, Supplier<C> mainContainerSupplier, CellGenerator<T> generator, CellSelectionHandler<T> handler, T... items) Creates the component with givenCellGenerator,CellSelectionHandlerand items, overriding default (empty) value.ItemGrid(T defaultValue, CellGenerator<T> generator, CellSelectionHandler<T> handler, T... items) Creates the component with givenCellGenerator,CellSelectionHandlerand items, overriding default (empty) value. -
Method Summary
Modifier and TypeMethodDescriptionbooleanChecks whether the padding cells (if any present) are clickable.protected final CellInformation<T>buildPaddingCell(int row, int column) protected final CellInformation<T>buildValueCell(T item, int row, int column) protected voidclickCell(CellInformation<T> information) Reacts to cell being clicked in the browser.static <V> com.vaadin.flow.component.ComponentdefaultCellGenerator(V item, int row, int col) DefaultCellGenerator.static <V> voidDefaultCellSelectionHandler.static com.vaadin.flow.component.html.DivDefault supplier for the main layout of the grid.static com.vaadin.flow.component.html.DivdefaultRowComponentGenerator(int rowNumber) DefaultRowComponentGenerator.protected TStream<com.vaadin.flow.component.Component>Returns aStreamof allComponents in the cells.Returns currentCellGeneratorused to generate cells.Returns a list with information about each cell.getCellInformation(int row, int column) ReturnsCellInformationthat corresponds to the cell of given coordinates.getCellInformation(T value) ReturnsCellInformationthat corresponds to the provided value.Returns currentCellSelectionHandlerused to react to selection changes.getColumnCellInformation(int column) Returns a list withCellInformationfor each cell in given column.intReturns the current number of columns.Returns the cell generator used for constructing padding cells.getRowCellInformation(int row) Returns a list withCellInformationfor each cell in given row.Returns currentRowComponentGenerator.longReturns the number of rows (even incomplete) currently in the grid.Returns currentRowPaddingStrategy.ReturnsCellInformationabout currently selected cell.protected voidregisterClickEvents(CellInformation<T> information) Adds a click listener to the dom element of theComponentinside givenCellInformation.protected final voidRepaints all current items.protected voidrepaintAllItems(Collection<T> itemCollection) Repaints all items in the collection.voidsetCellGenerator(CellGenerator<T> cellGenerator) Sets newCellGenerator.voidsetCellSelectionHandler(CellSelectionHandler<T> cellSelectionHandler) Sets newCellSelectionHandler.voidsetColumnCount(int columnCount) Sets the new number of columns.voidsetItems(Collection<T> collection) voidsetPaddingCellGenerator(CellGenerator<T> paddingCellGenerator) Sets cell generator for padding cells.voidsetPaddingCellsClickable(boolean paddingCellsClickable) Enables or disables click events on padding cells.protected voidvoidsetRowComponentGenerator(RowComponentGenerator<?> rowComponentGenerator) Sets newRowComponentGeneratorinvoked every time a new row for grid cells is needed.voidsetRowPaddingStrategy(RowPaddingStrategy rowPaddingStrategy) Sets newRowPaddingStrategy.intsize()Returns the number of cells.withCellGenerator(CellGenerator<T> generator) ChainssetCellGenerator(CellGenerator)and returns itself.withCellSelectionHandler(CellSelectionHandler<T> handler) ChainssetCellSelectionHandler(CellSelectionHandler)and returns itself.withColumnCount(int columnCount) ChainssetColumnCount(int)and returns itself.withPaddingCellGenerator(CellGenerator<T> paddingCellGenerator) ChainssetPaddingCellGenerator(CellGenerator)and returns itself.withPaddingCellsClickable(boolean paddingCellsClickable) ChainssetPaddingCellsClickable(boolean)and returns itself.withRowComponentGenerator(RowComponentGenerator<?> generator) ChainssetRowComponentGenerator(RowComponentGenerator)and returns itself.withRowPaddingStrategy(RowPaddingStrategy rowPaddingStrategy) ChainssetRowPaddingStrategy(RowPaddingStrategy)and returns itself.Methods inherited from class com.vaadin.flow.component.customfield.CustomField
add, addThemeVariants, getLabel, onAttach, remove, removeThemeVariants, setLabel, updateValueMethods inherited from class com.vaadin.flow.component.AbstractField
addValueChangeListener, getEmptyValue, getValue, isEmpty, setModelValue, setValue, valueEqualsMethods inherited from class com.vaadin.flow.component.Component
addListener, findAncestor, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getListeners, getLocale, getParent, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onDetach, onEnabledStateChanged, removeFromParent, scrollIntoView, scrollIntoView, set, setElement, setId, setVisibleMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.vaadin.flow.component.AttachNotifier
addAttachListenerMethods inherited from interface com.vaadin.flow.component.BlurNotifier
addBlurListenerMethods inherited from interface com.vaadin.flow.component.DetachNotifier
addDetachListenerMethods inherited from interface com.vaadin.flow.component.Focusable
addFocusShortcut, blur, focus, getTabIndex, setTabIndexMethods inherited from interface com.vaadin.flow.component.FocusNotifier
addFocusListenerMethods inherited from interface com.vaadin.flow.component.HasElement
getElementMethods inherited from interface com.vaadin.flow.component.HasEnabled
isEnabled, setEnabledMethods inherited from interface com.vaadin.flow.component.HasHelper
getHelperComponent, getHelperText, setHelperComponent, setHelperTextMethods inherited from interface org.vaadin.miki.markers.HasHelperPositionable
isHelperAbove, setHelperAbove, setHelperAbove, setHelperBelowMethods inherited from interface com.vaadin.flow.data.binder.HasItems
setItems, setItemsMethods inherited from interface com.vaadin.flow.component.HasSize
getHeight, getHeightUnit, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getWidth, getWidthUnit, setHeight, setHeight, setHeightFull, setMaxHeight, setMaxHeight, setMaxWidth, setMaxWidth, setMinHeight, setMinHeight, setMinWidth, setMinWidth, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthFullMethods inherited from interface com.vaadin.flow.component.HasStyle
addClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassNameMethods inherited from interface com.vaadin.flow.component.HasTheme
addThemeName, addThemeNames, getThemeName, getThemeNames, hasThemeName, removeThemeName, removeThemeNames, setThemeName, setThemeNameMethods inherited from interface com.vaadin.flow.component.shared.HasTooltip
getTooltip, setTooltipTextMethods inherited from interface com.vaadin.flow.component.shared.HasValidationProperties
getErrorMessage, isInvalid, setErrorMessage, setInvalidMethods inherited from interface com.vaadin.flow.component.HasValue
addValueChangeListener, clear, getEmptyValue, getOptionalValue, getValue, isEmpty, setValueMethods inherited from interface com.vaadin.flow.component.HasValueAndElement
isReadOnly, isRequiredIndicatorVisible, setReadOnly, setRequiredIndicatorVisibleMethods inherited from interface org.vaadin.miki.markers.WithHelperMixin
withHelperComponent, withHelperTextMethods inherited from interface org.vaadin.miki.markers.WithHelperPositionableMixin
withHelperAbove, withHelperAbove, withHelperBelowMethods inherited from interface org.vaadin.miki.markers.WithIdMixin
withIdMethods inherited from interface org.vaadin.miki.markers.WithItemsMixin
withItems, withItems, withItemsMethods inherited from interface org.vaadin.miki.markers.WithValueMixin
withValue
-
Field Details
-
DEFAULT_COLUMN_COUNT
public static final int DEFAULT_COLUMN_COUNTDefault number of columns.- See Also:
-
DEFAULT_SELECTED_ITEM_CLASS_NAME
Style that by default indicates a selected item. This is only needed when defaultsetCellSelectionHandler(CellSelectionHandler)is used.- See Also:
-
-
Constructor Details
-
ItemGrid
Creates the component with given items, using defaultCellGeneratorandCellSelectionHandler.- Parameters:
items- Items to add to the component.
-
ItemGrid
Creates the component with given items andCellGenerator, but with defaultCellSelectionHandler.- Parameters:
generator-CellGeneratorto use.items- Items to add to the component.
-
ItemGrid
@SafeVarargs public ItemGrid(CellGenerator<T> generator, CellSelectionHandler<T> handler, T... items) Creates the component with givenCellGenerator,CellSelectionHandlerand items.- Parameters:
generator-CellGeneratorto use.handler-CellSelectionHandlerto use.items- Items to add to the component.
-
ItemGrid
@SafeVarargs public ItemGrid(T defaultValue, CellGenerator<T> generator, CellSelectionHandler<T> handler, T... items) Creates the component with givenCellGenerator,CellSelectionHandlerand items, overriding default (empty) value.- Parameters:
defaultValue- Default (empty) value.generator-CellGeneratorto use.handler-CellSelectionHandlerto use.items- Items to add to the component.
-
ItemGrid
@SafeVarargs public ItemGrid(T defaultValue, Supplier<C> mainContainerSupplier, CellGenerator<T> generator, CellSelectionHandler<T> handler, T... items) Creates the component with givenCellGenerator,CellSelectionHandlerand items, overriding default (empty) value.- Type Parameters:
C- Type parameter to ensuremainContainerSupplierprovides aComponentthat alsoHasComponents.- Parameters:
defaultValue- Default (empty) value.mainContainerSupplier- Method to generate main container component.generator-CellGeneratorto use.handler-CellSelectionHandlerto use.items- Items to add to the component.
-
-
Method Details
-
defaultCellSelectionHandler
DefaultCellSelectionHandler. It adds or removesDEFAULT_SELECTED_ITEM_CLASS_NAMEto the element of the component.- Type Parameters:
V- Value type.- Parameters:
event- Event.
-
defaultMainContainerSupplier
public static com.vaadin.flow.component.html.Div defaultMainContainerSupplier()Default supplier for the main layout of the grid.- Returns:
- A
Div.
-
defaultCellGenerator
public static <V> com.vaadin.flow.component.Component defaultCellGenerator(V item, int row, int col) - Type Parameters:
V- Item type.- Parameters:
item- Item to generate component for.row- Row in the grid.col- Column in the grid.- Returns:
- A
Span:<span>item</span>.
-
defaultRowComponentGenerator
public static com.vaadin.flow.component.html.Div defaultRowComponentGenerator(int rowNumber) DefaultRowComponentGenerator. It produces aDiv.- Parameters:
rowNumber- Number of the row to create.- Returns:
- A
Div.
-
repaintAllItems
protected final void repaintAllItems()Repaints all current items. -
buildPaddingCell
-
buildValueCell
-
repaintAllItems
Repaints all items in the collection.- Parameters:
itemCollection- Collection with items to repaint.
-
registerClickEvents
Adds a click listener to the dom element of theComponentinside givenCellInformation. This click listener will select or deselect a cell and update the value of this grid. Note: when overriding this method, please remember to callsuper.- Parameters:
information- Information. Nevernull.
-
clickCell
Reacts to cell being clicked in the browser. This method is invoked for padding cells ifarePaddingCellsClickable()istrue.- Parameters:
information- Information about the clicked cell.
-
generateModelValue
- Specified by:
generateModelValuein classcom.vaadin.flow.component.customfield.CustomField<T>
-
setPresentationValue
- Specified by:
setPresentationValuein classcom.vaadin.flow.component.customfield.CustomField<T>
-
setCellGenerator
Sets newCellGenerator. Repaints all items.- Parameters:
cellGenerator- Cell generator. Ifnullis passed,defaultCellGenerator(Object, int, int)will be used.
-
getCellGenerator
Returns currentCellGeneratorused to generate cells.- Returns:
- A
CellGenerator. Nevernull.
-
withCellGenerator
ChainssetCellGenerator(CellGenerator)and returns itself.- Parameters:
generator-CellGeneratorto use.- Returns:
- This.
- See Also:
-
setCellSelectionHandler
Sets newCellSelectionHandler. Repaints all items.- Parameters:
cellSelectionHandler- Cell selection handler. Ifnullis passed,defaultCellSelectionHandler(CellSelectionEvent)will be used.
-
getCellSelectionHandler
Returns currentCellSelectionHandlerused to react to selection changes.- Returns:
- A
CellSelectionHandler. Nevernull.
-
withCellSelectionHandler
ChainssetCellSelectionHandler(CellSelectionHandler)and returns itself.- Parameters:
handler-CellSelectionHandlerto use.- Returns:
- This.
- See Also:
-
getRowCount
public long getRowCount()Returns the number of rows (even incomplete) currently in the grid.- Returns:
- The number of rows. This will change if new items are added or the number of columns changes.
- See Also:
-
setItems(Collection)HasItems.setItems(Object[])HasItems.setItems(Stream)setColumnCount(int)
-
getColumnCount
public int getColumnCount()Returns the current number of columns.- Returns:
- The number of columns in the grid.
-
setColumnCount
public void setColumnCount(int columnCount) Sets the new number of columns. Repaints all items.- Parameters:
columnCount- Number of columns. Values less than1are replaced with1instead,
-
withColumnCount
ChainssetColumnCount(int)and returns itself.- Parameters:
columnCount- Number of columns.- Returns:
- This.
- See Also:
-
setItems
- Specified by:
setItemsin interfacecom.vaadin.flow.data.binder.HasItems<T>
-
size
public int size()Returns the number of cells.- Returns:
- Number of cells.
-
getCellInformation
Returns a list with information about each cell.- Returns:
- A list with
CellInformation. Nevernull. Changes to the resulting object do not affect the grid.
-
getSelectedCellInformation
ReturnsCellInformationabout currently selected cell.- Returns:
- A
CellInformation, if any cell is currently selected.
-
getCellInformation
ReturnsCellInformationthat corresponds to the provided value.- Parameters:
value- A value to look for.- Returns:
- A
CellInformation, if a cell corresponding to the provided value is available. - See Also:
-
HasItems.setItems(Object[])setItems(Collection)HasItems.setItems(Stream)
-
getCellInformation
ReturnsCellInformationthat corresponds to the cell of given coordinates.- Parameters:
row- Row number (0-based).column- Column number (0-based).- Returns:
- A
CellInformation, if a cell corresponding to the given coordinates is available. - See Also:
-
getRowCellInformation
Returns a list withCellInformationfor each cell in given row.- Parameters:
row- Row number, 0-based.- Returns:
- An unmodifiable list. May be empty.
-
getColumnCellInformation
Returns a list withCellInformationfor each cell in given column.- Parameters:
column- Column number, 0-based.- Returns:
- An unmodifiable list. May be empty.
-
getCellComponents
Returns aStreamof allComponents in the cells.- Returns:
- A
Stream. Nevernull. - See Also:
-
setRowComponentGenerator
Sets newRowComponentGeneratorinvoked every time a new row for grid cells is needed.- Parameters:
rowComponentGenerator-RowComponentGeneratorto use. Ifnullis passed, thendefaultRowComponentGenerator(int)will be used.
-
getRowComponentGenerator
Returns currentRowComponentGenerator.- Returns:
- A
RowComponentGenerator. Nevernull.
-
withRowComponentGenerator
ChainssetRowComponentGenerator(RowComponentGenerator)and returns itself.- Parameters:
generator- ARowComponentGeneratorto use.- Returns:
- This.
- See Also:
-
setRowPaddingStrategy
Sets newRowPaddingStrategy. Repaints all items.- Parameters:
rowPaddingStrategy- An implementation ofRowPaddingStrategy. Ifnullis passed,RowPaddingStrategies.NO_PADDINGwill be used.- See Also:
-
getRowPaddingStrategy
Returns currentRowPaddingStrategy.- Returns:
- A
RowPaddingStrategycurrently assigned to this object. Defaults toRowPaddingStrategies.NO_PADDING. - See Also:
-
withRowPaddingStrategy
ChainssetRowPaddingStrategy(RowPaddingStrategy)and returns itself.- Parameters:
rowPaddingStrategy- ARowPaddingStrategyto use.- Returns:
- This.
- See Also:
-
getPaddingCellGenerator
Returns the cell generator used for constructing padding cells. If none present,getCellGenerator()will be used.- Returns:
- A generator for padding cells. Is used only when there is some
RowPaddingStrategyset. - See Also:
-
setPaddingCellGenerator
Sets cell generator for padding cells. Ifnullis passed,getCellGenerator()will be used.- Parameters:
paddingCellGenerator- A generator for padding cells. Is used only when there is someRowPaddingStrategyset.- See Also:
-
withPaddingCellGenerator
ChainssetPaddingCellGenerator(CellGenerator)and returns itself.- Parameters:
paddingCellGenerator- A generator for padding cells.- Returns:
- This.
- See Also:
-
arePaddingCellsClickable
public boolean arePaddingCellsClickable()Checks whether the padding cells (if any present) are clickable.- Returns:
- Whether or not padding cells can be clicked. Defaults to
false.
-
setPaddingCellsClickable
public void setPaddingCellsClickable(boolean paddingCellsClickable) Enables or disables click events on padding cells. Iftrue, clicking a padding cell turns value tonull.- Parameters:
paddingCellsClickable- Whether or not to allow padding cells to react to clicks.
-
withPaddingCellsClickable
ChainssetPaddingCellsClickable(boolean)and returns itself.- Parameters:
paddingCellsClickable- Whether or not to allow padding cells to react to clicks.- Returns:
- This.
- See Also:
-