Class GridColumnScanner<T>
- Type Parameters:
T- Java class to be introspected
@GridColumn annotated getter methods,
allowing for declarative auto-generation of Grid.Columns.
See @GridColumn for an example of usage.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionGridColumnScanner(Class<T> type) Scan the given type and all super-types for@GridColumnannotations.GridColumnScanner(GridColumnScanner<T> original) Static information copy constructor. -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Grid.Column<T>addColumn(Grid<T> grid, String key, GridColumn annotation, String description, ValueProvider<T, ?> valueProvider, boolean selfRendering) Add and configure a single column to the givenGrid.voidaddColumnsTo(Grid<?> grid) Augment the givenGridwith columns auto-generated from@GridColumnannotations.booleanaddVisbilityMenuItems(Grid<?> grid, HasMenuItems menu) Add menu items that enable/disable the visibility of individual columns for for whichvisibilityMenu()was true to the given menu.Create a newGridwith columns generated from@GridColumnannotations.static Grid<?>Obtain theGridbeing configured in the current thread.protected StringdetermineColumnKey(MethodAnnotationScanner<T, GridColumn>.MethodInfo methodInfo) Determine the column key from the annotation.Get the annotations found through introspection indexed by column key.getType()Get the type associated with this instance.
-
Constructor Details
-
GridColumnScanner
Scan the given type and all super-types for@GridColumnannotations.- Parameters:
type- Java type to be introspected for annotations- Throws:
IllegalArgumentException- iftypeis nullIllegalArgumentException- if a bean property name cannot be inferred from the name of a method that is annotated with no explicit column keyIllegalArgumentException- iftypehas multiple@GridColumn-annotated methods specifying the same column key
-
GridColumnScanner
Static information copy constructor.Using this constructor is more efficient than repeatedly scanning the same classes for the same annotations.
Any modifications made to the
Mapreturned fromgetColumnMap()are included.- Parameters:
original- original instance- Throws:
IllegalArgumentException- iforiginalis null
-
-
Method Details
-
getType
Get the type associated with this instance.- Returns:
- backing object type
-
getColumnMap
Get the annotations found through introspection indexed by column key.This represents static information gathered by this instance by scanning the class hierarchy during construction.
The returned map is mutable, e.g., if you delete unwanted entries then
buildGrid()will skip them.- Returns:
- annotations keyed by column key, and sorted based on
GridColumn.order(), then key
-
buildGrid
Create a newGridwith columns generated from@GridColumnannotations.No columns are included for bean properties that are not annotated.
During the execution of this method, in particular when any custom
Renderer,ValueProvider, etc., classes are being instantiated, theGridbeing configured is available viacurrentGrid().- Returns:
- newly built
Gridwith auto-generated columns
-
addColumnsTo
Augment the givenGridwith columns auto-generated from@GridColumnannotations.This method applies to target
Grids with any model type and gracefully handles mismatches: annotated methods declared in Java types that are not supertype ofgrid's model type always "return" null.This allows populating a
Gridwith columns even when only some subtypes of the model type can actually provide values for those columns.Any existing columns with conflicting column keys will be replaced.
During the execution of this method, in particular when any custom
Renderer,ValueProvider, etc., classes are being instantiated, the suppliedgridis available viacurrentGrid().- Parameters:
grid- target grid- Throws:
IllegalArgumentException- ifgridis null
-
addColumn
public static <T> Grid.Column<T> addColumn(Grid<T> grid, String key, GridColumn annotation, String description, ValueProvider<T, ?> valueProvider, boolean selfRendering) Add and configure a single column to the givenGrid.During the execution of this method, in particular when any custom
Renderer,ValueProvider, etc., classes are being instantiated, the suppliedgridis available viacurrentGrid().- Type Parameters:
T- underlying bean type- Parameters:
grid- targetGridkey- the column's unique column keyannotation-@GridColumnannotationdescription- description of what we're configuring (for debug purposes)valueProvider-ValueProviderproviding the return value from the annotated method, or null if the annotated method returnsvoidorVoidselfRendering- true if the annotated method (and thereforevalueProvider) returns aComponent- Returns:
- newly added column
- Throws:
IllegalArgumentException- if any parameter is null
-
currentGrid
Obtain theGridbeing configured in the current thread.This method only works when the current thread is executing in
buildGrid(),addColumn(), oraddColumnsTo().- Returns:
- current
Gridbeing configured - Throws:
IllegalStateException- if noGridis currently being configured by this class
-
determineColumnKey
Determine the column key from the annotation.- Parameters:
methodInfo- method info- Returns:
- property name
-