From: Artur Signell Date: Thu, 22 Dec 2011 10:41:24 +0000 (+0200) Subject: Integrated FormBuilder into FieldGroup, renamed X-Git-Tag: 7.0.0.alpha1~25 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=f544df0b2c65ab0118da5be3ab1c7d59cb5975ff;p=vaadin-framework.git Integrated FormBuilder into FieldGroup, renamed FormBuilderFieldFactory -> FieldGroupFieldFactory --- diff --git a/src/com/vaadin/data/fieldbinder/DefaultFormBuilderFieldFactory.java b/src/com/vaadin/data/fieldbinder/DefaultFormBuilderFieldFactory.java index 2b372de144..3977879267 100644 --- a/src/com/vaadin/data/fieldbinder/DefaultFormBuilderFieldFactory.java +++ b/src/com/vaadin/data/fieldbinder/DefaultFormBuilderFieldFactory.java @@ -6,6 +6,7 @@ package com.vaadin.data.fieldbinder; import java.util.EnumSet; import com.vaadin.data.Item; +import com.vaadin.data.fieldbinder.FieldGroup.BindException; import com.vaadin.ui.AbstractSelect; import com.vaadin.ui.AbstractTextField; import com.vaadin.ui.CheckBox; @@ -14,10 +15,11 @@ import com.vaadin.ui.Field; import com.vaadin.ui.ListSelect; import com.vaadin.ui.NativeSelect; import com.vaadin.ui.OptionGroup; +import com.vaadin.ui.RichTextArea; import com.vaadin.ui.Table; import com.vaadin.ui.TextField; -public class DefaultFormBuilderFieldFactory implements FormBuilderFieldFactory { +public class DefaultFormBuilderFieldFactory implements FieldGroupFieldFactory { public static final Object CAPTION_PROPERTY_ID = "Caption"; @@ -31,10 +33,19 @@ public class DefaultFormBuilderFieldFactory implements FormBuilderFieldFactory { if (AbstractTextField.class.isAssignableFrom(fieldType)) { return fieldType.cast(createAbstractTextField(fieldType .asSubclass(AbstractTextField.class))); + } else if (fieldType == RichTextArea.class) { + return fieldType.cast(createRichTextArea()); } return createDefaultField(type, fieldType); } + protected RichTextArea createRichTextArea() { + RichTextArea rta = new RichTextArea(); + rta.setImmediate(true); + + return rta; + } + private T createEnumField(Class type, Class fieldType) { if (AbstractSelect.class.isAssignableFrom(fieldType)) { @@ -92,11 +103,24 @@ public class DefaultFormBuilderFieldFactory implements FormBuilderFieldFactory { field.setImmediate(true); return field; } catch (Exception e) { - throw new FormBuilder.BuildException( - "Could not create a field of type " + fieldType, e); + throw new BindException("Could not create a field of type " + + fieldType, e); } } + /** + * Fallback when no specific field has been created. Typically returns a + * TextField. + * + * @param + * The type of field to create + * @param type + * The type of data that should be edited + * @param fieldType + * The type of field to create + * @return A field capable of editing the data or null if no field could be + * created + */ protected T createDefaultField(Class type, Class fieldType) { if (fieldType.isAssignableFrom(TextField.class)) { diff --git a/src/com/vaadin/data/fieldbinder/FieldGroup.java b/src/com/vaadin/data/fieldbinder/FieldGroup.java index 920849a289..8f5a507470 100644 --- a/src/com/vaadin/data/fieldbinder/FieldGroup.java +++ b/src/com/vaadin/data/fieldbinder/FieldGroup.java @@ -4,6 +4,7 @@ package com.vaadin.data.fieldbinder; import java.io.Serializable; +import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -18,6 +19,7 @@ import com.vaadin.data.TransactionalProperty; import com.vaadin.data.Validator.InvalidValueException; import com.vaadin.data.util.TransactionalPropertyWrapper; import com.vaadin.tools.ReflectTools; +import com.vaadin.ui.DefaultFieldFactory; import com.vaadin.ui.Field; import com.vaadin.ui.Form; @@ -56,6 +58,11 @@ public class FieldGroup implements Serializable { private LinkedHashMap, Object> fieldToPropertyId = new LinkedHashMap, Object>(); private List commitHandlers = new ArrayList(); + /** + * The field factory used by builder methods. + */ + private FieldGroupFieldFactory fieldFactory; + /** * Constructs a field binder. Use {@link #setItemDataSource(Item)} to set a * data source for the field binder. @@ -634,6 +641,28 @@ public class FieldGroup implements Serializable { return false; } + /** + * Gets the field factory for the {@link FieldGroup}. The field factory is + * only used when {@link FieldGroup} creates a new field. + * + * @return The field factory in use + * + */ + public FieldGroupFieldFactory getFieldFactory() { + return fieldFactory; + } + + /** + * Sets the field factory for the {@link FieldGroup}. The field factory is + * only used when {@link FieldGroup} creates a new field. + * + * @param fieldFactory + * The field factory to use + */ + public void setFieldFactory(FieldGroupFieldFactory fieldFactory) { + this.fieldFactory = fieldFactory; + } + /** * Binds member fields found in the given object. *

@@ -659,9 +688,9 @@ public class FieldGroup implements Serializable { * * *

- * This binds the firstName TextField to a "firstName" property id in the - * item, lastName TextField to a "last" property and the age TextField to a - * "age" property id. + * This binds the firstName TextField to a "firstName" property in the item, + * lastName TextField to a "last" property and the age TextField to a "age" + * property. * * @param objectWithMemberFields * The object that contains (Java) member fields to bind @@ -670,18 +699,87 @@ public class FieldGroup implements Serializable { */ public void bindMemberFields(Object objectWithMemberFields) throws BindException { + buildAndBindMemberFields(objectWithMemberFields, false); + } + + /** + * Binds member fields found in the given object and builds member fields + * that have not been initialized. + *

+ * This method processes all (Java) member fields whose type extends + * {@link Field} and that can be mapped to a property id. Property id + * mapping is done based on the field name or on a @{@link PropertyId} + * annotation on the field. Fields that are not initialized (null) are built + * using the field factory. All non-null fields for which a property id can + * be determined are bound to the property id. + *

+ *

+ * For example: + * + *

+     * public class MyForm extends VerticalLayout {
+     * private TextField firstName = new TextField("First name");
+     * @PropertyId("last")
+     * private TextField lastName = new TextField("Last name"); 
+     * private TextField age;
+     * 
+     * MyForm myForm = new MyForm(); 
+     * ... 
+     * fieldGroup.buildAndBindMemberFields(myForm);
+     * 
+ * + *

+ *

+ * This binds the firstName TextField to a "firstName" property in the item, + * lastName TextField to a "last" property and builds an age TextField using + * the field factory and then binds it to the "age" property. + *

+ * + * @param objectWithMemberFields + * The object that contains (Java) member fields to build and + * bind + * @throws BindException + * If there is a problem binding or building a field + */ + public void buildAndBindMemberFields(Object objectWithMemberFields) + throws BindException { + buildAndBindMemberFields(objectWithMemberFields, true); + } + + /** + * Binds member fields found in the given object and optionally builds + * member fields that have not been initialized. + *

+ * This method processes all (Java) member fields whose type extends + * {@link Field} and that can be mapped to a property id. Property id + * mapping is done based on the field name or on a @{@link PropertyId} + * annotation on the field. Fields that are not initialized (null) are built + * using the field factory is buildFields is true. All non-null fields for + * which a property id can be determined are bound to the property id. + *

+ * + * @param objectWithMemberFields + * The object that contains (Java) member fields to build and + * bind + * @throws BindException + * If there is a problem binding or building a field + */ + protected void buildAndBindMemberFields(Object objectWithMemberFields, + boolean buildFields) throws BindException { Class objectClass = objectWithMemberFields.getClass(); - for (java.lang.reflect.Field f : objectClass.getDeclaredFields()) { + for (java.lang.reflect.Field memberField : objectClass + .getDeclaredFields()) { - if (!Field.class.isAssignableFrom(f.getType())) { + if (!Field.class.isAssignableFrom(memberField.getType())) { // Process next field continue; } - PropertyId propertyIdAnnotation = f.getAnnotation(PropertyId.class); + PropertyId propertyIdAnnotation = memberField + .getAnnotation(PropertyId.class); - Class fieldType = (Class) f + Class fieldType = (Class) memberField .getType(); Object propertyId = null; @@ -689,7 +787,7 @@ public class FieldGroup implements Serializable { // @PropertyId(propertyId) always overrides property id propertyId = propertyIdAnnotation.value(); } else { - propertyId = f.getName(); + propertyId = memberField.getName(); } // Ensure that the property id exists @@ -702,18 +800,51 @@ public class FieldGroup implements Serializable { continue; } + Field field; try { // Get the field from the object - Field field = (Field) ReflectTools.getJavaFieldValue( - objectWithMemberFields, f); - // Bind it to the property id - bind(field, propertyId); + field = (Field) ReflectTools.getJavaFieldValue( + objectWithMemberFields, memberField); } catch (Exception e) { // If we cannot determine the value, just skip the field and try // the next one continue; } + if (field == null && buildFields) { + Caption captionAnnotation = memberField + .getAnnotation(Caption.class); + String caption; + if (captionAnnotation != null) { + caption = captionAnnotation.value(); + } else { + caption = DefaultFieldFactory + .createCaptionByPropertyId(propertyId); + } + + // Create the component (Field) + field = build(caption, propertyType, fieldType); + + // Store it in the field + try { + ReflectTools.setJavaFieldValue(objectWithMemberFields, + memberField, field); + } catch (IllegalArgumentException e) { + throw new BindException("Could not assign value to field '" + + memberField.getName() + "'", e); + } catch (IllegalAccessException e) { + throw new BindException("Could not assign value to field '" + + memberField.getName() + "'", e); + } catch (InvocationTargetException e) { + throw new BindException("Could not assign value to field '" + + memberField.getName() + "'", e); + } + } + + if (field != null) { + // Bind it to the property id + bind(field, propertyId); + } } } @@ -752,4 +883,96 @@ public class FieldGroup implements Serializable { } } -} + + /** + * Builds a field and binds it to the given property id using the field + * binder. + * + * @param propertyId + * The property id to bind to. Must be present in the field + * finder. + * @throws BindException + * If there is a problem while building or binding + * @return The created and bound field + */ + public Field buildAndBind(Object propertyId) throws BindException { + String caption = DefaultFieldFactory + .createCaptionByPropertyId(propertyId); + return buildAndBind(caption, propertyId); + } + + /** + * Builds a field using the given caption and binds it to the given property + * id using the field binder. + * + * @param caption + * The caption for the field + * @param propertyId + * The property id to bind to. Must be present in the field + * finder. + * @throws BindException + * If there is a problem while building or binding + * @return The created and bound field. Can be any type of {@link Field}. + */ + public Field buildAndBind(String caption, Object propertyId) + throws BindException { + Class type = getPropertyType(propertyId); + return buildAndBind(caption, propertyId, Field.class); + + } + + /** + * Builds a field using the given caption and binds it to the given property + * id using the field binder. Ensures the new field is of the given type. + * + * @param caption + * The caption for the field + * @param propertyId + * The property id to bind to. Must be present in the field + * finder. + * @throws BindException + * If the field could not be created + * @return The created and bound field. Can be any type of {@link Field}. + */ + + public T buildAndBind(String caption, Object propertyId, + Class fieldType) throws BindException { + Class type = getPropertyType(propertyId); + + T field = build(caption, type, fieldType); + bind(field, propertyId); + + return field; + } + + /** + * Creates a field based on the given data type. + *

+ * The data type is the type that we want to edit using the field. The field + * type is the type of field we want to create, can be {@link Field} if any + * Field is good. + *

+ * + * @param caption + * The caption for the new field + * @param dataType + * The data model type that we want to edit using the field + * @param fieldType + * The type of field that we want to create + * @return A Field capable of editing the given type + * @throws BindException + * If the field could not be created + */ + protected T build(String caption, Class dataType, + Class fieldType) throws BindException { + T field = getFieldFactory().createField(dataType, fieldType); + if (field == null) { + throw new BindException("Unable to build a field of type " + + fieldType.getName() + " for editing " + + dataType.getName()); + } + + field.setCaption(caption); + return field; + } +} \ No newline at end of file diff --git a/src/com/vaadin/data/fieldbinder/FieldGroupFieldFactory.java b/src/com/vaadin/data/fieldbinder/FieldGroupFieldFactory.java new file mode 100644 index 0000000000..8a8c2b9d46 --- /dev/null +++ b/src/com/vaadin/data/fieldbinder/FieldGroupFieldFactory.java @@ -0,0 +1,31 @@ +/* +@VaadinApache2LicenseForJavaFiles@ + */ +package com.vaadin.data.fieldbinder; + +import java.io.Serializable; + +import com.vaadin.ui.Field; + +/** + * Factory interface for creating new Field-instances based on the data type + * that should be edited. + * + * @author Vaadin Ltd. + * @version @version@ + * @since 7.0 + */ +public interface FieldGroupFieldFactory extends Serializable { + /** + * Creates a field based on the data type that we want to edit + * + * @param dataType + * The type that we want to edit using the field + * @param fieldType + * The type of field we want to create. If set to {@link Field} + * then any type of field is accepted + * @return A field that can be assigned to the given fieldType and that is + * capable of editing the given type of data + */ + T createField(Class dataType, Class fieldType); +} diff --git a/src/com/vaadin/data/fieldbinder/FormBuilder.java b/src/com/vaadin/data/fieldbinder/FormBuilder.java deleted file mode 100644 index ccf060ec97..0000000000 --- a/src/com/vaadin/data/fieldbinder/FormBuilder.java +++ /dev/null @@ -1,295 +0,0 @@ -/* -@VaadinApache2LicenseForJavaFiles@ - */ -package com.vaadin.data.fieldbinder; - -import java.io.Serializable; -import java.lang.reflect.InvocationTargetException; -import java.util.logging.Logger; - -import com.vaadin.data.fieldbinder.FieldGroup.BindException; -import com.vaadin.tools.ReflectTools; -import com.vaadin.ui.DefaultFieldFactory; -import com.vaadin.ui.Field; - -/** - * Class for constructing form fields based on a data type. - *

- * - * FIXME Javadoc - */ -public class FormBuilder implements Serializable { - - private FormBuilderFieldFactory fieldFactory = new DefaultFormBuilderFieldFactory(); - private FieldGroup fieldBinder; - private static final Logger logger = Logger.getLogger(FormBuilder.class - .getName()); - - /** - * Constructs a FormBuilder that can be used to build forms automatically. - * - * @param fieldBinder - * The FieldBinder to use for binding the fields to the data - * source - */ - public FormBuilder(FieldGroup fieldBinder) { - this.fieldBinder = fieldBinder; - } - - /** - * TODO: javadoc - */ - protected FieldGroup getFieldBinder() { - return fieldBinder; - } - - /** - * TODO: javadoc - */ - public FormBuilderFieldFactory getFieldFactory() { - return fieldFactory; - } - - /** - * TODO: javadoc - */ - public void setFieldFactory(FormBuilderFieldFactory fieldFactory) { - this.fieldFactory = fieldFactory; - } - - /** - * Builds a field and binds it to the given property id using the field - * binder. - * - * @param propertyId - * The property id to bind to. Must be present in the field - * finder. - * @return The created and bound field - */ - public Field buildAndBind(Object propertyId) { - String caption = DefaultFieldFactory - .createCaptionByPropertyId(propertyId); - return buildAndBind(caption, propertyId); - } - - /** - * Builds a field using the given caption and binds it to the given property - * id using the field binder. - * - * @param caption - * The caption for the field - * @param propertyId - * The property id to bind to. Must be present in the field - * finder. - * @return The created and bound field. Can be any type of {@link Field}. - */ - public Field buildAndBind(String caption, Object propertyId) { - Class type = getFieldBinder().getPropertyType(propertyId); - return buildAndBind(caption, propertyId, type, Field.class); - - } - - /** - * Builds a field using the given caption and binds it to the given property - * id using the field binder. Ensures the new field is of the given type. - * - * @param caption - * The caption for the field - * @param propertyId - * The property id to bind to. Must be present in the field - * finder. - * @return The created and bound field. Can be any type of {@link Field}. - */ - public T buildAndBind(String caption, Object propertyId, - Class fieldType) { - Class type = getFieldBinder().getPropertyType(propertyId); - return buildAndBind(caption, propertyId, type, fieldType); - - } - - /** - * Builds a field with the given type and binds it to the given property id - * using the field binder. - * - * @param caption - * The caption for the new field - * @param propertyId - * The property id to bind to. Must be present in the field - * binder. - * @param type - * The data model type we want to edit using the field - * @param fieldType - * The type of field we want to create - * @return The created and bound field - */ - protected T buildAndBind(String caption, - Object propertyId, Class type, Class fieldType) { - T field = build(caption, type, fieldType); - fieldBinder.bind(field, propertyId); - return field; - } - - /** - * Creates a field based on the given data type. - *

- * The data type is the type that we want to edit using the field. The field - * type is the type of field we want to create, can be {@link Field} if any - * Field is good. - *

- * - * @param caption - * The caption for the new field - * @param dataType - * The data model type that we want to edit using the field - * @param fieldType - * The type of field that we want to create - * @return A Field capable of editing the given type - */ - protected T build(String caption, Class dataType, - Class fieldType) { - logger.finest("Building a field with caption " + caption + " of type " - + dataType.getName()); - T field = getFieldFactory().createField(dataType, fieldType); - if (field == null) { - throw new BuildException("Unable to build a field of type " - + fieldType.getName() + " for editing " - + dataType.getName()); - } - - field.setCaption(caption); - return field; - } - - /** - * Builds and binds fields for the given class. - *

- * This method processes all fields whose type extends {@link Field} and - * that can be mapped to a property id. Property id mapping is done based on - * the field name or on a {@link PropertyId} annotation on the field. All - * fields for which a property id can be determined are built if they are - * null and then bound to the property id. Also existing fields are bound to - * the corresponding property id. - * - * @param object - * The object to process - * @throws FormBuilderException - * If there is a problem building or binding a field - */ - public void buildAndBindFields(Object object) throws FormBuilderException { - Class objectClass = object.getClass(); - - for (java.lang.reflect.Field f : objectClass.getDeclaredFields()) { - PropertyId propertyIdAnnotation = f.getAnnotation(PropertyId.class); - - if (!Field.class.isAssignableFrom(f.getType())) { - // Process next field - continue; - } - Class fieldType = (Class) f - .getType(); - - Object propertyId = null; - if (propertyIdAnnotation != null) { - // @PropertyId(propertyId) always overrides property id - propertyId = propertyIdAnnotation.value(); - } else { - propertyId = f.getName(); - } - - // Ensure that the property id exists - Class propertyType; - - try { - propertyType = fieldBinder.getPropertyType(propertyId); - } catch (BindException e) { - // Property id was not found, skip this field - continue; - } - - Field builtField; - try { - builtField = (Field) ReflectTools.getJavaFieldValue(object, - f); - } catch (Exception e) { - // If we cannot determine the value, just skip the field and try - // the next one - continue; - } - - if (builtField == null) { - // Field is null -> build the field - Caption captionAnnotation = f.getAnnotation(Caption.class); - String caption; - if (captionAnnotation != null) { - caption = captionAnnotation.value(); - } else { - caption = DefaultFieldFactory - .createCaptionByPropertyId(propertyId); - } - - // Create the component (Field) - builtField = build(caption, propertyType, fieldType); - - // Store it in the field - try { - ReflectTools.setJavaFieldValue(object, f, builtField); - } catch (IllegalArgumentException e) { - throw new BuildException( - "Could not assign value to field '" + f.getName() - + "'", e); - } catch (IllegalAccessException e) { - throw new BuildException( - "Could not assign value to field '" + f.getName() - + "'", e); - } catch (InvocationTargetException e) { - throw new BuildException( - "Could not assign value to field '" + f.getName() - + "'", e); - } - } - - // Bind it to the property id - if (builtField != null) { - fieldBinder.bind(builtField, propertyId); - } - - } - } - - public static class FormBuilderException extends RuntimeException { - - public FormBuilderException() { - super(); - // TODO Auto-generated constructor stub - } - - public FormBuilderException(String message, Throwable cause) { - super(message, cause); - // TODO Auto-generated constructor stub - } - - public FormBuilderException(String message) { - super(message); - // TODO Auto-generated constructor stub - } - - public FormBuilderException(Throwable cause) { - super(cause); - // TODO Auto-generated constructor stub - } - - } - - public static class BuildException extends RuntimeException { - - public BuildException(String message) { - super(message); - } - - public BuildException(String message, Throwable t) { - super(message, t); - } - - } - -} diff --git a/src/com/vaadin/data/fieldbinder/FormBuilderFieldFactory.java b/src/com/vaadin/data/fieldbinder/FormBuilderFieldFactory.java deleted file mode 100644 index c189fb5e21..0000000000 --- a/src/com/vaadin/data/fieldbinder/FormBuilderFieldFactory.java +++ /dev/null @@ -1,31 +0,0 @@ -/* -@VaadinApache2LicenseForJavaFiles@ - */ -package com.vaadin.data.fieldbinder; - -import java.io.Serializable; - -import com.vaadin.ui.Field; - -/** - * Factory interface for creating new Field-instances based on the data type - * that should be edited. - * - * @author Vaadin Ltd. - * @version @version@ - * @since 7.0 - */ -public interface FormBuilderFieldFactory extends Serializable { - /** - * Creates a field based on the data type that we want to edit - * - * @param dataType - * The type that we want to edit using the field - * @param fieldType - * The type of field we want to create. If set to {@link Field} - * then any type of field is accepted - * @return A field that can be assigned to the given fieldType and that is - * capable of editing the given type of data - */ - T createField(Class dataType, Class fieldType); -} diff --git a/tests/testbench/com/vaadin/tests/fieldbinder/BasicPersonForm.java b/tests/testbench/com/vaadin/tests/fieldbinder/BasicPersonForm.java index 0a6fa40b3a..dd3f201f49 100644 --- a/tests/testbench/com/vaadin/tests/fieldbinder/BasicPersonForm.java +++ b/tests/testbench/com/vaadin/tests/fieldbinder/BasicPersonForm.java @@ -5,7 +5,6 @@ import com.vaadin.data.fieldbinder.FieldGroup; import com.vaadin.data.fieldbinder.FieldGroup.CommitEvent; import com.vaadin.data.fieldbinder.FieldGroup.CommitException; import com.vaadin.data.fieldbinder.FieldGroup.CommitHandler; -import com.vaadin.data.fieldbinder.FormBuilder; import com.vaadin.data.util.BeanItem; import com.vaadin.data.util.converter.StringToBooleanConverter; import com.vaadin.data.validator.EmailValidator; @@ -65,13 +64,12 @@ public class BasicPersonForm extends TestBase { super("Configuration"); BeanItem bi = new BeanItem( configuration); - FieldGroup confBinder = new FieldGroup(bi); - confBinder.setItemDataSource(bi); - confBinder.setBuffered(false); + FieldGroup confFieldGroup = new FieldGroup(bi); + confFieldGroup.setItemDataSource(bi); + confFieldGroup.setBuffered(false); - FormBuilder builder = new FormBuilder(confBinder); for (Object propertyId : bi.getItemPropertyIds()) { - addComponent(builder.buildAndBind(propertyId)); + addComponent(confFieldGroup.buildAndBind(propertyId)); } } @@ -83,8 +81,8 @@ public class BasicPersonForm extends TestBase { Panel confPanel = new ConfigurationPanel(); addComponent(confPanel); - final FieldGroup binder = new BeanFieldGroup(Person.class); - binder.addCommitHandler(new CommitHandler() { + final FieldGroup fieldGroup = new BeanFieldGroup(Person.class); + fieldGroup.addCommitHandler(new CommitHandler() { public void preCommit(CommitEvent commitEvent) throws CommitException { @@ -108,10 +106,9 @@ public class BasicPersonForm extends TestBase { } }); - binder.setBuffered(true); + fieldGroup.setBuffered(true); - FormBuilder builder = new FormBuilder(binder); - builder.buildAndBindFields(this); + fieldGroup.buildAndBindMemberFields(this); addComponent(firstName); addComponent(lastName); addComponent(email); @@ -124,7 +121,7 @@ public class BasicPersonForm extends TestBase { public void buttonClick(ClickEvent event) { String msg = "Commit succesful"; try { - binder.commit(); + fieldGroup.commit(); } catch (CommitException e) { msg = "Commit failed: " + e.getMessage(); } @@ -137,7 +134,7 @@ public class BasicPersonForm extends TestBase { new Button.ClickListener() { public void buttonClick(ClickEvent event) { - binder.discard(); + fieldGroup.discard(); log.log("Discarded changes"); } @@ -146,7 +143,7 @@ public class BasicPersonForm extends TestBase { new Button.ClickListener() { public void buttonClick(ClickEvent event) { - log.log(getPerson(binder).toString()); + log.log(getPerson(fieldGroup).toString()); } }); @@ -173,7 +170,7 @@ public class BasicPersonForm extends TestBase { }); Person p = new Person("John", "Doe", "john@doe.com", 64, Sex.MALE, new Address("John street", 11223, "John's town", Country.USA)); - binder.setItemDataSource(new BeanItem(p)); + fieldGroup.setItemDataSource(new BeanItem(p)); } public static Person getPerson(FieldGroup binder) { diff --git a/tests/testbench/com/vaadin/tests/fieldbinder/FieldBinderWithBeanValidation.java b/tests/testbench/com/vaadin/tests/fieldbinder/FieldBinderWithBeanValidation.java index 9af14cb9fd..f6c585d5db 100644 --- a/tests/testbench/com/vaadin/tests/fieldbinder/FieldBinderWithBeanValidation.java +++ b/tests/testbench/com/vaadin/tests/fieldbinder/FieldBinderWithBeanValidation.java @@ -3,7 +3,6 @@ package com.vaadin.tests.fieldbinder; import com.vaadin.data.fieldbinder.BeanFieldGroup; import com.vaadin.data.fieldbinder.FieldGroup; import com.vaadin.data.fieldbinder.FieldGroup.CommitException; -import com.vaadin.data.fieldbinder.FormBuilder; import com.vaadin.data.util.BeanItem; import com.vaadin.tests.components.TestBase; import com.vaadin.tests.data.bean.Address; @@ -33,11 +32,10 @@ public class FieldBinderWithBeanValidation extends TestBase { protected void setup() { addComponent(log); - final BeanFieldGroup binder = new BeanFieldGroup( + final BeanFieldGroup fieldGroup = new BeanFieldGroup( PersonWithBeanValidationAnnotations.class); - FormBuilder builder = new FormBuilder(binder); - builder.buildAndBindFields(this); + fieldGroup.buildAndBindMemberFields(this); addComponent(firstName); addComponent(lastName); addComponent(email); @@ -50,7 +48,7 @@ public class FieldBinderWithBeanValidation extends TestBase { public void buttonClick(ClickEvent event) { String msg = "Commit succesful"; try { - binder.commit(); + fieldGroup.commit(); } catch (CommitException e) { msg = "Commit failed: " + e.getMessage(); } @@ -63,7 +61,7 @@ public class FieldBinderWithBeanValidation extends TestBase { new Button.ClickListener() { public void buttonClick(ClickEvent event) { - binder.discard(); + fieldGroup.discard(); log.log("Discarded changes"); } @@ -72,7 +70,7 @@ public class FieldBinderWithBeanValidation extends TestBase { new Button.ClickListener() { public void buttonClick(ClickEvent event) { - log.log(getPerson(binder).toString()); + log.log(getPerson(fieldGroup).toString()); } }); @@ -84,8 +82,9 @@ public class FieldBinderWithBeanValidation extends TestBase { PersonWithBeanValidationAnnotations p = new PersonWithBeanValidationAnnotations( "John", "Doe", "john@doe.com", 64, Sex.MALE, new Address( "John street", 11223, "John's town", Country.USA)); - binder.setItemDataSource(new BeanItem( - p)); + fieldGroup + .setItemDataSource(new BeanItem( + p)); } public static Person getPerson(FieldGroup binder) { diff --git a/tests/testbench/com/vaadin/tests/fieldbinder/FormBuilderWithNestedProperties.java b/tests/testbench/com/vaadin/tests/fieldbinder/FormBuilderWithNestedProperties.java index 284d69aa81..da6a666590 100644 --- a/tests/testbench/com/vaadin/tests/fieldbinder/FormBuilderWithNestedProperties.java +++ b/tests/testbench/com/vaadin/tests/fieldbinder/FormBuilderWithNestedProperties.java @@ -2,7 +2,6 @@ package com.vaadin.tests.fieldbinder; import com.vaadin.data.fieldbinder.BeanFieldGroup; import com.vaadin.data.fieldbinder.FieldGroup; -import com.vaadin.data.fieldbinder.FormBuilder; import com.vaadin.data.fieldbinder.PropertyId; import com.vaadin.data.util.BeanItem; import com.vaadin.tests.components.TestBase; @@ -21,15 +20,14 @@ public class FormBuilderWithNestedProperties extends TestBase { @Override protected void setup() { - FieldGroup fieldBinder = new BeanFieldGroup(Person.class); - FormBuilder b = new FormBuilder(fieldBinder); - b.buildAndBindFields(this); + FieldGroup fieldGroup = new BeanFieldGroup(Person.class); + fieldGroup.buildAndBindMemberFields(this); addComponent(firstName); addComponent(lastName); addComponent(streetAddress); - fieldBinder.setItemDataSource(new BeanItem(new Person("Who", + fieldGroup.setItemDataSource(new BeanItem(new Person("Who", "me?", "email", 1, Sex.MALE, new Address("street name", 202020, "City", Country.FINLAND)))); } diff --git a/tests/testbench/com/vaadin/tests/fieldbinder/FormWithNestedProperties.java b/tests/testbench/com/vaadin/tests/fieldbinder/FormWithNestedProperties.java index 637cc26a88..9886bc61f5 100644 --- a/tests/testbench/com/vaadin/tests/fieldbinder/FormWithNestedProperties.java +++ b/tests/testbench/com/vaadin/tests/fieldbinder/FormWithNestedProperties.java @@ -1,7 +1,6 @@ package com.vaadin.tests.fieldbinder; import com.vaadin.data.fieldbinder.BeanFieldGroup; -import com.vaadin.data.fieldbinder.FormBuilder; import com.vaadin.data.fieldbinder.PropertyId; import com.vaadin.tests.data.bean.Address; import com.vaadin.tests.data.bean.Country; @@ -32,9 +31,9 @@ public class FormWithNestedProperties extends AbstractBeanFieldBinderTest { super.setup(); setFieldBinder(new BeanFieldGroup(Person.class)); + country = getFieldBinder().buildAndBind("country", "address.country", + NativeSelect.class); getFieldBinder().bindMemberFields(this); - country = new FormBuilder(getFieldBinder()).buildAndBind("country", - "address.country", NativeSelect.class); addComponent(firstName); addComponent(lastName); addComponent(streetAddress);