import java.util.EnumSet;\r
\r
import com.vaadin.data.Item;\r
+import com.vaadin.data.fieldbinder.FieldGroup.BindException;\r
import com.vaadin.ui.AbstractSelect;\r
import com.vaadin.ui.AbstractTextField;\r
import com.vaadin.ui.CheckBox;\r
import com.vaadin.ui.ListSelect;\r
import com.vaadin.ui.NativeSelect;\r
import com.vaadin.ui.OptionGroup;\r
+import com.vaadin.ui.RichTextArea;\r
import com.vaadin.ui.Table;\r
import com.vaadin.ui.TextField;\r
\r
-public class DefaultFormBuilderFieldFactory implements FormBuilderFieldFactory {\r
+public class DefaultFormBuilderFieldFactory implements FieldGroupFieldFactory {\r
\r
public static final Object CAPTION_PROPERTY_ID = "Caption";\r
\r
if (AbstractTextField.class.isAssignableFrom(fieldType)) {\r
return fieldType.cast(createAbstractTextField(fieldType\r
.asSubclass(AbstractTextField.class)));\r
+ } else if (fieldType == RichTextArea.class) {\r
+ return fieldType.cast(createRichTextArea());\r
}\r
return createDefaultField(type, fieldType);\r
}\r
\r
+ protected RichTextArea createRichTextArea() {\r
+ RichTextArea rta = new RichTextArea();\r
+ rta.setImmediate(true);\r
+\r
+ return rta;\r
+ }\r
+\r
private <T extends Field> T createEnumField(Class<?> type,\r
Class<T> fieldType) {\r
if (AbstractSelect.class.isAssignableFrom(fieldType)) {\r
field.setImmediate(true);\r
return field;\r
} catch (Exception e) {\r
- throw new FormBuilder.BuildException(\r
- "Could not create a field of type " + fieldType, e);\r
+ throw new BindException("Could not create a field of type "\r
+ + fieldType, e);\r
}\r
}\r
\r
+ /**\r
+ * Fallback when no specific field has been created. Typically returns a\r
+ * TextField.\r
+ * \r
+ * @param <T>\r
+ * The type of field to create\r
+ * @param type\r
+ * The type of data that should be edited\r
+ * @param fieldType\r
+ * The type of field to create\r
+ * @return A field capable of editing the data or null if no field could be\r
+ * created\r
+ */\r
protected <T extends Field> T createDefaultField(Class<?> type,\r
Class<T> fieldType) {\r
if (fieldType.isAssignableFrom(TextField.class)) {\r
package com.vaadin.data.fieldbinder;\r
\r
import java.io.Serializable;\r
+import java.lang.reflect.InvocationTargetException;\r
import java.util.ArrayList;\r
import java.util.Collection;\r
import java.util.Collections;\r
import com.vaadin.data.Validator.InvalidValueException;\r
import com.vaadin.data.util.TransactionalPropertyWrapper;\r
import com.vaadin.tools.ReflectTools;\r
+import com.vaadin.ui.DefaultFieldFactory;\r
import com.vaadin.ui.Field;\r
import com.vaadin.ui.Form;\r
\r
private LinkedHashMap<Field<?>, Object> fieldToPropertyId = new LinkedHashMap<Field<?>, Object>();\r
private List<CommitHandler> commitHandlers = new ArrayList<CommitHandler>();\r
\r
+ /**\r
+ * The field factory used by builder methods.\r
+ */\r
+ private FieldGroupFieldFactory fieldFactory;\r
+\r
/**\r
* Constructs a field binder. Use {@link #setItemDataSource(Item)} to set a\r
* data source for the field binder.\r
return false;\r
}\r
\r
+ /**\r
+ * Gets the field factory for the {@link FieldGroup}. The field factory is\r
+ * only used when {@link FieldGroup} creates a new field.\r
+ * \r
+ * @return The field factory in use\r
+ * \r
+ */\r
+ public FieldGroupFieldFactory getFieldFactory() {\r
+ return fieldFactory;\r
+ }\r
+\r
+ /**\r
+ * Sets the field factory for the {@link FieldGroup}. The field factory is\r
+ * only used when {@link FieldGroup} creates a new field.\r
+ * \r
+ * @param fieldFactory\r
+ * The field factory to use\r
+ */\r
+ public void setFieldFactory(FieldGroupFieldFactory fieldFactory) {\r
+ this.fieldFactory = fieldFactory;\r
+ }\r
+\r
/**\r
* Binds member fields found in the given object.\r
* <p>\r
* </pre>\r
* \r
* </p>\r
- * This binds the firstName TextField to a "firstName" property id in the\r
- * item, lastName TextField to a "last" property and the age TextField to a\r
- * "age" property id.\r
+ * This binds the firstName TextField to a "firstName" property in the item,\r
+ * lastName TextField to a "last" property and the age TextField to a "age"\r
+ * property.\r
* \r
* @param objectWithMemberFields\r
* The object that contains (Java) member fields to bind\r
*/\r
public void bindMemberFields(Object objectWithMemberFields)\r
throws BindException {\r
+ buildAndBindMemberFields(objectWithMemberFields, false);\r
+ }\r
+\r
+ /**\r
+ * Binds member fields found in the given object and builds member fields\r
+ * that have not been initialized.\r
+ * <p>\r
+ * This method processes all (Java) member fields whose type extends\r
+ * {@link Field} and that can be mapped to a property id. Property id\r
+ * mapping is done based on the field name or on a @{@link PropertyId}\r
+ * annotation on the field. Fields that are not initialized (null) are built\r
+ * using the field factory. All non-null fields for which a property id can\r
+ * be determined are bound to the property id.\r
+ * </p>\r
+ * <p>\r
+ * For example:\r
+ * \r
+ * <pre>\r
+ * public class MyForm extends VerticalLayout {\r
+ * private TextField firstName = new TextField("First name");\r
+ * @PropertyId("last")\r
+ * private TextField lastName = new TextField("Last name"); \r
+ * private TextField age;\r
+ * \r
+ * MyForm myForm = new MyForm(); \r
+ * ... \r
+ * fieldGroup.buildAndBindMemberFields(myForm);\r
+ * </pre>\r
+ * \r
+ * </p>\r
+ * <p>\r
+ * This binds the firstName TextField to a "firstName" property in the item,\r
+ * lastName TextField to a "last" property and builds an age TextField using\r
+ * the field factory and then binds it to the "age" property.\r
+ * </p>\r
+ * \r
+ * @param objectWithMemberFields\r
+ * The object that contains (Java) member fields to build and\r
+ * bind\r
+ * @throws BindException\r
+ * If there is a problem binding or building a field\r
+ */\r
+ public void buildAndBindMemberFields(Object objectWithMemberFields)\r
+ throws BindException {\r
+ buildAndBindMemberFields(objectWithMemberFields, true);\r
+ }\r
+\r
+ /**\r
+ * Binds member fields found in the given object and optionally builds\r
+ * member fields that have not been initialized.\r
+ * <p>\r
+ * This method processes all (Java) member fields whose type extends\r
+ * {@link Field} and that can be mapped to a property id. Property id\r
+ * mapping is done based on the field name or on a @{@link PropertyId}\r
+ * annotation on the field. Fields that are not initialized (null) are built\r
+ * using the field factory is buildFields is true. All non-null fields for\r
+ * which a property id can be determined are bound to the property id.\r
+ * </p>\r
+ * \r
+ * @param objectWithMemberFields\r
+ * The object that contains (Java) member fields to build and\r
+ * bind\r
+ * @throws BindException\r
+ * If there is a problem binding or building a field\r
+ */\r
+ protected void buildAndBindMemberFields(Object objectWithMemberFields,\r
+ boolean buildFields) throws BindException {\r
Class<?> objectClass = objectWithMemberFields.getClass();\r
\r
- for (java.lang.reflect.Field f : objectClass.getDeclaredFields()) {\r
+ for (java.lang.reflect.Field memberField : objectClass\r
+ .getDeclaredFields()) {\r
\r
- if (!Field.class.isAssignableFrom(f.getType())) {\r
+ if (!Field.class.isAssignableFrom(memberField.getType())) {\r
// Process next field\r
continue;\r
}\r
\r
- PropertyId propertyIdAnnotation = f.getAnnotation(PropertyId.class);\r
+ PropertyId propertyIdAnnotation = memberField\r
+ .getAnnotation(PropertyId.class);\r
\r
- Class<? extends Field> fieldType = (Class<? extends Field>) f\r
+ Class<? extends Field> fieldType = (Class<? extends Field>) memberField\r
.getType();\r
\r
Object propertyId = null;\r
// @PropertyId(propertyId) always overrides property id\r
propertyId = propertyIdAnnotation.value();\r
} else {\r
- propertyId = f.getName();\r
+ propertyId = memberField.getName();\r
}\r
\r
// Ensure that the property id exists\r
continue;\r
}\r
\r
+ Field<?> field;\r
try {\r
// Get the field from the object\r
- Field<?> field = (Field<?>) ReflectTools.getJavaFieldValue(\r
- objectWithMemberFields, f);\r
- // Bind it to the property id\r
- bind(field, propertyId);\r
+ field = (Field<?>) ReflectTools.getJavaFieldValue(\r
+ objectWithMemberFields, memberField);\r
} catch (Exception e) {\r
// If we cannot determine the value, just skip the field and try\r
// the next one\r
continue;\r
}\r
\r
+ if (field == null && buildFields) {\r
+ Caption captionAnnotation = memberField\r
+ .getAnnotation(Caption.class);\r
+ String caption;\r
+ if (captionAnnotation != null) {\r
+ caption = captionAnnotation.value();\r
+ } else {\r
+ caption = DefaultFieldFactory\r
+ .createCaptionByPropertyId(propertyId);\r
+ }\r
+\r
+ // Create the component (Field)\r
+ field = build(caption, propertyType, fieldType);\r
+\r
+ // Store it in the field\r
+ try {\r
+ ReflectTools.setJavaFieldValue(objectWithMemberFields,\r
+ memberField, field);\r
+ } catch (IllegalArgumentException e) {\r
+ throw new BindException("Could not assign value to field '"\r
+ + memberField.getName() + "'", e);\r
+ } catch (IllegalAccessException e) {\r
+ throw new BindException("Could not assign value to field '"\r
+ + memberField.getName() + "'", e);\r
+ } catch (InvocationTargetException e) {\r
+ throw new BindException("Could not assign value to field '"\r
+ + memberField.getName() + "'", e);\r
+ }\r
+ }\r
+\r
+ if (field != null) {\r
+ // Bind it to the property id\r
+ bind(field, propertyId);\r
+ }\r
}\r
}\r
\r
}\r
\r
}\r
-}
+\r
+ /**\r
+ * Builds a field and binds it to the given property id using the field\r
+ * binder.\r
+ * \r
+ * @param propertyId\r
+ * The property id to bind to. Must be present in the field\r
+ * finder.\r
+ * @throws BindException\r
+ * If there is a problem while building or binding\r
+ * @return The created and bound field\r
+ */\r
+ public Field<?> buildAndBind(Object propertyId) throws BindException {\r
+ String caption = DefaultFieldFactory\r
+ .createCaptionByPropertyId(propertyId);\r
+ return buildAndBind(caption, propertyId);\r
+ }\r
+\r
+ /**\r
+ * Builds a field using the given caption and binds it to the given property\r
+ * id using the field binder.\r
+ * \r
+ * @param caption\r
+ * The caption for the field\r
+ * @param propertyId\r
+ * The property id to bind to. Must be present in the field\r
+ * finder.\r
+ * @throws BindException\r
+ * If there is a problem while building or binding\r
+ * @return The created and bound field. Can be any type of {@link Field}.\r
+ */\r
+ public Field<?> buildAndBind(String caption, Object propertyId)\r
+ throws BindException {\r
+ Class<?> type = getPropertyType(propertyId);\r
+ return buildAndBind(caption, propertyId, Field.class);\r
+\r
+ }\r
+\r
+ /**\r
+ * Builds a field using the given caption and binds it to the given property\r
+ * id using the field binder. Ensures the new field is of the given type.\r
+ * \r
+ * @param caption\r
+ * The caption for the field\r
+ * @param propertyId\r
+ * The property id to bind to. Must be present in the field\r
+ * finder.\r
+ * @throws BindException\r
+ * If the field could not be created\r
+ * @return The created and bound field. Can be any type of {@link Field}.\r
+ */\r
+\r
+ public <T extends Field> T buildAndBind(String caption, Object propertyId,\r
+ Class<T> fieldType) throws BindException {\r
+ Class<?> type = getPropertyType(propertyId);\r
+\r
+ T field = build(caption, type, fieldType);\r
+ bind(field, propertyId);\r
+\r
+ return field;\r
+ }\r
+\r
+ /**\r
+ * Creates a field based on the given data type.\r
+ * <p>\r
+ * The data type is the type that we want to edit using the field. The field\r
+ * type is the type of field we want to create, can be {@link Field} if any\r
+ * Field is good.\r
+ * </p>\r
+ * \r
+ * @param caption\r
+ * The caption for the new field\r
+ * @param dataType\r
+ * The data model type that we want to edit using the field\r
+ * @param fieldType\r
+ * The type of field that we want to create\r
+ * @return A Field capable of editing the given type\r
+ * @throws BindException\r
+ * If the field could not be created\r
+ */\r
+ protected <T extends Field> T build(String caption, Class<?> dataType,\r
+ Class<T> fieldType) throws BindException {\r
+ T field = getFieldFactory().createField(dataType, fieldType);\r
+ if (field == null) {\r
+ throw new BindException("Unable to build a field of type "\r
+ + fieldType.getName() + " for editing "\r
+ + dataType.getName());\r
+ }\r
+\r
+ field.setCaption(caption);\r
+ return field;\r
+ }\r
+}
\ No newline at end of file
--- /dev/null
+/* \r
+@VaadinApache2LicenseForJavaFiles@\r
+ */\r
+package com.vaadin.data.fieldbinder;\r
+\r
+import java.io.Serializable;\r
+\r
+import com.vaadin.ui.Field;\r
+\r
+/**\r
+ * Factory interface for creating new Field-instances based on the data type\r
+ * that should be edited.\r
+ * \r
+ * @author Vaadin Ltd.\r
+ * @version @version@\r
+ * @since 7.0\r
+ */\r
+public interface FieldGroupFieldFactory extends Serializable {\r
+ /**\r
+ * Creates a field based on the data type that we want to edit\r
+ * \r
+ * @param dataType\r
+ * The type that we want to edit using the field\r
+ * @param fieldType\r
+ * The type of field we want to create. If set to {@link Field}\r
+ * then any type of field is accepted\r
+ * @return A field that can be assigned to the given fieldType and that is\r
+ * capable of editing the given type of data\r
+ */\r
+ <T extends Field> T createField(Class<?> dataType, Class<T> fieldType);\r
+}\r
+++ /dev/null
-/* \r
-@VaadinApache2LicenseForJavaFiles@\r
- */\r
-package com.vaadin.data.fieldbinder;\r
-\r
-import java.io.Serializable;\r
-import java.lang.reflect.InvocationTargetException;\r
-import java.util.logging.Logger;\r
-\r
-import com.vaadin.data.fieldbinder.FieldGroup.BindException;\r
-import com.vaadin.tools.ReflectTools;\r
-import com.vaadin.ui.DefaultFieldFactory;\r
-import com.vaadin.ui.Field;\r
-\r
-/**\r
- * Class for constructing form fields based on a data type.\r
- * <p>\r
- * \r
- * FIXME Javadoc\r
- */\r
-public class FormBuilder implements Serializable {\r
-\r
- private FormBuilderFieldFactory fieldFactory = new DefaultFormBuilderFieldFactory();\r
- private FieldGroup fieldBinder;\r
- private static final Logger logger = Logger.getLogger(FormBuilder.class\r
- .getName());\r
-\r
- /**\r
- * Constructs a FormBuilder that can be used to build forms automatically.\r
- * \r
- * @param fieldBinder\r
- * The FieldBinder to use for binding the fields to the data\r
- * source\r
- */\r
- public FormBuilder(FieldGroup fieldBinder) {\r
- this.fieldBinder = fieldBinder;\r
- }\r
-\r
- /**\r
- * TODO: javadoc\r
- */\r
- protected FieldGroup getFieldBinder() {\r
- return fieldBinder;\r
- }\r
-\r
- /**\r
- * TODO: javadoc\r
- */\r
- public FormBuilderFieldFactory getFieldFactory() {\r
- return fieldFactory;\r
- }\r
-\r
- /**\r
- * TODO: javadoc\r
- */\r
- public void setFieldFactory(FormBuilderFieldFactory fieldFactory) {\r
- this.fieldFactory = fieldFactory;\r
- }\r
-\r
- /**\r
- * Builds a field and binds it to the given property id using the field\r
- * binder.\r
- * \r
- * @param propertyId\r
- * The property id to bind to. Must be present in the field\r
- * finder.\r
- * @return The created and bound field\r
- */\r
- public Field<?> buildAndBind(Object propertyId) {\r
- String caption = DefaultFieldFactory\r
- .createCaptionByPropertyId(propertyId);\r
- return buildAndBind(caption, propertyId);\r
- }\r
-\r
- /**\r
- * Builds a field using the given caption and binds it to the given property\r
- * id using the field binder.\r
- * \r
- * @param caption\r
- * The caption for the field\r
- * @param propertyId\r
- * The property id to bind to. Must be present in the field\r
- * finder.\r
- * @return The created and bound field. Can be any type of {@link Field}.\r
- */\r
- public Field<?> buildAndBind(String caption, Object propertyId) {\r
- Class<?> type = getFieldBinder().getPropertyType(propertyId);\r
- return buildAndBind(caption, propertyId, type, Field.class);\r
-\r
- }\r
-\r
- /**\r
- * Builds a field using the given caption and binds it to the given property\r
- * id using the field binder. Ensures the new field is of the given type.\r
- * \r
- * @param caption\r
- * The caption for the field\r
- * @param propertyId\r
- * The property id to bind to. Must be present in the field\r
- * finder.\r
- * @return The created and bound field. Can be any type of {@link Field}.\r
- */\r
- public <T extends Field> T buildAndBind(String caption, Object propertyId,\r
- Class<T> fieldType) {\r
- Class<?> type = getFieldBinder().getPropertyType(propertyId);\r
- return buildAndBind(caption, propertyId, type, fieldType);\r
-\r
- }\r
-\r
- /**\r
- * Builds a field with the given type and binds it to the given property id\r
- * using the field binder.\r
- * \r
- * @param caption\r
- * The caption for the new field\r
- * @param propertyId\r
- * The property id to bind to. Must be present in the field\r
- * binder.\r
- * @param type\r
- * The data model type we want to edit using the field\r
- * @param fieldType\r
- * The type of field we want to create\r
- * @return The created and bound field\r
- */\r
- protected <T extends Field> T buildAndBind(String caption,\r
- Object propertyId, Class<?> type, Class<T> fieldType) {\r
- T field = build(caption, type, fieldType);\r
- fieldBinder.bind(field, propertyId);\r
- return field;\r
- }\r
-\r
- /**\r
- * Creates a field based on the given data type.\r
- * <p>\r
- * The data type is the type that we want to edit using the field. The field\r
- * type is the type of field we want to create, can be {@link Field} if any\r
- * Field is good.\r
- * </p>\r
- * \r
- * @param caption\r
- * The caption for the new field\r
- * @param dataType\r
- * The data model type that we want to edit using the field\r
- * @param fieldType\r
- * The type of field that we want to create\r
- * @return A Field capable of editing the given type\r
- */\r
- protected <T extends Field> T build(String caption, Class<?> dataType,\r
- Class<T> fieldType) {\r
- logger.finest("Building a field with caption " + caption + " of type "\r
- + dataType.getName());\r
- T field = getFieldFactory().createField(dataType, fieldType);\r
- if (field == null) {\r
- throw new BuildException("Unable to build a field of type "\r
- + fieldType.getName() + " for editing "\r
- + dataType.getName());\r
- }\r
-\r
- field.setCaption(caption);\r
- return field;\r
- }\r
-\r
- /**\r
- * Builds and binds fields for the given class.\r
- * <p>\r
- * This method processes all fields whose type extends {@link Field} and\r
- * that can be mapped to a property id. Property id mapping is done based on\r
- * the field name or on a {@link PropertyId} annotation on the field. All\r
- * fields for which a property id can be determined are built if they are\r
- * null and then bound to the property id. Also existing fields are bound to\r
- * the corresponding property id.\r
- * \r
- * @param object\r
- * The object to process\r
- * @throws FormBuilderException\r
- * If there is a problem building or binding a field\r
- */\r
- public void buildAndBindFields(Object object) throws FormBuilderException {\r
- Class<?> objectClass = object.getClass();\r
-\r
- for (java.lang.reflect.Field f : objectClass.getDeclaredFields()) {\r
- PropertyId propertyIdAnnotation = f.getAnnotation(PropertyId.class);\r
-\r
- if (!Field.class.isAssignableFrom(f.getType())) {\r
- // Process next field\r
- continue;\r
- }\r
- Class<? extends Field> fieldType = (Class<? extends Field>) f\r
- .getType();\r
-\r
- Object propertyId = null;\r
- if (propertyIdAnnotation != null) {\r
- // @PropertyId(propertyId) always overrides property id\r
- propertyId = propertyIdAnnotation.value();\r
- } else {\r
- propertyId = f.getName();\r
- }\r
-\r
- // Ensure that the property id exists\r
- Class<?> propertyType;\r
-\r
- try {\r
- propertyType = fieldBinder.getPropertyType(propertyId);\r
- } catch (BindException e) {\r
- // Property id was not found, skip this field\r
- continue;\r
- }\r
-\r
- Field<?> builtField;\r
- try {\r
- builtField = (Field<?>) ReflectTools.getJavaFieldValue(object,\r
- f);\r
- } catch (Exception e) {\r
- // If we cannot determine the value, just skip the field and try\r
- // the next one\r
- continue;\r
- }\r
-\r
- if (builtField == null) {\r
- // Field is null -> build the field\r
- Caption captionAnnotation = f.getAnnotation(Caption.class);\r
- String caption;\r
- if (captionAnnotation != null) {\r
- caption = captionAnnotation.value();\r
- } else {\r
- caption = DefaultFieldFactory\r
- .createCaptionByPropertyId(propertyId);\r
- }\r
-\r
- // Create the component (Field)\r
- builtField = build(caption, propertyType, fieldType);\r
-\r
- // Store it in the field\r
- try {\r
- ReflectTools.setJavaFieldValue(object, f, builtField);\r
- } catch (IllegalArgumentException e) {\r
- throw new BuildException(\r
- "Could not assign value to field '" + f.getName()\r
- + "'", e);\r
- } catch (IllegalAccessException e) {\r
- throw new BuildException(\r
- "Could not assign value to field '" + f.getName()\r
- + "'", e);\r
- } catch (InvocationTargetException e) {\r
- throw new BuildException(\r
- "Could not assign value to field '" + f.getName()\r
- + "'", e);\r
- }\r
- }\r
-\r
- // Bind it to the property id\r
- if (builtField != null) {\r
- fieldBinder.bind(builtField, propertyId);\r
- }\r
-\r
- }\r
- }\r
-\r
- public static class FormBuilderException extends RuntimeException {\r
-\r
- public FormBuilderException() {\r
- super();\r
- // TODO Auto-generated constructor stub\r
- }\r
-\r
- public FormBuilderException(String message, Throwable cause) {\r
- super(message, cause);\r
- // TODO Auto-generated constructor stub\r
- }\r
-\r
- public FormBuilderException(String message) {\r
- super(message);\r
- // TODO Auto-generated constructor stub\r
- }\r
-\r
- public FormBuilderException(Throwable cause) {\r
- super(cause);\r
- // TODO Auto-generated constructor stub\r
- }\r
-\r
- }\r
-\r
- public static class BuildException extends RuntimeException {\r
-\r
- public BuildException(String message) {\r
- super(message);\r
- }\r
-\r
- public BuildException(String message, Throwable t) {\r
- super(message, t);\r
- }\r
-\r
- }\r
-\r
-}\r
+++ /dev/null
-/* \r
-@VaadinApache2LicenseForJavaFiles@\r
- */\r
-package com.vaadin.data.fieldbinder;\r
-\r
-import java.io.Serializable;\r
-\r
-import com.vaadin.ui.Field;\r
-\r
-/**\r
- * Factory interface for creating new Field-instances based on the data type\r
- * that should be edited.\r
- * \r
- * @author Vaadin Ltd.\r
- * @version @version@\r
- * @since 7.0\r
- */\r
-public interface FormBuilderFieldFactory extends Serializable {\r
- /**\r
- * Creates a field based on the data type that we want to edit\r
- * \r
- * @param dataType\r
- * The type that we want to edit using the field\r
- * @param fieldType\r
- * The type of field we want to create. If set to {@link Field}\r
- * then any type of field is accepted\r
- * @return A field that can be assigned to the given fieldType and that is\r
- * capable of editing the given type of data\r
- */\r
- <T extends Field> T createField(Class<?> dataType, Class<T> fieldType);\r
-}\r
import com.vaadin.data.fieldbinder.FieldGroup.CommitEvent;\r
import com.vaadin.data.fieldbinder.FieldGroup.CommitException;\r
import com.vaadin.data.fieldbinder.FieldGroup.CommitHandler;\r
-import com.vaadin.data.fieldbinder.FormBuilder;\r
import com.vaadin.data.util.BeanItem;\r
import com.vaadin.data.util.converter.StringToBooleanConverter;\r
import com.vaadin.data.validator.EmailValidator;\r
super("Configuration");\r
BeanItem<Configuration> bi = new BeanItem<BasicPersonForm.Configuration>(\r
configuration);\r
- FieldGroup confBinder = new FieldGroup(bi);\r
- confBinder.setItemDataSource(bi);\r
- confBinder.setBuffered(false);\r
+ FieldGroup confFieldGroup = new FieldGroup(bi);\r
+ confFieldGroup.setItemDataSource(bi);\r
+ confFieldGroup.setBuffered(false);\r
\r
- FormBuilder builder = new FormBuilder(confBinder);\r
for (Object propertyId : bi.getItemPropertyIds()) {\r
- addComponent(builder.buildAndBind(propertyId));\r
+ addComponent(confFieldGroup.buildAndBind(propertyId));\r
}\r
\r
}\r
Panel confPanel = new ConfigurationPanel();\r
addComponent(confPanel);\r
\r
- final FieldGroup binder = new BeanFieldGroup<Person>(Person.class);\r
- binder.addCommitHandler(new CommitHandler() {\r
+ final FieldGroup fieldGroup = new BeanFieldGroup<Person>(Person.class);\r
+ fieldGroup.addCommitHandler(new CommitHandler() {\r
\r
public void preCommit(CommitEvent commitEvent)\r
throws CommitException {\r
}\r
});\r
\r
- binder.setBuffered(true);\r
+ fieldGroup.setBuffered(true);\r
\r
- FormBuilder builder = new FormBuilder(binder);\r
- builder.buildAndBindFields(this);\r
+ fieldGroup.buildAndBindMemberFields(this);\r
addComponent(firstName);\r
addComponent(lastName);\r
addComponent(email);\r
public void buttonClick(ClickEvent event) {\r
String msg = "Commit succesful";\r
try {\r
- binder.commit();\r
+ fieldGroup.commit();\r
} catch (CommitException e) {\r
msg = "Commit failed: " + e.getMessage();\r
}\r
new Button.ClickListener() {\r
\r
public void buttonClick(ClickEvent event) {\r
- binder.discard();\r
+ fieldGroup.discard();\r
log.log("Discarded changes");\r
\r
}\r
new Button.ClickListener() {\r
\r
public void buttonClick(ClickEvent event) {\r
- log.log(getPerson(binder).toString());\r
+ log.log(getPerson(fieldGroup).toString());\r
\r
}\r
});\r
});\r
Person p = new Person("John", "Doe", "john@doe.com", 64, Sex.MALE,\r
new Address("John street", 11223, "John's town", Country.USA));\r
- binder.setItemDataSource(new BeanItem<Person>(p));\r
+ fieldGroup.setItemDataSource(new BeanItem<Person>(p));\r
}\r
\r
public static Person getPerson(FieldGroup binder) {\r
import com.vaadin.data.fieldbinder.BeanFieldGroup;\r
import com.vaadin.data.fieldbinder.FieldGroup;\r
import com.vaadin.data.fieldbinder.FieldGroup.CommitException;\r
-import com.vaadin.data.fieldbinder.FormBuilder;\r
import com.vaadin.data.util.BeanItem;\r
import com.vaadin.tests.components.TestBase;\r
import com.vaadin.tests.data.bean.Address;\r
protected void setup() {\r
addComponent(log);\r
\r
- final BeanFieldGroup<PersonWithBeanValidationAnnotations> binder = new BeanFieldGroup<PersonWithBeanValidationAnnotations>(\r
+ final BeanFieldGroup<PersonWithBeanValidationAnnotations> fieldGroup = new BeanFieldGroup<PersonWithBeanValidationAnnotations>(\r
PersonWithBeanValidationAnnotations.class);\r
\r
- FormBuilder builder = new FormBuilder(binder);\r
- builder.buildAndBindFields(this);\r
+ fieldGroup.buildAndBindMemberFields(this);\r
addComponent(firstName);\r
addComponent(lastName);\r
addComponent(email);\r
public void buttonClick(ClickEvent event) {\r
String msg = "Commit succesful";\r
try {\r
- binder.commit();\r
+ fieldGroup.commit();\r
} catch (CommitException e) {\r
msg = "Commit failed: " + e.getMessage();\r
}\r
new Button.ClickListener() {\r
\r
public void buttonClick(ClickEvent event) {\r
- binder.discard();\r
+ fieldGroup.discard();\r
log.log("Discarded changes");\r
\r
}\r
new Button.ClickListener() {\r
\r
public void buttonClick(ClickEvent event) {\r
- log.log(getPerson(binder).toString());\r
+ log.log(getPerson(fieldGroup).toString());\r
\r
}\r
});\r
PersonWithBeanValidationAnnotations p = new PersonWithBeanValidationAnnotations(\r
"John", "Doe", "john@doe.com", 64, Sex.MALE, new Address(\r
"John street", 11223, "John's town", Country.USA));\r
- binder.setItemDataSource(new BeanItem<PersonWithBeanValidationAnnotations>(\r
- p));\r
+ fieldGroup\r
+ .setItemDataSource(new BeanItem<PersonWithBeanValidationAnnotations>(\r
+ p));\r
}\r
\r
public static Person getPerson(FieldGroup binder) {\r
\r
import com.vaadin.data.fieldbinder.BeanFieldGroup;\r
import com.vaadin.data.fieldbinder.FieldGroup;\r
-import com.vaadin.data.fieldbinder.FormBuilder;\r
import com.vaadin.data.fieldbinder.PropertyId;\r
import com.vaadin.data.util.BeanItem;\r
import com.vaadin.tests.components.TestBase;\r
\r
@Override\r
protected void setup() {\r
- FieldGroup fieldBinder = new BeanFieldGroup<Person>(Person.class);\r
- FormBuilder b = new FormBuilder(fieldBinder);\r
- b.buildAndBindFields(this);\r
+ FieldGroup fieldGroup = new BeanFieldGroup<Person>(Person.class);\r
+ fieldGroup.buildAndBindMemberFields(this);\r
\r
addComponent(firstName);\r
addComponent(lastName);\r
addComponent(streetAddress);\r
\r
- fieldBinder.setItemDataSource(new BeanItem<Person>(new Person("Who",\r
+ fieldGroup.setItemDataSource(new BeanItem<Person>(new Person("Who",\r
"me?", "email", 1, Sex.MALE, new Address("street name", 202020,\r
"City", Country.FINLAND))));\r
}\r
package com.vaadin.tests.fieldbinder;\r
\r
import com.vaadin.data.fieldbinder.BeanFieldGroup;\r
-import com.vaadin.data.fieldbinder.FormBuilder;\r
import com.vaadin.data.fieldbinder.PropertyId;\r
import com.vaadin.tests.data.bean.Address;\r
import com.vaadin.tests.data.bean.Country;\r
super.setup();\r
\r
setFieldBinder(new BeanFieldGroup<Person>(Person.class));\r
+ country = getFieldBinder().buildAndBind("country", "address.country",\r
+ NativeSelect.class);\r
getFieldBinder().bindMemberFields(this);\r
- country = new FormBuilder(getFieldBinder()).buildAndBind("country",\r
- "address.country", NativeSelect.class);\r
addComponent(firstName);\r
addComponent(lastName);\r
addComponent(streetAddress);\r