Class SimplePropertyComponentBuilder
java.lang.Object
org.vaadin.miki.superfields.object.builder.SimplePropertyComponentBuilder
- All Implemented Interfaces:
Serializable,PropertyComponentBuilder
Reference implementation of
PropertyComponentBuilder.
In general, it allows building components based on Predicate<Property> and provides some helper methods for common use cases.- Since:
- 2022-06-06
- Author:
- miki
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final FieldBuilder<?>Default field builder used when no registered predicate matches given property. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<P,C extends com.vaadin.flow.component.Component & com.vaadin.flow.component.HasValue<?, P>>
Optional<C>buildPropertyField(Property<?, P> property) Builds a component for a given property.final FieldBuilder<?>Returns the current defaultFieldBuilder, i.e.Map<Predicate<Property<?,?>>, FieldBuilder<?>> Returns the builders registered so far.booleanChecks if the produced component should have its label set to default.isExactlyType(Class<?> type) Returns aPredicatethat checks if a property is exactly of given type.Returns aPredicatethat checks if a property is of the given type (i.e.<P> voidregisterBuilder(Class<P> valueType, FieldBuilder<P> builder) Registers a givenbuilderwith a predicate that checks for a given (not exact) type.<P> voidregisterBuilder(Predicate<Property<?, P>> predicate, FieldBuilder<P> builder) Registers a givenPredicateand its matchingFieldBuilder.<P,C extends com.vaadin.flow.component.Component & com.vaadin.flow.component.HasValue<?, P>>
voidregisterType(Class<P> valueType, com.vaadin.flow.function.SerializableSupplier<C> componentSupplier) Registers a builder for a givenComponentfor properties of exactly the givenvalueType.voidsetDefaultBuilder(FieldBuilder<?> defaultBuilder) Sets a new defaultFieldBuilder, i.e.voidsetDefaultLabel(boolean defaultLabel) Controls whether the produced component should have its label set to default.withDefaultBuilder(FieldBuilder<?> builder) ChainssetDefaultBuilder(FieldBuilder)and returns itself.ChainssetDefaultLabel(boolean)withtrueand returns itself.withDefaultLabel(boolean state) ChainssetDefaultLabel(boolean)and returns itself.ChainssetDefaultLabel(boolean)withfalseand returns itself.final <P> SimplePropertyComponentBuilderwithRegisteredBuilder(Class<P> valueType, FieldBuilder<P> builder) ChainsregisterBuilder(Class, FieldBuilder)and returns itself.final <P> SimplePropertyComponentBuilderwithRegisteredBuilder(Predicate<Property<?, P>> predicate, FieldBuilder<P> builder) ChainsregisterBuilder(Predicate, FieldBuilder)and returns itself.final <P,C extends com.vaadin.flow.component.Component & com.vaadin.flow.component.HasValue<?, P>>
SimplePropertyComponentBuilderwithRegisteredType(Class<P> valueType, com.vaadin.flow.function.SerializableSupplier<C> componentSupplier) ChainsregisterType(Class, SerializableSupplier)and returns itself.
-
Field Details
-
DEFAULT_BUILDER
Default field builder used when no registered predicate matches given property. It always produces a result.
-
-
Constructor Details
-
SimplePropertyComponentBuilder
public SimplePropertyComponentBuilder()
-
-
Method Details
-
isExactlyType
Returns aPredicatethat checks if a property is exactly of given type.- Parameters:
type- Type to check.- Returns:
- A
Predicatethat checks if the giventypeis equal to the property's type.
-
isOfType
Returns aPredicatethat checks if a property is of the given type (i.e. is a subclass or implementation of it).- Parameters:
type- Type to check.- Returns:
- A
Predicatethat evaluates totype.isAssignableFrom(property.getType()).
-
buildPropertyField
public <P,C extends com.vaadin.flow.component.Component & com.vaadin.flow.component.HasValue<?, Optional<C> buildPropertyFieldP>> (Property<?, P> property) Description copied from interface:PropertyComponentBuilderBuilds a component for a given property.- Specified by:
buildPropertyFieldin interfacePropertyComponentBuilder- Type Parameters:
P- Type of the value of the property.C- Component to be returned.- Parameters:
property- Property to build a component for.- Returns:
- A component capable of displaying the value of the given property, if any.
-
getRegisteredBuilders
Returns the builders registered so far. Modifications of the returned map will affect this object.- Returns:
- A non-
null, but possibly empty,Mapof registeredFieldBuilders with matchingPredicates.
-
registerType
public <P,C extends com.vaadin.flow.component.Component & com.vaadin.flow.component.HasValue<?, void registerTypeP>> (Class<P> valueType, com.vaadin.flow.function.SerializableSupplier<C> componentSupplier) Registers a builder for a givenComponentfor properties of exactly the givenvalueType.- Type Parameters:
P- Value type.C- Component type.- Parameters:
valueType- Type of the property.componentSupplier- Supplier of component capable of displaying value of the given type.
-
withRegisteredType
public final <P,C extends com.vaadin.flow.component.Component & com.vaadin.flow.component.HasValue<?, SimplePropertyComponentBuilder withRegisteredTypeP>> (Class<P> valueType, com.vaadin.flow.function.SerializableSupplier<C> componentSupplier) ChainsregisterType(Class, SerializableSupplier)and returns itself.- Type Parameters:
P- Value type.C- Component type.- Parameters:
valueType- Type of the property.componentSupplier- Supplier of component capable of displaying value of the given type.- Returns:
- This.
- See Also:
-
registerBuilder
Registers a givenbuilderwith a predicate that checks for a given (not exact) type.- Type Parameters:
P- Property value type.- Parameters:
valueType- Type to check.builder- Builder to register.
-
registerBuilder
Registers a givenPredicateand its matchingFieldBuilder.- Type Parameters:
P- Property value type.- Parameters:
predicate- Predicate.builder- Builder.
-
withRegisteredBuilder
public final <P> SimplePropertyComponentBuilder withRegisteredBuilder(Class<P> valueType, FieldBuilder<P> builder) ChainsregisterBuilder(Class, FieldBuilder)and returns itself.- Type Parameters:
P- Property value type.- Parameters:
valueType- Value type to check.builder- Builder.- Returns:
- This.
- See Also:
-
withRegisteredBuilder
public final <P> SimplePropertyComponentBuilder withRegisteredBuilder(Predicate<Property<?, P>> predicate, FieldBuilder<P> builder) ChainsregisterBuilder(Predicate, FieldBuilder)and returns itself.- Type Parameters:
P- Property value type.- Parameters:
predicate- Predicate to check.builder- Builder.- Returns:
- This.
- See Also:
-
isDefaultLabel
public boolean isDefaultLabel()Checks if the produced component should have its label set to default.- Returns:
- When
true(default), the created component will have its label set to human-readable version of the property name, if it is possible.
-
setDefaultLabel
public void setDefaultLabel(boolean defaultLabel) Controls whether the produced component should have its label set to default.- Parameters:
defaultLabel- Whentrue, the created component will have its label set to human-readable version of the property name, if it is possible.
-
withDefaultLabel
ChainssetDefaultLabel(boolean)withtrueand returns itself.- Returns:
- This.
- See Also:
-
withoutDefaultLabel
ChainssetDefaultLabel(boolean)withfalseand returns itself.- Returns:
- This.
- See Also:
-
withDefaultLabel
ChainssetDefaultLabel(boolean)and returns itself.- Parameters:
state- Whentrue, the created component will have its label set to human-readable version of the property name, if it is possible.- Returns:
- This.
-
setDefaultBuilder
Sets a new defaultFieldBuilder, i.e. the builder used when none of the registered builders are suitable.- Parameters:
defaultBuilder- New builder. Whennullis passed,DEFAULT_BUILDERwill be used instead.
-
getDefaultBuilder
Returns the current defaultFieldBuilder, i.e. the builder used when none of the registered builders are suitable.- Returns:
- The current default
FieldBuilder. Nevernull.
-
withDefaultBuilder
ChainssetDefaultBuilder(FieldBuilder)and returns itself.- Parameters:
builder- Builder to use.- Returns:
- This.
- See Also:
-