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
Nested ClassesModifier and TypeClassDescriptionstatic @interfaceSpecifies properties of theBinderbinding itself.classFieldBuilderstatic configuration information for one bean property.static classHolds static information gathered from scanning@FieldBuilder.FieldDefaultannotations.static @interfaceCauses the generated field to be automatically enabled or disabled based on the value of some other controlling field(s).static @interfaceDeclare alternate default values for properties of the Vaadin fields created by@FieldBuilder.static @interfaceConfigures howFieldBuilder.addFieldComponents()adds a generated field to aFormLayout.static @interfaceCauses the field that would otherwise be used for a property to be wrapped in aNullableField, which adds aCheckboxthat controls whether the value is null or not.static @interfaceSpecifies that the annotated method will create a field suitable for editing the specified property. -
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractFieldBuilder(Class<T> type) Constructor.protectedAbstractFieldBuilder(AbstractFieldBuilder<S, T> original) Static information copy constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddFieldComponents(FormLayout formLayout) Add the fields' components created by this instance in the previous call tobindFields()to the givenFormLayout.protected voidapplyFieldDefaultAnnotations(HasValue<?, ?> field, Class<?> modelType) Apply defaults derived from@FieldBuilder.FieldDefaultannotations to the given field.voidbindFields(Binder<? extends T> binder) Create, configure, and bind fields into the givenBinder.protected Map<Class<? extends Annotation>, Annotation> Get all of the declarative widget annotation types defined for this class and their default values.protected FieldComponent<?> buildDeclarativeField(AbstractFieldBuilder<S, T>.BindingInfo bindingInfo) Construct and configure a field based on a@FieldBuilder.Foodeclarative 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.ProvidesFieldannotated 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 Map<String, FieldComponent<?>> Obtain the fields created by this instance in the most recent call tobindFields().protected StringGet the name of the annotation property that specifies the implementation class.Get the field property default values discovered by this instance (if any) from scanned@FieldBuilder.FieldDefaultannotations.Get all of the properties discovered by this instance from scanned annotations.getType()Get the type associated with this instance.protected <F> Finstantiate(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> Tinstantiate(Class<T> type, AbstractFieldBuilder<S, T>.BindingInfo bindingInfo) Instantiate a field (or whatever) from the givenClass.protected FieldBuilderContextnewFieldBuilderContext(AbstractFieldBuilder<S, T>.BindingInfo bindingInfo) Create anFieldBuilderContextfrom the given method and annotation.protected voidIntrospect the configured class for defined@FieldBuilder.Foo,@FieldBuilder.ProvidesField,@FieldBuilder.Binding, and@FieldBuilder.FormLayoutannotations.protected <M> Map<String, AbstractFieldBuilder.DefaultInfo> scanForFieldDefaultAnnotations(Class<M> modelType) Scan the given model type for@FieldBuilder.FieldDefaultannotations.
-
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- iftypeis 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- iforiginalis null
-
-
Method Details
-
getType
-
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
Mapiterates in order of@FieldBuilder.FormLayout.order(), then by property name.- Returns:
- unmodifiable mapping of scanned properties keyed by property name
-
getScannedFieldDefaults
Get the field property default values discovered by this instance (if any) from scanned@FieldBuilder.FieldDefaultannotations.The returned map is keyed by the return types of methods found with
@FieldBuilder.Foodeclarative 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
binderdoes not have a bean currently bound to it, then any@FieldBuilder.ProvidesFieldannotations on instance methods will generate an error.After this method completes, the associated components can be obtained via
getFieldComponents()or added to aFormLayoutviaaddFieldComponents().- Parameters:
binder- target binder- Throws:
IllegalArgumentException- if invalid annotation use is encounteredIllegalArgumentException- ifbinderis null
-
getFieldComponents
Obtain the fields created by this instance in the most recent call tobindFields().The returned
Mapiterates 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- ifformLayoutis 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.FormLayoutannotations.Note: this method is invoked from the
AbstractFieldBuilderconstructor.- 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.FieldDefaultannotations.- 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- ifmodelTypeis null
-
buildDeclarativeField
protected FieldComponent<?> buildDeclarativeField(AbstractFieldBuilder<S, T>.BindingInfo bindingInfo) Construct and configure a field based on a@FieldBuilder.Foodeclarative annotation.- Parameters:
bindingInfo- field binding context- Returns:
- new field
-
applyFieldDefaultAnnotations
Apply defaults derived from@FieldBuilder.FieldDefaultannotations 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.ProvidesFieldannotated method.- Parameters:
bindingInfo- field binding contextmethodInfo- scanned annotation contextbean- binder bean, or null if none- Returns:
- new field
-
buildDeclarativeAnnotationsMap
Get all of the declarative widget annotation types defined for this class and their default values.The implementation in
AbstractFieldBuildergleans this information using reflection by looking for a method named "annotationDefaultsMethod"<S extends AbstractFieldBuilder<S,T>, T> taking zero parameters declared by this class or some superclass and returning all annotations on that method. Subclasses may override this method to augment or modify this information. Entries in the map may have null values if defaults are handled differently in a subclass' overridden
buildDeclarativeField().- Returns:
- mutable mapping from widget annotation types to default values
-
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 onmethodbinding- associated@FieldBuilder.Bindingannotation, if anyformLayout- associated@FieldBuilder.FormLayoutannotation, 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, orfieldBuilderis null
-
getImplementationPropertyName
Get the name of the annotation property that specifies the implementation class.The implementation in
AbstractFieldBuilderreturns "implementation"<S extends AbstractFieldBuilder<S,T>, T>. - 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
FieldBuilderContextconstructor 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
FieldBuilderContextconstructor 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 anFieldBuilderContextfrom the given method and annotation.The implementation in
AbstractFieldBuildercreates aFieldBuilderContextImpl.- Parameters:
bindingInfo- binding context- Throws:
IllegalArgumentException- ifbindingInfois null
-