Class GridColumnScanner<T>
- Type Parameters:
T
- Java class to be introspected
@GridColumn
annotated getter methods,
allowing for declarative auto-generation of Grid.Column
s.
See @GridColumn
for an example of usage.
- See Also:
-
Constructor Summary
ConstructorDescriptionGridColumnScanner
(Class<T> type) Scan the given type and all super-types for@GridColumn
annotations.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
.void
addColumnsTo
(Grid<?> grid) Augment the givenGrid
with columns auto-generated from@GridColumn
annotations.boolean
addVisbilityMenuItems
(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 newGrid
with columns generated from@GridColumn
annotations.static Grid<?>
Obtain theGrid
being configured in the current thread.protected String
determineColumnKey
(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@GridColumn
annotations.- Parameters:
type
- Java type to be introspected for annotations- Throws:
IllegalArgumentException
- iftype
is nullIllegalArgumentException
- if a bean property name cannot be inferred from the name of a method that is annotated with no explicit column keyIllegalArgumentException
- iftype
has 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
Map
returned fromgetColumnMap()
are included.- Parameters:
original
- original instance- Throws:
IllegalArgumentException
- iforiginal
is 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 newGrid
with columns generated from@GridColumn
annotations.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, theGrid
being configured is available viacurrentGrid()
.- Returns:
- newly built
Grid
with auto-generated columns
-
addColumnsTo
Augment the givenGrid
with columns auto-generated from@GridColumn
annotations.This method applies to target
Grid
s 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
Grid
with 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 suppliedgrid
is available viacurrentGrid()
.- Parameters:
grid
- target grid- Throws:
IllegalArgumentException
- ifgrid
is 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 suppliedgrid
is available viacurrentGrid()
.- Type Parameters:
T
- underlying bean type- Parameters:
grid
- targetGrid
key
- the column's unique column keyannotation
-@GridColumn
annotationdescription
- description of what we're configuring (for debug purposes)valueProvider
-ValueProvider
providing the return value from the annotated method, or null if the annotated method returnsvoid
orVoid
selfRendering
- true if the annotated method (and thereforevalueProvider
) returns aComponent
- Returns:
- newly added column
- Throws:
IllegalArgumentException
- if any parameter is null
-
currentGrid
Obtain theGrid
being configured in the current thread.This method only works when the current thread is executing in
buildGrid()
,addColumn()
, oraddColumnsTo()
.- Returns:
- current
Grid
being configured - Throws:
IllegalStateException
- if noGrid
is currently being configured by this class
-
determineColumnKey
Determine the column key from the annotation.- Parameters:
methodInfo
- method info- Returns:
- property name
-