GridSystemService

Encapsulates a single layout grid system which can be used to customize the layout of domain objects.

In particular this means being able to return a "normalized" form (validating and associating domain object members into the various regions of the grid) and in providing a default grid if there is no other metadata available.

API

GridSystemService.java
interface GridSystemService<G> {
  Class<G> gridImplementation()     (1)
  String tns()     (2)
  String schemaLocation()     (3)
  G defaultGrid(Class<?> domainClass)     (4)
  void normalize(G grid, Class<?> domainClass)     (5)
  void complete(G grid, Class<?> domainClass)     (6)
  void minimal(G grid, Class<?> domainClass)     (7)
}
1 gridImplementation()

The concrete subclass of Grid supported by this implementation.

2 tns()

The target namespace for this grid system.

3 schemaLocation()

The schema location for the XSD.

4 defaultGrid(Class)

A default grid, used when no grid layout can be found for the domain class.

5 normalize(G, Class)

Validates and normalizes a grid, modifying the grid so that all of the domain object’s members (properties, collections, actions) are bound to regions of the grid.

6 complete(G, Class)

Takes a normalized grid and enriches it with all the available metadata (taken from Apache Causeway' internal metadata) that can be represented in the layout XML.

7 minimal(G, Class)

Takes a normalized grid and strips out removes all members, leaving only the grid structure.

Members

gridImplementation()

The concrete subclass of Grid supported by this implementation.

There can be multiple implementations of this service, this indicates the base class used by the implementation.

tns()

The target namespace for this grid system.

This is used when generating the XML. The Bootstrap grid system provided by the framework returns the value https://causeway.apache.org/applib/layout/grid/bootstrap3.

schemaLocation()

The schema location for the XSD.

Every grid system is expected to provide a schema XSD in order to provide code completion in an IDE. The Bootstrap grid system provided by the framework returns the value https://causeway.apache.org/applib/layout/grid/bootstrap3/bootstrap3.xsd.

defaultGrid(Class)

A default grid, used when no grid layout can be found for the domain class.

For example, this layout could define two columns in ratio 4:8.

normalize(G, Class)

Validates and normalizes a grid, modifying the grid so that all of the domain object’s members (properties, collections, actions) are bound to regions of the grid.

This is done using existing metadata, most notably that of the org.apache.causeway.applib.annotation.MemberOrder annotation. Such a grid, if persisted as the layout XML file for the domain class, allows the org.apache.causeway.applib.annotation.MemberOrder annotation to be removed from the source code of the domain class (but other annotations must be retained).

complete(G, Class)

Takes a normalized grid and enriches it with all the available metadata (taken from Apache Causeway' internal metadata) that can be represented in the layout XML.

Such a grid, if persisted as the layout XML file for the domain class, allows all layout annotations ( org.apache.causeway.applib.annotation.ActionLayout , org.apache.causeway.applib.annotation.PropertyLayout , org.apache.causeway.applib.annotation.CollectionLayout ) to be removed from the source code of the domain class.

minimal(G, Class)

Takes a normalized grid and strips out removes all members, leaving only the grid structure.

Such a grid, if persisted as the layout XML file for the domain class, requires that the org.apache.causeway.applib.annotation.MemberOrder annotation is retained in the source code of said class in order to bind members to the regions of the grid.

Implementation

The framework provides a single grid implementation, o.a.c.core.metamodel.services.grid.bootstrap.GridSystemServiceBootstrap, which supports Bootstrap3 (https://causeway.apache.org/applib/layout/grid/bootstrap3/bootstrap3.xsd).

A SPI is provided via nested interface FallbackLayoutDataSource, that allows to customize layout fallback behavior on a per class basis. (Without having to override the heavy weight GridSystemServiceBootstrap.)

FallbackLayoutDataSource SPI
interface FallbackLayoutDataSource {
    Try<String> tryLoadAsStringUtf8(Class<?> domainClass); (1)
}
  1. Provides custom default for given domainClass or return an Try.empty() if indifferent.

FallbackLayoutDataSource example
@Service
public class FallbackLayoutForManager implements FallbackLayoutDataSource {

    @Override
    public Try<String> tryLoadAsStringUtf8(final Class<?> domainClass) {
        return domainClass.getSimpleName().endsWith("Manager")
                ? DataSource.ofResource(getClass(), "ManagerLayout.xml") (1)
                    .tryReadAsStringUtf8()
                : Try.empty(); (2)
    }

}
  1. Provides a custom layout for all domain classes that have a name ending with 'Manager'.

  2. Indifferent for given domain type. Tells the framework to fall through.

(The framework also provides Web UI (Wicket viewer) components that are capable of interpreting and rendering this metadata.

Usage Notes

The framework will check all available implementations of GridSystemService to obtain available grid systems, rather than merely the first implementation found, to determine if a grid is available for the domain object to be rendered; in other words it uses the chain-of-responsibility pattern. Services are called in the order defined by the @javax.annotation.Priority annotation.

Note though that each concrete implementation must also provide corresponding Wicket viewer components capable of interpreting the grid layout. This is therefore a highly specialized and very deep customisation of the framework.

See also

This service is used by GridService.