Skip to content

Commit cb34dc9

Browse files
javier-godoyscardanzan
authored andcommitted
docs: update specifications
1 parent d9ddec2 commit cb34dc9

1 file changed

Lines changed: 47 additions & 34 deletions

File tree

SPECIFICATIONS.md

Lines changed: 47 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
## 1. Overview
44

5-
The Easy Grid Add-on is a configuration helper that wraps an externally instantiated Vaadin `Grid<T>`. It uses reflection to discover bean properties, maps them to appropriately typed and formatted columns, and provides a clean Java API for controlling column ordering and type-specific rendering.
5+
The Easy Grid Add-on provides `EasyGrid<T>`, a Vaadin `Composite` component that wraps an internally created `Grid<T>`. It uses reflection to discover bean properties, maps them to appropriately typed and formatted columns, and provides a clean Java API for controlling column ordering and type-specific rendering.
66

7-
`EasyGrid<T>` is **not** a component — it configures an existing `Grid<T>` that was created and managed by the caller. Data binding, selection, events, and all other standard `Grid` features are accessed directly on the wrapped `Grid` instance.
7+
`EasyGrid<T>` is a component — it is added to the layout directly. Data binding and all other standard `Grid` features are accessed directly on the `EasyGrid` instance, which delegates them to the wrapped `Grid`. The wrapped `Grid` is accessible via `getGrid()` for any configuration not covered by the delegating API.
8+
9+
For advanced cases where a custom `Grid` subclass must be supplied (e.g. `TreeGrid`), use `EasyGridWrapper<T, GRID>` instead — it accepts a caller-provided `GRID extends Grid<T>` and otherwise provides the same API.
810

911
## 2. Core Concepts
1012

