Class EasyGridWrapper<T,GRID extends Grid<T>>

java.lang.Object
com.vaadin.flow.component.Component
com.vaadin.flow.component.Composite<GRID>
com.flowingcode.vaadin.addons.easygrid.EasyGridWrapper<T,GRID>
Type Parameters:
T - the grid bean type
GRID - the concrete Grid subtype being wrapped
All Implemented Interfaces:
AttachNotifier, BlurNotifier<Grid<T>>, DetachNotifier, Focusable<Grid<T>>, FocusNotifier<Grid<T>>, HasElement, HasEnabled, HasSize, HasStyle, HasTheme, HasDataGenerators<T>, HasDataView<T,Void,GridDataView<T>>, HasLazyDataView<T,Void,GridLazyDataView<T>>, HasListDataView<T,GridListDataView<T>>, Serializable
Direct Known Subclasses:
EasyGrid

public class EasyGridWrapper<T,GRID extends Grid<T>> extends Composite<GRID>
Wraps a Grid to provide bean property-based column creation and type-aware ColumnConfiguration resolution. Columns can be created automatically from all top-level bean properties, from an explicit list of property names, or individually via addColumn(String) and addColumn(Class, ValueProvider).

EasyGrid is the standard concrete subclass for use with a plain Grid.

See Also:
  • Constructor Details

    • EasyGridWrapper

      public EasyGridWrapper(@NonNull GRID grid, @NonNull @NonNull Class<T> beanType)
      Creates an EasyGridWrapper that discovers all top-level bean properties and adds a column for each.
      Parameters:
      grid - the grid to configure, not null
      beanType - the bean type to use, not null
      Throws:
      NullPointerException - if either grid or beanType is null
    • EasyGridWrapper

      public EasyGridWrapper(@NonNull GRID grid, @NonNull @NonNull Class<T> beanType, boolean autoCreateColumns)
      Creates an EasyGridWrapper for the given bean type, optionally auto-creating columns.
      Parameters:
      grid - the grid to configure, not null
      beanType - the bean type to use, not null
      autoCreateColumns - when true, columns are created automatically for the properties of the bean type
      Throws:
      NullPointerException - if either grid or beanType is null
    • EasyGridWrapper

      public EasyGridWrapper(@NonNull GRID grid, @NonNull @NonNull Class<T> beanType, String... propertyNames)
      Creates an EasyGridWrapper that adds columns for the specified properties in order.
      Parameters:
      grid - the grid to configure, not null
      beanType - the bean type to use, not null
      propertyNames - the names of the properties for which columns are created
      Throws:
      NullPointerException - if either grid or beanType is null, or if propertyNames is null
  • Method Details

    • getColumn

      public EasyColumn<T,?> getColumn(String propertyName)
      Returns the EasyColumn for the given property name, or null if no column with that key exists or the column was not created through the EasyGrid API.
      Parameters:
      propertyName - the property name used as the column key
      Returns:
      the EasyColumn for the given key, or null
    • addColumn

      public EasyColumn<T,?> addColumn(String propertyName)
      Adds a column for the given bean property. The column header is derived from the property name, and the column is made sortable if the property type implements Comparable or is a primitive type.
      Parameters:
      propertyName - the name of the bean property
      Returns:
      the EasyColumn for the added column
      Throws:
      IllegalArgumentException - if the property cannot be resolved or a column for it already exists
    • setColumnOrder

      public void setColumnOrder(@NonNull @NonNull String... propertyNames)
      Sets the order of the columns shown in the grid. Only the listed columns are visible after this call; all other columns are hidden. The columns are shown in the order they are listed.
      Parameters:
      propertyNames - the property names of the columns to show, in the desired order
      Throws:
      NullPointerException - if propertyNames is null
    • hideColumns

      public void hideColumns(@NonNull @NonNull String... propertyNames)
      Hides the columns with the given property names.
      Parameters:
      propertyNames - the property names of the columns to hide
      Throws:
      NullPointerException - if propertyNames is null
    • addColumns

      public void addColumns(@NonNull @NonNull String... propertyNames)
      Adds columns for the given bean properties in order.
      Parameters:
      propertyNames - the names of the bean properties
      Throws:
      NullPointerException - if propertyNames is null
      IllegalArgumentException - if any property cannot be resolved or already has a column
    • addColumn

      public <V> EasyColumn<T,V> addColumn(Class<V> type, ValueProvider<T,V> getter)
      Adds a column for the given type and value provider. The column is made sortable if the value type implements Comparable or is a primitive type. No column key or header is set automatically; use the returned EasyColumn to configure them.
      Type Parameters:
      V - the column value type
      Parameters:
      type - the Class of the column value, used to resolve the ColumnConfiguration
      getter - a value provider that extracts the column value from a bean instance
      Returns:
      the EasyColumn for the added column
    • createEasyColumn

      protected <V> EasyColumn<T,V> createEasyColumn(Class<V> type, ValueProvider<T,V> getter, String propertyName, PropertyDescriptor propertyDescriptor)
    • typeConfiguration

      public <V> ColumnConfiguration<V> typeConfiguration(Class<V> type)
      Returns the ColumnConfiguration for the given value type at the instance level, creating it if it does not yet exist. Modifications to the returned configuration apply to all columns of that type managed by this instance and take precedence over GlobalEasyGridConfiguration.
      Type Parameters:
      V - the column value type
      Parameters:
      type - the Class of the column value type
      Returns:
      the ColumnConfiguration for the given type
    • initContent

      protected GRID initContent()
      Overrides:
      initContent in class Composite<GRID extends Grid<T>>
    • getWrappedGrid

      public final GRID getWrappedGrid()
      Returns the wrapped grid.
      Returns:
      the wrapped grid, never null
    • configure

      public void configure(Consumer<Grid<T>> customizer)
      Passes the wrapped grid to the given customizer, allowing direct configuration of the grid.
      Parameters:
      customizer - a consumer that configures the wrapped grid