public class SimplePropertyComponentBuilder extends Object implements PropertyComponentBuilder
PropertyComponentBuilder.
In general, it allows building components based on Predicate<Property> and provides some helper methods for common use cases.| Modifier and Type | Field and Description |
|---|---|
static FieldBuilder<?> |
DEFAULT_BUILDER
Default field builder used when no registered predicate matches given property.
|
| Constructor and Description |
|---|
SimplePropertyComponentBuilder() |
| Modifier and Type | Method and Description |
|---|---|
<P,C extends com.vaadin.flow.component.Component & com.vaadin.flow.component.HasValue<?,P>> |
buildPropertyField(Property<?,P> property)
Builds a component for a given property.
|
FieldBuilder<?> |
getDefaultBuilder()
Returns the current default
FieldBuilder, i.e. |
Map<Predicate<Property<?,?>>,FieldBuilder<?>> |
getRegisteredBuilders()
Returns the builders registered so far.
|
boolean |
isDefaultLabel()
Checks if the produced component should have its label set to default.
|
static Predicate<Property<?,?>> |
isExactlyType(Class<?> type)
Returns a
Predicate that checks if a property is exactly of given type. |
static Predicate<Property<?,?>> |
isOfType(Class<?> type)
Returns a
Predicate that checks if a property is of the given type (i.e. |
<P> void |
registerBuilder(Class<P> valueType,
FieldBuilder<P> builder)
Registers a given
builder with a predicate that checks for a given (not exact) type. |
<P> void |
registerBuilder(Predicate<Property<?,P>> predicate,
FieldBuilder<P> builder)
Registers a given
Predicate and its matching FieldBuilder. |
<P,C extends com.vaadin.flow.component.Component & com.vaadin.flow.component.HasValue<?,P>> |
registerType(Class<P> valueType,
com.vaadin.flow.function.SerializableSupplier<C> componentSupplier)
Registers a builder for a given
Component for properties of exactly the given valueType. |
void |
setDefaultBuilder(FieldBuilder<?> defaultBuilder)
Sets a new default
FieldBuilder, i.e. |
void |
setDefaultLabel(boolean defaultLabel)
Controls whether the produced component should have its label set to default.
|
SimplePropertyComponentBuilder |
withDefaultBuilder(FieldBuilder<?> builder)
Chains
setDefaultBuilder(FieldBuilder) and returns itself. |
SimplePropertyComponentBuilder |
withDefaultLabel()
Chains
setDefaultLabel(boolean) with true and returns itself. |
SimplePropertyComponentBuilder |
withDefaultLabel(boolean state)
Chains
setDefaultLabel(boolean) and returns itself. |
SimplePropertyComponentBuilder |
withoutDefaultLabel()
Chains
setDefaultLabel(boolean) with false and returns itself. |
<P> SimplePropertyComponentBuilder |
withRegisteredBuilder(Class<P> valueType,
FieldBuilder<P> builder)
Chains
registerBuilder(Class, FieldBuilder) and returns itself. |
<P> SimplePropertyComponentBuilder |
withRegisteredBuilder(Predicate<Property<?,P>> predicate,
FieldBuilder<P> builder)
Chains
registerBuilder(Predicate, FieldBuilder) and returns itself. |
<P,C extends com.vaadin.flow.component.Component & com.vaadin.flow.component.HasValue<?,P>> |
withRegisteredType(Class<P> valueType,
com.vaadin.flow.function.SerializableSupplier<C> componentSupplier)
Chains
registerType(Class, SerializableSupplier) and returns itself. |
public static final FieldBuilder<?> DEFAULT_BUILDER
public static Predicate<Property<?,?>> isExactlyType(Class<?> type)
Predicate that checks if a property is exactly of given type.type - Type to check.Predicate that checks if the given type is equal to the property's type.public static Predicate<Property<?,?>> isOfType(Class<?> type)
Predicate that checks if a property is of the given type (i.e. is a subclass or implementation of it).type - Type to check.Predicate that evaluates to type.isAssignableFrom(property.getType()).public <P,C extends com.vaadin.flow.component.Component & com.vaadin.flow.component.HasValue<?,P>> Optional<C> buildPropertyField(Property<?,P> property)
PropertyComponentBuilderbuildPropertyField in interface PropertyComponentBuilderP - Type of the value of the property.C - Component to be returned.property - Property to build a component for.public Map<Predicate<Property<?,?>>,FieldBuilder<?>> getRegisteredBuilders()
null, but possibly empty, Map of registered FieldBuilders with matching Predicates.public <P,C extends com.vaadin.flow.component.Component & com.vaadin.flow.component.HasValue<?,P>> void registerType(Class<P> valueType, com.vaadin.flow.function.SerializableSupplier<C> componentSupplier)
Component for properties of exactly the given valueType.P - Value type.C - Component type.valueType - Type of the property.componentSupplier - Supplier of component capable of displaying value of the given type.public final <P,C extends com.vaadin.flow.component.Component & com.vaadin.flow.component.HasValue<?,P>> SimplePropertyComponentBuilder withRegisteredType(Class<P> valueType, com.vaadin.flow.function.SerializableSupplier<C> componentSupplier)
registerType(Class, SerializableSupplier) and returns itself.P - Value type.C - Component type.valueType - Type of the property.componentSupplier - Supplier of component capable of displaying value of the given type.registerType(Class, SerializableSupplier)public <P> void registerBuilder(Class<P> valueType, FieldBuilder<P> builder)
builder with a predicate that checks for a given (not exact) type.P - Property value type.valueType - Type to check.builder - Builder to register.public <P> void registerBuilder(Predicate<Property<?,P>> predicate, FieldBuilder<P> builder)
Predicate and its matching FieldBuilder.P - Property value type.predicate - Predicate.builder - Builder.public final <P> SimplePropertyComponentBuilder withRegisteredBuilder(Class<P> valueType, FieldBuilder<P> builder)
registerBuilder(Class, FieldBuilder) and returns itself.P - Property value type.valueType - Value type to check.builder - Builder.registerBuilder(Class, FieldBuilder)public final <P> SimplePropertyComponentBuilder withRegisteredBuilder(Predicate<Property<?,P>> predicate, FieldBuilder<P> builder)
registerBuilder(Predicate, FieldBuilder) and returns itself.P - Property value type.predicate - Predicate to check.builder - Builder.registerBuilder(Predicate, FieldBuilder)public boolean isDefaultLabel()
true (default), the created component will have its label set to human-readable version of the property name, if it is possible.public void setDefaultLabel(boolean defaultLabel)
defaultLabel - When true, the created component will have its label set to human-readable version of the property name, if it is possible.public final SimplePropertyComponentBuilder withDefaultLabel()
setDefaultLabel(boolean) with true and returns itself.setDefaultLabel(boolean),
withoutDefaultLabel(),
withDefaultLabel(boolean)public final SimplePropertyComponentBuilder withoutDefaultLabel()
setDefaultLabel(boolean) with false and returns itself.setDefaultLabel(boolean),
withDefaultLabel(),
withDefaultLabel(boolean)public final SimplePropertyComponentBuilder withDefaultLabel(boolean state)
setDefaultLabel(boolean) and returns itself.state - When true, the created component will have its label set to human-readable version of the property name, if it is possible.public void setDefaultBuilder(FieldBuilder<?> defaultBuilder)
FieldBuilder, i.e. the builder used when none of the registered builders are suitable.defaultBuilder - New builder. When null is passed, DEFAULT_BUILDER will be used instead.public final FieldBuilder<?> getDefaultBuilder()
FieldBuilder, i.e. the builder used when none of the registered builders are suitable.FieldBuilder. Never null.public final SimplePropertyComponentBuilder withDefaultBuilder(FieldBuilder<?> builder)
setDefaultBuilder(FieldBuilder) and returns itself.builder - Builder to use.setDefaultBuilder(FieldBuilder)Copyright © 2024 Miki. All rights reserved.