Class AbstractFieldBuilder<S extends AbstractFieldBuilder<S,T>,T>
- Type Parameters:
S
- subclass typeT
- edited model type
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
AbstractGridFieldBuilder
FieldBuilder
-like classes.
The annotation classes defined in this class, which are common to all FieldBuilder
-like classes, may
be referenced using the concrete subclass name for consistency. For example, code can reference
@FieldBuilder.Binding
instead of @AbstractFieldBuilder.Binding
.
See FieldBuilder
for details and the standard implementation.
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic @interface
Specifies properties of theBinder
binding itself.class
FieldBuilder
static configuration information for one bean property.static class
Holds static information gathered from scanning@FieldBuilder.FieldDefault
annotations.static @interface
Causes the generated field to be automatically enabled or disabled based on the value of some other controlling field(s).static @interface
Declare alternate default values for properties of the Vaadin fields created by@FieldBuilder
.static @interface
Configures howFieldBuilder.addFieldComponents()
adds a generated field to aFormLayout
.static @interface
Causes the field that would otherwise be used for a property to be wrapped in aNullableField
, which adds aCheckbox
that controls whether the value is null or not.static @interface
Specifies that the annotated method will create a field suitable for editing the specified property. -
Field Summary
-
Constructor Summary
ModifierConstructorDescriptionprotected
AbstractFieldBuilder
(Class<T> type) Constructor.protected
AbstractFieldBuilder
(AbstractFieldBuilder<S, T> original) Static information copy constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addFieldComponents
(FormLayout formLayout) Add the fields' components created by this instance in the previous call tobindFields()
to the givenFormLayout
.protected void
applyFieldDefaultAnnotations
(HasValue<?, ?> field, Class<?> modelType) Apply defaults derived from@FieldBuilder.FieldDefault
annotations to the given field.void
bindFields
(Binder<? extends T> binder) Create, configure, and bind fields into the givenBinder
.protected FieldComponent<?>
buildDeclarativeField
(AbstractFieldBuilder<S, T>.BindingInfo bindingInfo) Construct and configure a field based on a@FieldBuilder.Foo
declarative annotation.protected FieldComponent<?>
buildProvidedField
(AbstractFieldBuilder<S, T>.BindingInfo bindingInfo, MethodAnnotationScanner<T, AbstractFieldBuilder.ProvidesField>.MethodInfo methodInfo, Object bean) Construct a field and corresponding component using a@FieldBuilder.ProvidesField
annotated method.protected AbstractFieldBuilder<S,
T>.BindingInfo createBindingInfo
(Method method, String propertyName, Annotation annotation, AbstractFieldBuilder.Binding binding, AbstractFieldBuilder.FormLayout formLayout, AbstractFieldBuilder.NullifyCheckbox nullifyCheckbox, AbstractFieldBuilder.EnabledBy enabledBy, BiFunction<AbstractFieldBuilder<S, T>.BindingInfo, ? super T, FieldComponent<?>> fieldBuilder) Create aAbstractFieldBuilder<S extends AbstractFieldBuilder<S,
.T>, T>.BindingInfo protected Method
Get the method in this class that has all of the widget annotations (with default values) applied to it.protected String
Get the name of the method in this class that has all of the widget annotations (with default values) applied to it.protected Stream<Class<? extends Annotation>>
Get all of the widget annotation types defined for this class.protected <A extends Annotation>
AgetDefaultsFor
(A annotation) Get an instance of the given widget annotation that has all default values.protected <A extends Annotation>
AgetDefaultsFor
(Class<A> annotationType) Get an instance of the given widget annotation type with all default values.Map<String,
FieldComponent<?>> Obtain the fields created by this instance in the most recent call tobindFields()
.protected String
Get the name of the annotation property that specifies the implementation class.Get the default values discovered by this instance (if any) from scanned@FieldBuilder.FieldDefault
annotations.Get all of the properties discovered by this instance from scanned annotations.getType()
Get the type associated with this instance.protected <F> F
instantiate
(Class<F> expectedType, AbstractFieldBuilder<S, T>.BindingInfo bindingInfo, Annotation annotation, String propertyName) Instantiate a field (or whatever) from the givenClass
-valued annotation property.protected <T> T
instantiate
(Class<T> type, AbstractFieldBuilder<S, T>.BindingInfo bindingInfo) Instantiate a field (or whatever) from the givenClass
.protected FieldBuilderContext
newFieldBuilderContext
(AbstractFieldBuilder<S, T>.BindingInfo bindingInfo) Create anFieldBuilderContext
from the given method and annotation.protected void
Introspect the configured class for defined@FieldBuilder.Foo
,@FieldBuilder.ProvidesField
,@FieldBuilder.Binding
, and@FieldBuilder.FormLayout
annotations.protected <M> Map<String,
AbstractFieldBuilder.DefaultInfo> scanForFieldDefaultAnnotations
(Class<M> modelType) Scan the given model type for@FieldBuilder.FieldDefault
annotations.
-
Field Details
-
DEFAULT_IMPLEMENTATION_PROPERTY_NAME
- See Also:
-
DEFAULT_ANNOTATION_DEFAULTS_METHOD_NAME
- See Also:
-
-
Constructor Details
-
AbstractFieldBuilder
Constructor.- Parameters:
type
- backing object type- Throws:
IllegalArgumentException
- iftype
is null
-
AbstractFieldBuilder
Static information copy constructor.Using this constructor is more efficient than repeatedly scanning the same classes for the same annotations.
Only the static information gathered by this instance by scanning for annotations is copied. Any previously built fields are not copied.
- Parameters:
original
- original instance- Throws:
IllegalArgumentException
- iforiginal
is null
-
-
Method Details
-
getType
Get the type associated with this instance.- Returns:
- configured type
-
getScannedProperties
Get all of the properties discovered by this instance from scanned annotations.This represents static information gathered by this instance by scanning the class hierarchy during construction.
The returned
Map
iterates in order of@FieldBuilder.FormLayout.order()
, then by property name.- Returns:
- unmodifiable mapping of scanned properties keyed by property name
-
getScannedFieldDefaults
Get the default values discovered by this instance (if any) from scanned@FieldBuilder.FieldDefault
annotations.The returned map is keyed by the return types of methods found with
@FieldBuilder.Foo
declarative annotations.This represents static information gathered by this instance by scanning the class hierarchy during construction.
- Returns:
- unmodifiable mapping from model class to field defaults keyed by field property name
-
bindFields
Create, configure, and bind fields into the givenBinder
.If the
binder
does not have a bean currently bound to it, then any@FieldBuilder.ProvidesField
annotations on instance methods will generate an error.After this method completes, the associated components can be obtained via
getFieldComponents()
or added to aFormLayout
viaaddFieldComponents()
.- Parameters:
binder
- target binder- Throws:
IllegalArgumentException
- if invalid annotation use is encounteredIllegalArgumentException
- ifbinder
is null
-
getFieldComponents
Obtain the fields created by this instance in the most recent call tobindFields()
.The returned
Map
iterates in order of@FieldBuilder.FormLayout.order()
, then by property name.- Returns:
- unmodifiable mapping from property name to field/component
- Throws:
IllegalStateException
- ifbindFields()
has not yet been invoked
-
addFieldComponents
Add the fields' components created by this instance in the previous call tobindFields()
to the givenFormLayout
.The field components are added in order of
@FieldBuilder.FormLayout.order()
, then by property name.- Parameters:
formLayout
- target layout- Throws:
IllegalArgumentException
- ifformLayout
is nullIllegalStateException
- ifbindFields()
has not yet been invokedIllegalStateException
- if this method is invoked twice in a row without an intervening call tobindFields()
-
scanForAnnotations
protected void scanForAnnotations()Introspect the configured class for defined@FieldBuilder.Foo
,@FieldBuilder.ProvidesField
,@FieldBuilder.Binding
, and@FieldBuilder.FormLayout
annotations.Note: this method is invoked from the
AbstractFieldBuilder
constructor.- Throws:
IllegalArgumentException
- if an invalid use of an annotation is encountered
-
scanForFieldDefaultAnnotations
protected <M> Map<String,AbstractFieldBuilder.DefaultInfo> scanForFieldDefaultAnnotations(Class<M> modelType) Scan the given model type for@FieldBuilder.FieldDefault
annotations.- Type Parameters:
M
- model type- Parameters:
modelType
- model type for some edited property- Returns:
- mapping from field property name to default info for that property (possibly empty)
- Throws:
IllegalArgumentException
- ifmodelType
is null
-
buildDeclarativeField
protected FieldComponent<?> buildDeclarativeField(AbstractFieldBuilder<S, T>.BindingInfo bindingInfo) Construct and configure a field based on a@FieldBuilder.Foo
declarative annotation.- Parameters:
bindingInfo
- field binding context- Returns:
- new field
-
applyFieldDefaultAnnotations
Apply defaults derived from@FieldBuilder.FieldDefault
annotations to the given field.- Parameters:
field
- the field being configuredmodelType
- the type of the property edited byfield
- Throws:
IllegalArgumentException
- if either parameter is null
-
buildProvidedField
protected FieldComponent<?> buildProvidedField(AbstractFieldBuilder<S, T>.BindingInfo bindingInfo, MethodAnnotationScanner<T, AbstractFieldBuilder.ProvidesField>.MethodInfo methodInfo, Object bean) Construct a field and corresponding component using a@FieldBuilder.ProvidesField
annotated method.- Parameters:
bindingInfo
- field binding contextmethodInfo
- scanned annotation contextbean
- binder bean, or null if none- Returns:
- new field
-
getDefaultsFor
Get an instance of the given widget annotation that has all default values.- Type Parameters:
A
- annotation type- Parameters:
annotation
- the annotation to get defautls for- Returns:
- default annotation, or null if not a widget annotation
- Throws:
IllegalArgumentException
- ifannotation
is not a widget annotationIllegalArgumentException
- ifannotation
is null
-
getDefaultsFor
Get an instance of the given widget annotation type with all default values.- Type Parameters:
A
- annotation type- Parameters:
annotationType
- the annotation type to get defautls for- Returns:
- default annotation, or null if not a widget annotation
- Throws:
IllegalArgumentException
- ifannotationType
is not a widget annotation typeIllegalArgumentException
- ifannotationType
is null
-
getDeclarativeAnnotationTypes
Get all of the widget annotation types defined for this class.The implementation in
AbstractFieldBuilder
returns the types of all annotations found on the annotation defaults method.- Returns:
- widget annotation types
-
createBindingInfo
protected AbstractFieldBuilder<S,T>.BindingInfo createBindingInfo(Method method, String propertyName, Annotation annotation, AbstractFieldBuilder.Binding binding, AbstractFieldBuilder.FormLayout formLayout, AbstractFieldBuilder.NullifyCheckbox nullifyCheckbox, AbstractFieldBuilder.EnabledBy enabledBy, BiFunction<AbstractFieldBuilder<S, T>.BindingInfo, ? super T, FieldComponent<?>> fieldBuilder) Create aAbstractFieldBuilder<S extends AbstractFieldBuilder<S,
.T>, T>.BindingInfo - Parameters:
method
- annotated methodpropertyName
- property nameannotation
- annotation found onmethod
binding
- associated@FieldBuilder.Binding
annotation, if anyformLayout
- associated@FieldBuilder.FormLayout
annotation, if anynullifyCheckbox
- associated from@FieldBuilder.NullifyCheckbox
, if anyenabledBy
- associated from@FieldBuilder.EnabledBy
, if anyfieldBuilder
- builds the field- Returns:
- new
AbstractFieldBuilder<S extends AbstractFieldBuilder<S,
, or null if this property should be ignoredT>, T>.BindingInfo - Throws:
IllegalArgumentException
- ifmethod
,propertyName
,annotation
, orfieldBuilder
is null
-
getAnnotationDefaultsMethod
Get the method in this class that has all of the widget annotations (with default values) applied to it.- Returns:
- defaults method name, never null
-
getAnnotationDefaultsMethodName
Get the name of the method in this class that has all of the widget annotations (with default values) applied to it.The implementation in
AbstractFieldBuilder
returns "annotationDefaultsMethod".- Returns:
- defaults method name, never null
-
getImplementationPropertyName
Get the name of the annotation property that specifies the implementation class.The implementation in
AbstractFieldBuilder
returns "implementation".- Returns:
- implementation property name, never null
-
instantiate
protected <F> F instantiate(Class<F> expectedType, AbstractFieldBuilder<S, T>.BindingInfo bindingInfo, Annotation annotation, String propertyName) Instantiate a field (or whatever) from the givenClass
-valued annotation property.We use the
FieldBuilderContext
constructor if available, otherwise default constructor.- Type Parameters:
F
- field type- Parameters:
expectedType
- expected type of thing we're instantiatingbindingInfo
- binding contextannotation
- annotation withClass
-valued propertypropertyName
- annotation property name having typeClass
- Throws:
IllegalArgumentException
- if any parameter is null
-
instantiate
Instantiate a field (or whatever) from the givenClass
.We use the
FieldBuilderContext
constructor if available, otherwise default constructor.- Parameters:
type
- expected type of the thing we're instantiatingbindingInfo
- binding context- Throws:
IllegalArgumentException
- if any parameter is null
-
newFieldBuilderContext
protected FieldBuilderContext newFieldBuilderContext(AbstractFieldBuilder<S, T>.BindingInfo bindingInfo) Create anFieldBuilderContext
from the given method and annotation.The implementation in
AbstractFieldBuilder
creates aFieldBuilderContextImpl
.- Parameters:
bindingInfo
- binding context- Throws:
IllegalArgumentException
- ifbindingInfo
is null
-