Class ObjectFieldFactory
java.lang.Object
org.vaadin.miki.superfields.util.factory.ObjectFieldFactory
Configures
ObjectField to work "out of the box" for most common use cases.
Allows overriding most settings either directly or by subclassing.- Since:
- 2022-09-08
- Author:
- miki
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected PropertyComponentBuilderBuilds aSimplePropertyComponentBuilderand configures it for building most default components: properties marked withMetadataProperties.SHOW_AS_COMPONENT_METADATA_PROPERTYas requested boolean properties asSuperCheckboxinteger properties asSuperIntegerFieldlong properties asSuperLongFielddouble properties asSuperDoubleFieldBigDecimalproperties asSuperBigDecimalFieldLocalDateproperties asSuperDatePickerLocalDateTimeproperties asSuperDateTimePickerStringproperties as eitherSuperTextFieldorSuperTextArea(depending onMetadataProperties.MULTILINE_METADATA_PROPERTY) registered collection (lists and sets) properties asCollectionFieldmap properties asMapFieldObjectFieldusing this factory as default (that falls back toLabelField)protected PropertyGroupingProviderBuilds aPropertyGroupingProviderbased on presence ofMetadataProperties.GROUP_METADATA_PROPERTYandMetadataProperties.ORDER_METADATA_PROPERTY.protected PropertyGroupLayoutProviderBuilds aPropertyGroupLayoutProviderthat provides a separate layout for a group with two or more properties in it.<T> ObjectField<T>buildAndConfigureObjectField(Class<T> type) Builds, configures, and repaints anObjectFieldfor a given type, using instance provider fromgetInstanceProvider(Class).<T> ObjectField<T>buildAndConfigureObjectField(Class<T> type, boolean repaint) Builds, configures, and optionally repaints anObjectFieldfor a given type, using instance provider fromgetInstanceProvider(Class).<T> ObjectField<T>buildAndConfigureObjectField(Class<T> type, com.vaadin.flow.function.SerializableSupplier<T> newInstanceProvider) Builds, configures, and repaints anObjectFieldfor a given type using given instance provider.<T> ObjectField<T>buildAndConfigureObjectField(Class<T> type, com.vaadin.flow.function.SerializableSupplier<T> newInstanceProvider, boolean repaint) Builds, configures and optionally repaints anObjectFieldfor a given type using given instance provider.protected PropertyProviderBuilds aReflectivePropertyProviderand configures it to a typical use case based on annotations:FieldGroupis mapped toMetadataProperties.GROUP_METADATA_PROPERTYFieldOrderis mapped toMetadataProperties.ORDER_METADATA_PROPERTYBigFieldis mapped toMetadataProperties.MULTILINE_METADATA_PROPERTYFieldCaptionis mapped toMetadataProperties.CAPTION_METADATA_PROPERTYShowFieldAsis mapped toMetadataProperties.SHOW_AS_COMPONENT_METADATA_PROPERTYBuildFieldWithis mapped toMetadataProperties.COMPONENT_BUILDER_METADATA_PROPERTYIn addition fields without a setter are marked withMetadataProperties.READ_ONLY_METADATA_PROPERTY, and collections and maps usingMetadataProperties.COLLECTION_ELEMENT_TYPE_METADATA_PROPERTY,MetadataProperties.MAP_KEY_TYPE_METADATA_PROPERTYandMetadataProperties.MAP_VALUE_TYPE_METADATA_PROPERTY.protected <T,C extends Collection<T>>
CollectionField<T,C> buildCollectionField(Property<?, T> elementProperty, Class<? extends Collection<?>> collectionType, PropertyComponentBuilder callbackFactory) Builds a collection field.protected <T> Collection<ComponentConfigurator<T>>buildComponentConfigurators(Class<T> dataType) BuildsComponentConfigurators for a given data type: components have their label set up according toMetadataProperties.CAPTION_METADATA_PROPERTYor the field name components are set to read only based onMetadataProperties.READ_ONLY_METADATA_PROPERTYcomponents have their style names set up according toMetadataProperties.COMPONENT_STYLE_METADATA_PROPERTYcomponents have their id set according toMetadataProperties.COMPONENT_ID_METADATA_PROPERTYprotected Collection<ComponentGroupConfigurator>BuildsComponentGroupConfigurators: each component in a named group has style names added to it (obtained fromgetGroupComponentStyleNames()protected <K,V> MapField<K, V> buildMapField(Property<?, K> keyProperty, Property<?, V> valueProperty, PropertyComponentBuilder callbackFactory) Builds a map field.final <T> ObjectField<T>configureObjectField(ObjectField<T> objectField) Configures a given object field.Returns aCollectionLayoutProviderto be used in newCollectionFields.<E,C extends Collection<E>>
com.vaadin.flow.function.SerializableSupplier<C>getEmptyCollectionProvider(Class<C> type) Returns an empty collection provider for a given collection type.<K,V> com.vaadin.flow.function.SerializableSupplier<Map<K, V>> Returns a supplier for an empty map.Returns styles to be added to each component in a group inObjectField.Returns styles to be added to each group layout in anObjectField.<T> com.vaadin.flow.function.SerializableSupplier<T>getInstanceProvider(Class<T> type) Returns the instance provider associated with the given type, if any, or a default one.<L extends com.vaadin.flow.component.Component & com.vaadin.flow.component.HasComponents>
com.vaadin.flow.function.SerializableSupplier<L>Returns a way to obtain a layout for aMapEntryFieldused inMapFields.Returns aCollectionLayoutProviderfor newMapFields.<L extends com.vaadin.flow.component.Component & com.vaadin.flow.component.HasComponents>
com.vaadin.flow.function.SerializableSupplier<L>Returns a way to obtain layouts for each group in anObjectField.<L extends com.vaadin.flow.component.Component & com.vaadin.flow.component.HasComponents>
com.vaadin.flow.function.SerializableSupplier<L>Returns a way to obtain layouts for newObjectFields.<E,C extends Collection<E>>
voidregisterEmptyCollectionProvider(Class<C> collectionType, com.vaadin.flow.function.SerializableSupplier<C> supplier) Registers an empty collection provider for a given collection type.<T> voidregisterInstanceProvider(Class<T> type, com.vaadin.flow.function.SerializableSupplier<T> supplier) Registers an instance provider for a given type.voidsetCollectionFieldLayoutProvider(CollectionLayoutProvider<?> collectionFieldLayoutProvider) Sets a newCollectionLayoutProviderto be used in newCollectionFields.voidsetEmptyMapSupplier(com.vaadin.flow.function.SerializableSupplier<Map<?, ?>> emptyMapSupplier) Sets a supplier for empty maps.voidsetGroupComponentStyleNames(Collection<String> groupComponentStyleNames) Sets new styles to be added to each component in a group inObjectField.voidsetGroupLayoutStyleNames(Collection<String> groupLayoutStyleNames) Sets new styles to be added to each group layout in anObjectField.<L extends com.vaadin.flow.component.Component & com.vaadin.flow.component.HasComponents>
voidsetMapEntryFieldLayoutProvider(com.vaadin.flow.function.SerializableSupplier<L> mapEntryFieldLayoutProvider) Sets a new way to obtain layouts forMapEntryFieldinMapField.voidsetMapFieldLayoutProvider(CollectionLayoutProvider<?> mapFieldLayoutProvider) Sets a newCollectionLayoutProviderto be used in newMapFields.<L extends com.vaadin.flow.component.Component & com.vaadin.flow.component.HasComponents>
voidsetObjectFieldGroupLayoutProvider(com.vaadin.flow.function.SerializableSupplier<L> objectFieldGroupLayoutProvider) Sets a new way to obtain layouts for each group in anObjectField.<L extends com.vaadin.flow.component.Component & com.vaadin.flow.component.HasComponents>
voidsetObjectFieldLayoutProvider(com.vaadin.flow.function.SerializableSupplier<L> objectFieldLayoutProvider) Sets a new way to obtain layouts for newObjectFields.
-
Constructor Details
-
ObjectFieldFactory
public ObjectFieldFactory()Constructs the factory.
-
-
Method Details
-
buildCollectionField
protected <T,C extends Collection<T>> CollectionField<T,C> buildCollectionField(Property<?, T> elementProperty, Class<? extends Collection<?>> collectionType, PropertyComponentBuilder callbackFactory) Builds a collection field.- Type Parameters:
T- Type of element in the collection.C- Type of collection.- Parameters:
elementProperty- Property for the element of the collection.collectionType- Type of the collection.callbackFactory- Callback factory to build components.- Returns:
- An instance of a
CollectionField.
-
buildMapField
protected <K,V> MapField<K,V> buildMapField(Property<?, K> keyProperty, Property<?, V> valueProperty, PropertyComponentBuilder callbackFactory) Builds a map field.- Type Parameters:
K- Type of key.V- Type of value.- Parameters:
keyProperty- Property for the key of the map.valueProperty- Property for the value of the map.callbackFactory- Factory to produce components.- Returns:
- A
MapField.
-
buildAndConfigureComponentBuilder
Builds aSimplePropertyComponentBuilderand configures it for building most default components:- properties marked with
MetadataProperties.SHOW_AS_COMPONENT_METADATA_PROPERTYas requested - boolean properties as
SuperCheckbox - integer properties as
SuperIntegerField - long properties as
SuperLongField - double properties as
SuperDoubleField BigDecimalproperties asSuperBigDecimalFieldLocalDateproperties asSuperDatePickerLocalDateTimeproperties asSuperDateTimePickerStringproperties as eitherSuperTextFieldorSuperTextArea(depending onMetadataProperties.MULTILINE_METADATA_PROPERTY)- registered collection (lists and sets) properties as
CollectionField - map properties as
MapField ObjectFieldusing this factory as default (that falls back toLabelField)
- Returns:
- A
SimplePropertyComponentBuilder.
- properties marked with
-
buildAndConfigurePropertyProvider
Builds aReflectivePropertyProviderand configures it to a typical use case based on annotations:FieldGroupis mapped toMetadataProperties.GROUP_METADATA_PROPERTYFieldOrderis mapped toMetadataProperties.ORDER_METADATA_PROPERTYBigFieldis mapped toMetadataProperties.MULTILINE_METADATA_PROPERTYFieldCaptionis mapped toMetadataProperties.CAPTION_METADATA_PROPERTYShowFieldAsis mapped toMetadataProperties.SHOW_AS_COMPONENT_METADATA_PROPERTYBuildFieldWithis mapped toMetadataProperties.COMPONENT_BUILDER_METADATA_PROPERTY
MetadataProperties.READ_ONLY_METADATA_PROPERTY, and collections and maps usingMetadataProperties.COLLECTION_ELEMENT_TYPE_METADATA_PROPERTY,MetadataProperties.MAP_KEY_TYPE_METADATA_PROPERTYandMetadataProperties.MAP_VALUE_TYPE_METADATA_PROPERTY.- Returns:
- A
ReflectivePropertyProvider.
-
buildAndConfigureGroupingProvider
Builds aPropertyGroupingProviderbased on presence ofMetadataProperties.GROUP_METADATA_PROPERTYandMetadataProperties.ORDER_METADATA_PROPERTY.- Returns:
- A
MetadataBasedGroupingProvider.
-
buildComponentConfigurators
BuildsComponentConfigurators for a given data type:- components have their label set up according to
MetadataProperties.CAPTION_METADATA_PROPERTYor the field name - components are set to read only based on
MetadataProperties.READ_ONLY_METADATA_PROPERTY - components have their style names set up according to
MetadataProperties.COMPONENT_STYLE_METADATA_PROPERTY - components have their id set according to
MetadataProperties.COMPONENT_ID_METADATA_PROPERTY
- Type Parameters:
T- Type of object.- Parameters:
dataType- Type of object (the type of theObjectFieldthe returned configurators will be added to).- Returns:
- A non-
null, but possibly empty collection.
- components have their label set up according to
-
buildAndConfigureGroupLayoutProvider
Builds aPropertyGroupLayoutProviderthat provides a separate layout for a group with two or more properties in it. Each produced layout has style names added (fromgetGroupLayoutStyleNames()), if possible.- Returns:
- A
PropertyGroupLayoutProvider.
-
buildComponentGroupConfigurators
BuildsComponentGroupConfigurators:- each component in a named group has style names added to it (obtained from
getGroupComponentStyleNames()
- Returns:
- A non-
nullcollection ofComponentGroupConfigurators.
- each component in a named group has style names added to it (obtained from
-
buildAndConfigureObjectField
Builds, configures, and repaints anObjectFieldfor a given type, using instance provider fromgetInstanceProvider(Class).- Type Parameters:
T- Type of object to display.- Parameters:
type- Type to build anObjectFieldfor.- Returns:
- An
ObjectField.
-
buildAndConfigureObjectField
Builds, configures, and optionally repaints anObjectFieldfor a given type, using instance provider fromgetInstanceProvider(Class).- Type Parameters:
T- Type of object to display.- Parameters:
type- Type to build anObjectFieldfor.repaint- Whether to repaint the created object field. Note that a not-repainted field will basically be empty until it is repainted or a new value is set.- Returns:
- An
ObjectField.
-
buildAndConfigureObjectField
public <T> ObjectField<T> buildAndConfigureObjectField(Class<T> type, com.vaadin.flow.function.SerializableSupplier<T> newInstanceProvider) Builds, configures, and repaints anObjectFieldfor a given type using given instance provider.- Type Parameters:
T- Type of object to display.- Parameters:
type- Type to build anObjectFieldfor.newInstanceProvider- A way to produce new instances of the object.- Returns:
- An
ObjectField.
-
buildAndConfigureObjectField
public <T> ObjectField<T> buildAndConfigureObjectField(Class<T> type, com.vaadin.flow.function.SerializableSupplier<T> newInstanceProvider, boolean repaint) Builds, configures and optionally repaints anObjectFieldfor a given type using given instance provider.- Type Parameters:
T- Type of object to display.- Parameters:
type- Type to build anObjectFieldfor.newInstanceProvider- A way to produce new instances of the object.repaint- Whether to repaint the created object field. Note that a not-repainted field will basically be empty until it is repainted or a new value is set.- Returns:
- An
ObjectField.
-
configureObjectField
Configures a given object field. This will call the following methods, in the given order:ObjectField.withPropertyProvider(PropertyProvider)usingbuildAndConfigurePropertyProvider()ObjectField.withPropertyGroupingProvider(PropertyGroupingProvider)usingbuildAndConfigureGroupingProvider()ObjectField.withPropertyComponentBuilder(PropertyComponentBuilder)usingbuildAndConfigureComponentBuilder()ObjectField.withGroupLayoutProvider(PropertyGroupLayoutProvider)usingbuildAndConfigureGroupLayoutProvider()ObjectField.withComponentConfigurators(Collection)usingbuildComponentConfigurators(Class)ObjectField.withComponentGroupConfigurators(Collection)usingbuildComponentGroupConfigurators()
- Type Parameters:
T- Type of object to display.- Parameters:
objectField- The passed parameter, but with the above-mentioned configuration applied.
-
registerInstanceProvider
public <T> void registerInstanceProvider(Class<T> type, com.vaadin.flow.function.SerializableSupplier<T> supplier) Registers an instance provider for a given type. This speeds up creating new instances of the type inObjectFields.- Type Parameters:
T- Type.- Parameters:
type- Type to register instance provider for.supplier- A method called to create a new instance.
-
getInstanceProvider
Returns the instance provider associated with the given type, if any, or a default one.- Type Parameters:
T- Type.- Parameters:
type- Type to return the instance provider for.- Returns:
- A method that produces new instances of the given type.
-
registerEmptyCollectionProvider
public <E,C extends Collection<E>> void registerEmptyCollectionProvider(Class<C> collectionType, com.vaadin.flow.function.SerializableSupplier<C> supplier) Registers an empty collection provider for a given collection type.- Type Parameters:
E- Element type. Ignored.C- Collection type. Ignored.- Parameters:
collectionType- Base collection type.supplier- Supplier for an empty collection.
-
getEmptyCollectionProvider
public <E,C extends Collection<E>> com.vaadin.flow.function.SerializableSupplier<C> getEmptyCollectionProvider(Class<C> type) Returns an empty collection provider for a given collection type.- Type Parameters:
E- Element type. Ignored.C- Collection type. Ignored.- Parameters:
type- Type of collection.- Returns:
- A method to produce an empty collection. Used in
buildCollectionField(Property, Class, PropertyComponentBuilder).
-
getEmptyMapSupplier
Returns a supplier for an empty map. Used inbuildMapField(Property, Property, PropertyComponentBuilder).- Returns:
- A way to get an empty map.
-
setEmptyMapSupplier
public void setEmptyMapSupplier(com.vaadin.flow.function.SerializableSupplier<Map<?, ?>> emptyMapSupplier) Sets a supplier for empty maps.- Parameters:
emptyMapSupplier- A way to produce an empty map.
-
getCollectionFieldLayoutProvider
Returns aCollectionLayoutProviderto be used in newCollectionFields.- Returns:
- A
CollectionLayoutProvider. Used inbuildCollectionField(Property, Class, PropertyComponentBuilder).
-
setCollectionFieldLayoutProvider
public void setCollectionFieldLayoutProvider(CollectionLayoutProvider<?> collectionFieldLayoutProvider) Sets a newCollectionLayoutProviderto be used in newCollectionFields.- Parameters:
collectionFieldLayoutProvider- ACollectionLayoutProvider.
-
getMapFieldLayoutProvider
Returns aCollectionLayoutProviderfor newMapFields.- Returns:
- A
CollectionLayoutProvider. Used inbuildMapField(Property, Property, PropertyComponentBuilder).
-
setMapFieldLayoutProvider
Sets a newCollectionLayoutProviderto be used in newMapFields.- Parameters:
mapFieldLayoutProvider- ACollectionLayoutProvider.
-
getMapEntryFieldLayoutProvider
public <L extends com.vaadin.flow.component.Component & com.vaadin.flow.component.HasComponents> com.vaadin.flow.function.SerializableSupplier<L> getMapEntryFieldLayoutProvider()Returns a way to obtain a layout for aMapEntryFieldused inMapFields.- Type Parameters:
L- Type of layout.- Returns:
- A way to obtain a layout. Used in
buildMapField(Property, Property, PropertyComponentBuilder).
-
setMapEntryFieldLayoutProvider
public <L extends com.vaadin.flow.component.Component & com.vaadin.flow.component.HasComponents> void setMapEntryFieldLayoutProvider(com.vaadin.flow.function.SerializableSupplier<L> mapEntryFieldLayoutProvider) Sets a new way to obtain layouts forMapEntryFieldinMapField.- Type Parameters:
L- Layout type.- Parameters:
mapEntryFieldLayoutProvider- A new way to obtain layouts.
-
getObjectFieldLayoutProvider
public <L extends com.vaadin.flow.component.Component & com.vaadin.flow.component.HasComponents> com.vaadin.flow.function.SerializableSupplier<L> getObjectFieldLayoutProvider()Returns a way to obtain layouts for newObjectFields.- Type Parameters:
L- Type of layout.- Returns:
- A way to obtain a layout.
-
setObjectFieldLayoutProvider
public <L extends com.vaadin.flow.component.Component & com.vaadin.flow.component.HasComponents> void setObjectFieldLayoutProvider(com.vaadin.flow.function.SerializableSupplier<L> objectFieldLayoutProvider) Sets a new way to obtain layouts for newObjectFields.- Type Parameters:
L- Layout type.- Parameters:
objectFieldLayoutProvider- Layout provider.
-
getObjectFieldGroupLayoutProvider
public <L extends com.vaadin.flow.component.Component & com.vaadin.flow.component.HasComponents> com.vaadin.flow.function.SerializableSupplier<L> getObjectFieldGroupLayoutProvider()Returns a way to obtain layouts for each group in anObjectField. This is used inbuildAndConfigureGroupLayoutProvider().- Type Parameters:
L- Layout type.- Returns:
- A layout provider.
-
setObjectFieldGroupLayoutProvider
public <L extends com.vaadin.flow.component.Component & com.vaadin.flow.component.HasComponents> void setObjectFieldGroupLayoutProvider(com.vaadin.flow.function.SerializableSupplier<L> objectFieldGroupLayoutProvider) Sets a new way to obtain layouts for each group in anObjectField.- Type Parameters:
L- Type of layout.- Parameters:
objectFieldGroupLayoutProvider- A layout provider.
-
getGroupLayoutStyleNames
Returns styles to be added to each group layout in anObjectField. This is used inbuildAndConfigureGroupLayoutProvider().- Returns:
- A non-
nullcollection of styles.
-
setGroupLayoutStyleNames
Sets new styles to be added to each group layout in anObjectField. Each style name will have.format(groupName)applied to it.- Parameters:
groupLayoutStyleNames- Style names.
-
getGroupComponentStyleNames
Returns styles to be added to each component in a group inObjectField. This is used inbuildComponentGroupConfigurators().- Returns:
- A non-
nullcollection of styles.
-
setGroupComponentStyleNames
Sets new styles to be added to each component in a group inObjectField. Each style name will have.format(groupName)applied to it.- Parameters:
groupComponentStyleNames- Style names.
-