@@ -16,18 +18,18 @@ Given a POJO class `T`, `EasyGrid<T>` introspects its properties (via getter/set
1618

1719
Each Java type maps to a default column renderer and configuration:
1820

19-
| Java Type | Renderer | Alignment | Sorting |
20-
|-----------|----------|-----------|---------|
21-
| `String` | `TextRenderer` | Start | Alphabetical |
22-
| `Integer`, `int` | `NumberRenderer` | End | Numeric |
23-
| `Long`, `long` | `NumberRenderer` | End | Numeric |
24-
| `Double`, `double`, `Float`, `float` | `NumberRenderer` | End | Numeric |
25-
| `BigDecimal` | `NumberRenderer` | End | Numeric |
26-
| `Boolean`, `boolean` | `TextRenderer` ("true"/"false") | Center ||
27-
| `LocalDate` | `LocalDateRenderer` | Start | Chronological |
28-
| `LocalDateTime` | `LocalDateTimeRenderer` | Start | Chronological |
29-
| `LocalTime` | `TextRenderer` (formatted) | Start | Chronological |
30-
| `Enum<?>` | `TextRenderer` (`toString()`) | Start | Alphabetical |
21+
| Java Type | Renderer | Default Format | Alignment | Sorting |
22+
|-----------|----------|----------------|-----------|---------|
23+
| `String` | `TextRenderer` | | Start | Alphabetical |
24+
| `Integer`, `int` | `NumberRenderer` | | End | Numeric |
25+
| `Long`, `long` | `NumberRenderer` | | End | Numeric |
26+
| `Double`, `double`, `Float`, `float` | `NumberRenderer` | | End | Numeric |
27+
| `BigDecimal` | `NumberRenderer` | | End | Numeric |
28+
| `Boolean`, `boolean` | `TextRenderer` | "true"/"false" | Center ||
29+
| `LocalDate` | `LocalDateRenderer` | `yyyy-MM-dd` | Start | Chronological |
30+
| `LocalDateTime` | `LocalDateTimeRenderer` | `yyyy-MM-dd HH:mm:ss` | Start | Chronological |
31+
| `LocalTime` | `TextRenderer` (formatted) | | Start | Chronological |
32+
| `Enum<?>` | `TextRenderer` | `toString()` | Start | Alphabetical |
3133

3234
Custom type mappings can be registered globally or per-grid instance.
3335

@@ -43,29 +45,38 @@ All columns backed by `Comparable` property types are sortable by default. Multi
4345

4446
### 3.1 Construction
4547

46-
`EasyGrid<T>` takes an existing `Grid<T>` instance and a bean class. The caller retains full ownership of the grid.
48+
`EasyGrid<T>` creates its own `Grid<T>` internally. The caller adds the `EasyGrid` instance to the layout and calls `setItems()` on it.
4749

4850
```java
4951
// Basic: all discovered properties become columns
50-
Grid<Person> grid = new Grid<>();
51-
EasyGrid<Person> easyGrid = new EasyGrid<>(grid, Person.class);
52-
grid.setItems(personService.findAll());
53-
add(grid);
52+
EasyGrid<Person> easyGrid = new EasyGrid<>(Person.class);
53+
easyGrid.setItems(personService.findAll());
54+
add(easyGrid);
5455

5556
// Selective: only specified properties become columns, in order
56-
Grid<Person> grid = new Grid<>();
57-
EasyGrid<Person> easyGrid = new EasyGrid<>(grid, Person.class, "firstName", "lastName", "email", "age");
58-
grid.setItems(personService.findAll());
59-
add(grid);
57+
EasyGrid<Person> easyGrid = new EasyGrid<>(Person.class, "firstName", "lastName", "email", "age");
58+
easyGrid.setItems(personService.findAll());
59+
add(easyGrid);
6060

6161
// Manual: suppress automatic column creation; add columns explicitly
62-
Grid<Person> grid = new Grid<>();
63-
EasyGrid<Person> easyGrid = new EasyGrid<>(grid, Person.class, false);
62+
EasyGrid<Person> easyGrid = new EasyGrid<>(Person.class, false);
6463
easyGrid.addColumn("firstName");
6564
easyGrid.addColumn("lastName");
6665
easyGrid.addColumn(String.class, person -> person.getAddress().getCity());
67-
grid.setItems(personService.findAll());
68-
add(grid);
66+
easyGrid.setItems(personService.findAll());
67+
add(easyGrid);
68+
```
69+
70+
For cases where a custom `Grid` subclass must be supplied, use `EasyGridWrapper`:
71+
72+
```java
73+
TreeGrid<Person> treeGrid = new TreeGrid<>();
74+
EasyGridWrapper<Person, TreeGrid<Person>> wrapper =
75+
new EasyGridWrapper<>(treeGrid, Person.class, "firstName", "lastName");
76+
wrapper.setItems(personService.findAll());
77+
add(wrapper);
78+
// access the wrapped grid for TreeGrid-specific configuration
79+
wrapper.getGrid().setItemHierarchyData(...);
6980
```
7081

7182
`EasyGrid` also provides a typed overload for columns not backed by a named bean property:
@@ -102,6 +113,9 @@ public class EasyColumn<T, V> {
102113
// Cast-checked type narrowing — succeeds when the column's value type is a subtype of S
103114
<S> EasyColumn<T, S> as(Class<S> type);
104115

116+
// The column value type
117+
Class<V> getType();
118+
105119
// Standard Grid.Column configuration — delegated for fluent chaining
106120
EasyColumn<T, V> setHeader(String headerText);
107121
EasyColumn<T, V> setHeader(Component headerComponent);
@@ -207,7 +221,7 @@ Formatters that receive a `ColumnConfiguration` parameter can call `getNullRepre
207221

208222
#### Type Hierarchy Support
209223

210-
Inside each scope level, `EasyGridConfigurationClassMap` walks the Java class hierarchy. When a configuration is requested for `Foo` and none exists, it is created with `Foo`'s superclass configuration as its parent, continuing up to `Object`. Primitive types are mapped to their boxed counterparts before hierarchy walking (`int``Integer`, `boolean``Boolean`, etc.).
224+
Inside each scope level, configuration walks the Java class hierarchy. When a configuration is requested for `Foo` and none exists, it is created with `Foo`'s superclass configuration as its parent, continuing up to `Object`. Primitive types are mapped to their boxed counterparts before hierarchy walking (`int``Integer`, `boolean``Boolean`, etc.).
211225

212226
A global `Number.class` renderer factory is therefore automatically inherited by `Integer`, `Long`, `BigDecimal`, and every other `Number` subtype unless a more specific configuration overrides it.
213227

@@ -244,7 +258,7 @@ When a column is added by `EasyGrid` and no explicit header has been set on it,
244258
Nested properties can be referenced using dot notation:
245259

246260
```java
247-
EasyGrid<Person> easyGrid = new EasyGrid<>(grid, Person.class,
261+
EasyGrid<Person> easyGrid = new EasyGrid<>(Person.class,
248262
"firstName", "lastName", "address.city", "address.postalCode");
249263

250264
easyGrid.getColumn("address.city")
@@ -259,8 +273,7 @@ easyGrid.getColumn("address.city")
259273
## 7. Usage Example — Complete
260274

261275
```java
262-
Grid<Person> grid = new Grid<>();
263-
EasyGrid<Person> easyGrid = new EasyGrid<>(grid, Person.class);
276+
EasyGrid<Person> easyGrid = new EasyGrid<>(Person.class);
264277

265278
// Column ordering and visibility
266279
easyGrid.setColumnOrder("firstName", "lastName", "email", "birthDate", "age", "subscriber");
@@ -279,9 +292,9 @@ easyGrid.getColumn("firstName")
279292
easyGrid.getColumn("age")
280293
.setTextAlign(ColumnTextAlign.END);
281294

282-
// Data binding and adding to layout — done on the Grid directly
283-
grid.setItems(personService.findAll());
284-
add(grid);
295+
// Data binding and adding to layout
296+
easyGrid.setItems(personService.findAll());
297+
add(easyGrid);
285298
```
286299

287300
## 8. Dependencies

0 commit comments

Comments
 (0)