public class ObjectFieldFactory extends Object
ObjectField to work "out of the box" for most common use cases.
Allows overriding most settings either directly or by subclassing.| Constructor and Description |
|---|
ObjectFieldFactory()
Constructs the factory.
|
| Modifier and Type | Method and Description |
|---|---|
protected PropertyComponentBuilder |
buildAndConfigureComponentBuilder()
Builds a
SimplePropertyComponentBuilder and configures it for building most default components:
properties marked with MetadataProperties.SHOW_AS_COMPONENT_METADATA_PROPERTY as requested
boolean properties as SuperCheckbox
integer properties as SuperIntegerField
long properties as SuperLongField
double properties as SuperDoubleField
BigDecimal properties as SuperBigDecimalField
LocalDate properties as SuperDatePicker
LocalDateTime properties as SuperDateTimePicker
String properties as either SuperTextField or SuperTextArea (depending on MetadataProperties.MULTILINE_METADATA_PROPERTY)
registered collection (lists and sets) properties as CollectionField
map properties as MapField
ObjectField using this factory as default (that falls back to LabelField)
|
protected PropertyGroupingProvider |
buildAndConfigureGroupingProvider()
Builds a
PropertyGroupingProvider based on presence of MetadataProperties.GROUP_METADATA_PROPERTY and MetadataProperties.ORDER_METADATA_PROPERTY. |
protected PropertyGroupLayoutProvider |
buildAndConfigureGroupLayoutProvider()
Builds a
PropertyGroupLayoutProvider that 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 an
ObjectField for a given type, using instance provider from getInstanceProvider(Class). |
<T> ObjectField<T> |
buildAndConfigureObjectField(Class<T> type,
boolean repaint)
Builds, configures, and optionally repaints an
ObjectField for a given type, using instance provider from getInstanceProvider(Class). |
<T> ObjectField<T> |
buildAndConfigureObjectField(Class<T> type,
com.vaadin.flow.function.SerializableSupplier<T> newInstanceProvider)
Builds, configures, and repaints an
ObjectField for 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 an
ObjectField for a given type using given instance provider. |
protected PropertyProvider |
buildAndConfigurePropertyProvider()
Builds a
ReflectivePropertyProvider and configures it to a typical use case based on annotations:
FieldGroup is mapped to MetadataProperties.GROUP_METADATA_PROPERTY
FieldOrder is mapped to MetadataProperties.ORDER_METADATA_PROPERTY
BigField is mapped to MetadataProperties.MULTILINE_METADATA_PROPERTY
FieldCaption is mapped to MetadataProperties.CAPTION_METADATA_PROPERTY
ShowFieldAs is mapped to MetadataProperties.SHOW_AS_COMPONENT_METADATA_PROPERTY
BuildFieldWith is mapped to MetadataProperties.COMPONENT_BUILDER_METADATA_PROPERTY
In addition fields without a setter are marked with MetadataProperties.READ_ONLY_METADATA_PROPERTY, and collections and maps using MetadataProperties.COLLECTION_ELEMENT_TYPE_METADATA_PROPERTY, MetadataProperties.MAP_KEY_TYPE_METADATA_PROPERTY and MetadataProperties.MAP_VALUE_TYPE_METADATA_PROPERTY. |
protected <T,C extends Collection<T>> |
buildCollectionField(Property<?,T> elementProperty,
Class<? extends Collection<?>> collectionType,
PropertyComponentBuilder callbackFactory)
Builds a collection field.
|
protected <T> Collection<ComponentConfigurator<T>> |
buildComponentConfigurators(Class<T> dataType)
Builds
ComponentConfigurators for a given data type:
components have their label set up according to MetadataProperties.CAPTION_METADATA_PROPERTY or 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
|
protected Collection<ComponentGroupConfigurator> |
buildComponentGroupConfigurators()
Builds
ComponentGroupConfigurators:
each component in a named group has style names added to it (obtained from getGroupComponentStyleNames()
|
protected <K,V> MapField<K,V> |
buildMapField(Property<?,K> keyProperty,
Property<?,V> valueProperty,
PropertyComponentBuilder callbackFactory)
Builds a map field.
|
<T> ObjectField<T> |
configureObjectField(ObjectField<T> objectField)
Configures a given object field.
|
CollectionLayoutProvider<?> |
getCollectionFieldLayoutProvider()
Returns a
CollectionLayoutProvider to be used in new CollectionFields. |
<E,C extends Collection<E>> |
getEmptyCollectionProvider(Class<C> type)
Returns an empty collection provider for a given collection type.
|
<K,V> com.vaadin.flow.function.SerializableSupplier<Map<K,V>> |
getEmptyMapSupplier()
Returns a supplier for an empty map.
|
Collection<String> |
getGroupComponentStyleNames()
Returns styles to be added to each component in a group in
ObjectField. |
Collection<String> |
getGroupLayoutStyleNames()
Returns styles to be added to each group layout in an
ObjectField. |
<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> |
getMapEntryFieldLayoutProvider()
Returns a way to obtain a layout for a
MapEntryField used in MapFields. |
CollectionLayoutProvider<?> |
getMapFieldLayoutProvider()
Returns a
CollectionLayoutProvider for new MapFields. |
<L extends com.vaadin.flow.component.Component & com.vaadin.flow.component.HasComponents> |
getObjectFieldGroupLayoutProvider()
Returns a way to obtain layouts for each group in an
ObjectField. |
<L extends com.vaadin.flow.component.Component & com.vaadin.flow.component.HasComponents> |
getObjectFieldLayoutProvider()
Returns a way to obtain layouts for new
ObjectFields. |
<E,C extends Collection<E>> |
registerEmptyCollectionProvider(Class<C> collectionType,
com.vaadin.flow.function.SerializableSupplier<C> supplier)
Registers an empty collection provider for a given collection type.
|
<T> void |
registerInstanceProvider(Class<T> type,
com.vaadin.flow.function.SerializableSupplier<T> supplier)
Registers an instance provider for a given type.
|
void |
setCollectionFieldLayoutProvider(CollectionLayoutProvider<?> collectionFieldLayoutProvider)
Sets a new
CollectionLayoutProvider to be used in new CollectionFields. |
void |
setEmptyMapSupplier(com.vaadin.flow.function.SerializableSupplier<Map<?,?>> emptyMapSupplier)
Sets a supplier for empty maps.
|
void |
setGroupComponentStyleNames(Collection<String> groupComponentStyleNames)
Sets new styles to be added to each component in a group in
ObjectField. |
void |
setGroupLayoutStyleNames(Collection<String> groupLayoutStyleNames)
Sets new styles to be added to each group layout in an
ObjectField. |
<L extends com.vaadin.flow.component.Component & com.vaadin.flow.component.HasComponents> |
setMapEntryFieldLayoutProvider(com.vaadin.flow.function.SerializableSupplier<L> mapEntryFieldLayoutProvider)
Sets a new way to obtain layouts for
MapEntryField in MapField. |
void |
setMapFieldLayoutProvider(CollectionLayoutProvider<?> mapFieldLayoutProvider)
Sets a new
CollectionLayoutProvider to be used in new MapFields. |
<L extends com.vaadin.flow.component.Component & com.vaadin.flow.component.HasComponents> |
setObjectFieldGroupLayoutProvider(com.vaadin.flow.function.SerializableSupplier<L> objectFieldGroupLayoutProvider)
Sets a new way to obtain layouts for each group in an
ObjectField. |
<L extends com.vaadin.flow.component.Component & com.vaadin.flow.component.HasComponents> |
setObjectFieldLayoutProvider(com.vaadin.flow.function.SerializableSupplier<L> objectFieldLayoutProvider)
Sets a new way to obtain layouts for new
ObjectFields. |
protected <T,C extends Collection<T>> CollectionField<T,C> buildCollectionField(Property<?,T> elementProperty, Class<? extends Collection<?>> collectionType, PropertyComponentBuilder callbackFactory)
T - Type of element in the collection.C - Type of collection.elementProperty - Property for the element of the collection.collectionType - Type of the collection.callbackFactory - Callback factory to build components.CollectionField.protected <K,V> MapField<K,V> buildMapField(Property<?,K> keyProperty, Property<?,V> valueProperty, PropertyComponentBuilder callbackFactory)
K - Type of key.V - Type of value.keyProperty - Property for the key of the map.valueProperty - Property for the value of the map.callbackFactory - Factory to produce components.MapField.protected PropertyComponentBuilder buildAndConfigureComponentBuilder()
SimplePropertyComponentBuilder and configures it for building most default components:MetadataProperties.SHOW_AS_COMPONENT_METADATA_PROPERTY as requestedSuperCheckboxSuperIntegerFieldSuperLongFieldSuperDoubleFieldBigDecimal properties as SuperBigDecimalFieldLocalDate properties as SuperDatePickerLocalDateTime properties as SuperDateTimePickerString properties as either SuperTextField or SuperTextArea (depending on MetadataProperties.MULTILINE_METADATA_PROPERTY)CollectionFieldMapFieldObjectField using this factory as default (that falls back to LabelField)SimplePropertyComponentBuilder.protected PropertyProvider buildAndConfigurePropertyProvider()
ReflectivePropertyProvider and configures it to a typical use case based on annotations:FieldGroup is mapped to MetadataProperties.GROUP_METADATA_PROPERTYFieldOrder is mapped to MetadataProperties.ORDER_METADATA_PROPERTYBigField is mapped to MetadataProperties.MULTILINE_METADATA_PROPERTYFieldCaption is mapped to MetadataProperties.CAPTION_METADATA_PROPERTYShowFieldAs is mapped to MetadataProperties.SHOW_AS_COMPONENT_METADATA_PROPERTYBuildFieldWith is mapped to MetadataProperties.COMPONENT_BUILDER_METADATA_PROPERTYMetadataProperties.READ_ONLY_METADATA_PROPERTY, and collections and maps using MetadataProperties.COLLECTION_ELEMENT_TYPE_METADATA_PROPERTY, MetadataProperties.MAP_KEY_TYPE_METADATA_PROPERTY and MetadataProperties.MAP_VALUE_TYPE_METADATA_PROPERTY.ReflectivePropertyProvider.protected PropertyGroupingProvider buildAndConfigureGroupingProvider()
PropertyGroupingProvider based on presence of MetadataProperties.GROUP_METADATA_PROPERTY and MetadataProperties.ORDER_METADATA_PROPERTY.MetadataBasedGroupingProvider.protected <T> Collection<ComponentConfigurator<T>> buildComponentConfigurators(Class<T> dataType)
ComponentConfigurators for a given data type:MetadataProperties.CAPTION_METADATA_PROPERTY or the field nameMetadataProperties.READ_ONLY_METADATA_PROPERTYMetadataProperties.COMPONENT_STYLE_METADATA_PROPERTYMetadataProperties.COMPONENT_ID_METADATA_PROPERTYT - Type of object.dataType - Type of object (the type of the ObjectField the returned configurators will be added to).null, but possibly empty collection.protected PropertyGroupLayoutProvider buildAndConfigureGroupLayoutProvider()
PropertyGroupLayoutProvider that provides a separate layout for a group with two or more properties in it.
Each produced layout has style names added (from getGroupLayoutStyleNames()), if possible.PropertyGroupLayoutProvider.protected Collection<ComponentGroupConfigurator> buildComponentGroupConfigurators()
ComponentGroupConfigurators:getGroupComponentStyleNames()null collection of ComponentGroupConfigurators.public <T> ObjectField<T> buildAndConfigureObjectField(Class<T> type)
ObjectField for a given type, using instance provider from getInstanceProvider(Class).T - Type of object to display.type - Type to build an ObjectField for.ObjectField.public <T> ObjectField<T> buildAndConfigureObjectField(Class<T> type, boolean repaint)
ObjectField for a given type, using instance provider from getInstanceProvider(Class).T - Type of object to display.type - Type to build an ObjectField for.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.ObjectField.public <T> ObjectField<T> buildAndConfigureObjectField(Class<T> type, com.vaadin.flow.function.SerializableSupplier<T> newInstanceProvider)
ObjectField for a given type using given instance provider.T - Type of object to display.type - Type to build an ObjectField for.newInstanceProvider - A way to produce new instances of the object.ObjectField.public <T> ObjectField<T> buildAndConfigureObjectField(Class<T> type, com.vaadin.flow.function.SerializableSupplier<T> newInstanceProvider, boolean repaint)
ObjectField for a given type using given instance provider.T - Type of object to display.type - Type to build an ObjectField for.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.ObjectField.public final <T> ObjectField<T> configureObjectField(ObjectField<T> objectField)
ObjectField.withPropertyProvider(PropertyProvider) using buildAndConfigurePropertyProvider()ObjectField.withPropertyGroupingProvider(PropertyGroupingProvider) using buildAndConfigureGroupingProvider()ObjectField.withPropertyComponentBuilder(PropertyComponentBuilder) using buildAndConfigureComponentBuilder()ObjectField.withGroupLayoutProvider(PropertyGroupLayoutProvider) using buildAndConfigureGroupLayoutProvider()ObjectField.withComponentConfigurators(Collection) using buildComponentConfigurators(Class)ObjectField.withComponentGroupConfigurators(Collection) using buildComponentGroupConfigurators()T - Type of object to display.objectField - The passed parameter, but with the above-mentioned configuration applied.public <T> void registerInstanceProvider(Class<T> type, com.vaadin.flow.function.SerializableSupplier<T> supplier)
ObjectFields.T - Type.type - Type to register instance provider for.supplier - A method called to create a new instance.public <T> com.vaadin.flow.function.SerializableSupplier<T> getInstanceProvider(Class<T> type)
T - Type.type - Type to return the instance provider for.public <E,C extends Collection<E>> void registerEmptyCollectionProvider(Class<C> collectionType, com.vaadin.flow.function.SerializableSupplier<C> supplier)
E - Element type. Ignored.C - Collection type. Ignored.collectionType - Base collection type.supplier - Supplier for an empty collection.public <E,C extends Collection<E>> com.vaadin.flow.function.SerializableSupplier<C> getEmptyCollectionProvider(Class<C> type)
E - Element type. Ignored.C - Collection type. Ignored.type - Type of collection.buildCollectionField(Property, Class, PropertyComponentBuilder).public <K,V> com.vaadin.flow.function.SerializableSupplier<Map<K,V>> getEmptyMapSupplier()
buildMapField(Property, Property, PropertyComponentBuilder).public void setEmptyMapSupplier(com.vaadin.flow.function.SerializableSupplier<Map<?,?>> emptyMapSupplier)
emptyMapSupplier - A way to produce an empty map.public CollectionLayoutProvider<?> getCollectionFieldLayoutProvider()
CollectionLayoutProvider to be used in new CollectionFields.CollectionLayoutProvider. Used in buildCollectionField(Property, Class, PropertyComponentBuilder).public void setCollectionFieldLayoutProvider(CollectionLayoutProvider<?> collectionFieldLayoutProvider)
CollectionLayoutProvider to be used in new CollectionFields.collectionFieldLayoutProvider - A CollectionLayoutProvider.public CollectionLayoutProvider<?> getMapFieldLayoutProvider()
CollectionLayoutProvider for new MapFields.CollectionLayoutProvider. Used in buildMapField(Property, Property, PropertyComponentBuilder).public void setMapFieldLayoutProvider(CollectionLayoutProvider<?> mapFieldLayoutProvider)
CollectionLayoutProvider to be used in new MapFields.mapFieldLayoutProvider - A CollectionLayoutProvider.public <L extends com.vaadin.flow.component.Component & com.vaadin.flow.component.HasComponents> com.vaadin.flow.function.SerializableSupplier<L> getMapEntryFieldLayoutProvider()
MapEntryField used in MapFields.L - Type of layout.buildMapField(Property, Property, PropertyComponentBuilder).public <L extends com.vaadin.flow.component.Component & com.vaadin.flow.component.HasComponents> void setMapEntryFieldLayoutProvider(com.vaadin.flow.function.SerializableSupplier<L> mapEntryFieldLayoutProvider)
MapEntryField in MapField.L - Layout type.mapEntryFieldLayoutProvider - A new way to obtain layouts.public <L extends com.vaadin.flow.component.Component & com.vaadin.flow.component.HasComponents> com.vaadin.flow.function.SerializableSupplier<L> getObjectFieldLayoutProvider()
ObjectFields.L - Type of layout.public <L extends com.vaadin.flow.component.Component & com.vaadin.flow.component.HasComponents> void setObjectFieldLayoutProvider(com.vaadin.flow.function.SerializableSupplier<L> objectFieldLayoutProvider)
ObjectFields.L - Layout type.objectFieldLayoutProvider - Layout provider.public <L extends com.vaadin.flow.component.Component & com.vaadin.flow.component.HasComponents> com.vaadin.flow.function.SerializableSupplier<L> getObjectFieldGroupLayoutProvider()
ObjectField. This is used in buildAndConfigureGroupLayoutProvider().L - Layout type.public <L extends com.vaadin.flow.component.Component & com.vaadin.flow.component.HasComponents> void setObjectFieldGroupLayoutProvider(com.vaadin.flow.function.SerializableSupplier<L> objectFieldGroupLayoutProvider)
ObjectField.L - Type of layout.objectFieldGroupLayoutProvider - A layout provider.public Collection<String> getGroupLayoutStyleNames()
ObjectField. This is used in buildAndConfigureGroupLayoutProvider().null collection of styles.public void setGroupLayoutStyleNames(Collection<String> groupLayoutStyleNames)
ObjectField. Each style name will have .format(groupName) applied to it.groupLayoutStyleNames - Style names.public Collection<String> getGroupComponentStyleNames()
ObjectField. This is used in buildComponentGroupConfigurators().null collection of styles.public void setGroupComponentStyleNames(Collection<String> groupComponentStyleNames)
ObjectField. Each style name will have .format(groupName) applied to it.groupComponentStyleNames - Style names.Copyright © 2023 Miki. All rights reserved.