public class FieldBuilder extends Object
FieldBuilder annotations.
The various nested FieldBuilder annotation types annotate Java bean property "getter" methods and specify
how the the bean properties of that class should be edited using AbstractFields. This allows all information
about how to edit a Java model class to stay contained within that class.
This class supports two types of annotations: first, the @ProvidesField annotation annotates
a method that knows how to build an AbstractField suitable for editing the bean property specified by
its value(). So @ProvidesField is analgous to
@ProvidesProperty, except that it defines an editing field rather than a container property.
The @FieldBuilder.AbstractField hierarchy annotations are the other type of annotation.
These annotations annotate a Java bean property getter method and specify how to configure an AbstractField subclass
instance to edit the bean property corresponding to the getter method.
@FieldBuilder.AbstractField is the top level annotation in a hierarchy of annotations
that correspond to the AbstractField class hierarchy. @FieldBuilder.AbstractField
corresponds to AbstractField, and its properties configure corresponding AbstractField properties.
More specific annotations correspond to the various AbstractField subclasses,
for example @FieldBuilder.ComboBox corresponds to ComboBox.
When using more specific annotations, the "superclass" annotations configure the corresponding superclass' properties.
A simple example shows how these annotations are used:
// Use a 10x40 TextArea to edit the "description" property
@FieldBuilder.AbstractField(caption = "Description:")
@FieldBuilder.TextArea(columns = 40, rows = 10)
public String getDescription() {
return this.description;
}
// Use my own custom field to edit the "foobar" property
@FieldBuilder.ProvidesField("foobar")
private MyCustomField createFoobarField() {
...
}
A FieldBuilder instance will read these annotations and build the fields automatically. For example:
// Create fields based on FieldGroup.* annotations
Person person = new Person("Joe Smith", 100);
BeanFieldGroup<Person> fieldGroup = FieldBuilder.buildFieldGroup(person);
// Layout the fields in a form
FormLayout layout = new FormLayout();
for (Field<?> field : fieldGroup.getFields())
layout.addComponent(field);
For all annotations in the @FieldBuilder.AbstractField hierarchy, leaving properties
set to their default values results in the default behavior.
AbstractSelect,
AbstractTextField,
CheckBox,
ComboBox,
DateField,
EnumComboBox,
ListSelect,
PasswordField,
TextArea,
TextField| Modifier and Type | Class and Description |
|---|---|
static interface |
FieldBuilder.AbstractField
Specifies how a Java property should be edited in Vaadin using an
AbstractField. |
static interface |
FieldBuilder.AbstractSelect
Specifies how a Java property should be edited in Vaadin using an
AbstractSelect. |
static interface |
FieldBuilder.AbstractTextField
Specifies how a Java property should be edited in Vaadin using a
AbstractTextField. |
protected static class |
FieldBuilder.AnnotationApplier<A extends Annotation,F extends AbstractField<?>>
Class that knows how to apply annotation properties to a corresponding field.
|
static interface |
FieldBuilder.CheckBox
Specifies how a Java property should be edited in Vaadin using an
CheckBox. |
static interface |
FieldBuilder.ComboBox
Specifies how a Java property should be edited in Vaadin using an
ComboBox. |
static interface |
FieldBuilder.DateField
Specifies how a Java property should be edited in Vaadin using an
DateField. |
static interface |
FieldBuilder.EnumComboBox
Specifies how a Java property should be edited in Vaadin using an
EnumComboBox. |
static interface |
FieldBuilder.ListSelect
Specifies how a Java property should be edited in Vaadin using an
ListSelect. |
static interface |
FieldBuilder.PasswordField
Specifies how a Java property should be edited in Vaadin using a
PasswordField. |
static interface |
FieldBuilder.ProvidesField
Specifies that the annotated method will return an
AbstractField suitable for
editing the specified property. |
static interface |
FieldBuilder.TextArea
Specifies how a Java property should be edited in Vaadin using a
TextArea. |
static interface |
FieldBuilder.TextField
Specifies how a Java property should be edited in Vaadin using a
TextField. |
| Constructor and Description |
|---|
FieldBuilder() |
| Modifier and Type | Method and Description |
|---|---|
void |
buildAndBind(BeanFieldGroup<?> fieldGroup)
Introspect for
FieldBuilder annotations on property getter methods of the
BeanFieldGroup's data source, and then build and bind the corresponding fields. |
protected List<FieldBuilder.AnnotationApplier<?,?>> |
buildApplierList(Method method)
Find all relevant annotations on the given method as well as on any supertype methods it overrides.
|
Map<String,Field<?>> |
buildBeanPropertyFields(Object bean)
Introspect for
FieldBuilder annotations on property getter methods and build
a mapping from Java bean property name to a field that may be used to edit that property. |
protected List<FieldBuilder.AnnotationApplier<?,?>> |
buildDirectApplierList(Method method)
Find all relevant annotations declared directly on the given
Method. |
protected AbstractField<?> |
buildField(Collection<FieldBuilder.AnnotationApplier<?,?>> appliers,
String description)
Instantiate and configure an
AbstractField according to the given scanned annotations. |
static <T> BeanFieldGroup<T> |
buildFieldGroup(T bean)
Create a
BeanFieldGroup using the given instance, introspect for FieldBuilder annotations
on property getter methods of the given bean's class, and build and bind the corresponding fields, and return
the result. |
protected FieldBuilder.AnnotationApplier<?,?> |
getAnnotationApplier(Method method,
Annotation annotation)
Get the
FieldBuilder.AnnotationApplier that applies the given annotation. |
public void buildAndBind(BeanFieldGroup<?> fieldGroup)
FieldBuilder annotations on property getter methods of the
BeanFieldGroup's data source, and then build and bind the corresponding fields.fieldGroup - field group to configureIllegalArgumentException - if fieldGroup is nullIllegalArgumentException - if fieldGroup does not yet
have a data sourcepublic Map<String,Field<?>> buildBeanPropertyFields(Object bean)
FieldBuilder annotations on property getter methods and build
a mapping from Java bean property name to a field that may be used to edit that property.
Only bean properties that have FieldBuilder annotations are detected.bean - Java beanIllegalArgumentException - if bean is nullIllegalArgumentException - if invalid or conflicting annotations are encounteredpublic static <T> BeanFieldGroup<T> buildFieldGroup(T bean)
BeanFieldGroup using the given instance, introspect for FieldBuilder annotations
on property getter methods of the given bean's class, and build and bind the corresponding fields, and return
the result.T - bean typebean - model bean annotated with FieldBuilder annotationsBeanFieldGroupIllegalArgumentException - if bean is nullprotected AbstractField<?> buildField(Collection<FieldBuilder.AnnotationApplier<?,?>> appliers, String description)
AbstractField according to the given scanned annotations.appliers - annotation appliersdescription - description of the field (used for exception messages)protected List<FieldBuilder.AnnotationApplier<?,?>> buildApplierList(Method method)
method - annotated getter methodIllegalArgumentException - if method is nullIllegalArgumentException - if method has parametersprotected List<FieldBuilder.AnnotationApplier<?,?>> buildDirectApplierList(Method method)
Method.method - method to inspectIllegalArgumentException - if method is nullprotected FieldBuilder.AnnotationApplier<?,?> getAnnotationApplier(Method method, Annotation annotation)
FieldBuilder.AnnotationApplier that applies the given annotation.
Subclasses can add support for additional annotation types by overriding this method.method - method to inspectannotation - method annotation to inspectFieldBuilder.AnnotationApplier, or null if annotation is unknownCopyright © 2017. All rights reserved.