From: Artur Signell Date: Thu, 22 Dec 2011 08:20:57 +0000 (+0200) Subject: Renamed FieldBinder -> FieldGroup, BeanFieldBinder -> BeanFieldGroup X-Git-Tag: 7.0.0.alpha1~31 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=6295641ae1b0ed1c14541a85de5a82cdc7f2f827;p=vaadin-framework.git Renamed FieldBinder -> FieldGroup, BeanFieldBinder -> BeanFieldGroup based on API review meeting --- diff --git a/src/com/vaadin/data/fieldbinder/BeanFieldBinder.java b/src/com/vaadin/data/fieldbinder/BeanFieldBinder.java deleted file mode 100644 index 2b15058500..0000000000 --- a/src/com/vaadin/data/fieldbinder/BeanFieldBinder.java +++ /dev/null @@ -1,128 +0,0 @@ -/* -@VaadinApache2LicenseForJavaFiles@ - */ -package com.vaadin.data.fieldbinder; - -import com.vaadin.data.Item; -import com.vaadin.data.util.BeanItem; -import com.vaadin.data.validator.BeanValidationValidator; -import com.vaadin.ui.Field; - -public class BeanFieldBinder extends FieldBinder { - - private Class beanType; - - public BeanFieldBinder(Class beanType) { - this.beanType = beanType; - } - - @Override - protected Class getPropertyType(Object propertyId) { - if (getItemDataSource() != null) { - return super.getPropertyType(propertyId); - } else { - // Data source not set so we need to figure out the type manually - /* - * toString should never really be needed as propertyId should be of - * form "fieldName" or "fieldName.subField[.subField2]" but the - * method declaration comes from parent. - */ - java.lang.reflect.Field f; - try { - f = getField(beanType, propertyId.toString()); - return f.getType(); - } catch (SecurityException e) { - throw new BindException("Cannot determine type of propertyId '" - + propertyId + "'.", e); - } catch (NoSuchFieldException e) { - throw new BindException("Cannot determine type of propertyId '" - + propertyId + "'. The propertyId was not found in " - + beanType.getName(), e); - } - } - } - - private static java.lang.reflect.Field getField(Class cls, - String propertyId) throws SecurityException, NoSuchFieldException { - if (propertyId.contains(".")) { - String[] parts = propertyId.split("\\.", 2); - // Get the type of the field in the "cls" class - java.lang.reflect.Field field1 = getField(cls, parts[0]); - // Find the rest from the sub type - return getField(field1.getType(), parts[1]); - } else { - try { - // Try to find the field directly in the given class - java.lang.reflect.Field field1 = cls - .getDeclaredField(propertyId); - return field1; - } catch (NoSuchFieldError e) { - // Try super classes until we reach Object - Class superClass = cls.getSuperclass(); - if (superClass != Object.class) { - return getField(superClass, propertyId); - } else { - throw e; - } - } - } - } - - /** - * Helper method for setting the data source directly using a bean. This - * method wraps the bean in a {@link BeanItem} and calls - * {@link #setItemDataSource(Item)}. - * - * @param bean - * The bean to use as data source. - */ - public void setItemDataSource(T bean) { - setItemDataSource(new BeanItem(bean)); - } - - @Override - public void setItemDataSource(Item item) { - if (!(item instanceof BeanItem)) { - throw new RuntimeException(getClass().getSimpleName() - + " only supports BeanItems as item data source"); - } - super.setItemDataSource(item); - } - - @Override - public BeanItem getItemDataSource() { - return (BeanItem) super.getItemDataSource(); - } - - @Override - public void bind(Field field, Object propertyId) { - if (getItemDataSource() != null) { - // The data source is set so the property must be found in the item. - // If it is not we try to add it. - try { - getItemProperty(propertyId); - } catch (BindException e) { - // Not found, try to add a nested property; - // BeanItem property ids are always strings so this is safe - getItemDataSource().addNestedProperty((String) propertyId); - } - } - - super.bind(field, propertyId); - } - - @Override - protected void configureField(Field field) { - super.configureField(field); - // Add Bean validators if there are annotations - if (BeanValidationValidator.isImplementationAvailable()) { - BeanValidationValidator validator = new BeanValidationValidator( - beanType, getPropertyIdForField(field).toString()); - field.addValidator(validator); - if (field.getLocale() != null) { - validator.setLocale(field.getLocale()); - } - } - } - -} \ No newline at end of file diff --git a/src/com/vaadin/data/fieldbinder/BeanFieldGroup.java b/src/com/vaadin/data/fieldbinder/BeanFieldGroup.java new file mode 100644 index 0000000000..a01c6e0879 --- /dev/null +++ b/src/com/vaadin/data/fieldbinder/BeanFieldGroup.java @@ -0,0 +1,128 @@ +/* +@VaadinApache2LicenseForJavaFiles@ + */ +package com.vaadin.data.fieldbinder; + +import com.vaadin.data.Item; +import com.vaadin.data.util.BeanItem; +import com.vaadin.data.validator.BeanValidationValidator; +import com.vaadin.ui.Field; + +public class BeanFieldGroup extends FieldGroup { + + private Class beanType; + + public BeanFieldGroup(Class beanType) { + this.beanType = beanType; + } + + @Override + protected Class getPropertyType(Object propertyId) { + if (getItemDataSource() != null) { + return super.getPropertyType(propertyId); + } else { + // Data source not set so we need to figure out the type manually + /* + * toString should never really be needed as propertyId should be of + * form "fieldName" or "fieldName.subField[.subField2]" but the + * method declaration comes from parent. + */ + java.lang.reflect.Field f; + try { + f = getField(beanType, propertyId.toString()); + return f.getType(); + } catch (SecurityException e) { + throw new BindException("Cannot determine type of propertyId '" + + propertyId + "'.", e); + } catch (NoSuchFieldException e) { + throw new BindException("Cannot determine type of propertyId '" + + propertyId + "'. The propertyId was not found in " + + beanType.getName(), e); + } + } + } + + private static java.lang.reflect.Field getField(Class cls, + String propertyId) throws SecurityException, NoSuchFieldException { + if (propertyId.contains(".")) { + String[] parts = propertyId.split("\\.", 2); + // Get the type of the field in the "cls" class + java.lang.reflect.Field field1 = getField(cls, parts[0]); + // Find the rest from the sub type + return getField(field1.getType(), parts[1]); + } else { + try { + // Try to find the field directly in the given class + java.lang.reflect.Field field1 = cls + .getDeclaredField(propertyId); + return field1; + } catch (NoSuchFieldError e) { + // Try super classes until we reach Object + Class superClass = cls.getSuperclass(); + if (superClass != Object.class) { + return getField(superClass, propertyId); + } else { + throw e; + } + } + } + } + + /** + * Helper method for setting the data source directly using a bean. This + * method wraps the bean in a {@link BeanItem} and calls + * {@link #setItemDataSource(Item)}. + * + * @param bean + * The bean to use as data source. + */ + public void setItemDataSource(T bean) { + setItemDataSource(new BeanItem(bean)); + } + + @Override + public void setItemDataSource(Item item) { + if (!(item instanceof BeanItem)) { + throw new RuntimeException(getClass().getSimpleName() + + " only supports BeanItems as item data source"); + } + super.setItemDataSource(item); + } + + @Override + public BeanItem getItemDataSource() { + return (BeanItem) super.getItemDataSource(); + } + + @Override + public void bind(Field field, Object propertyId) { + if (getItemDataSource() != null) { + // The data source is set so the property must be found in the item. + // If it is not we try to add it. + try { + getItemProperty(propertyId); + } catch (BindException e) { + // Not found, try to add a nested property; + // BeanItem property ids are always strings so this is safe + getItemDataSource().addNestedProperty((String) propertyId); + } + } + + super.bind(field, propertyId); + } + + @Override + protected void configureField(Field field) { + super.configureField(field); + // Add Bean validators if there are annotations + if (BeanValidationValidator.isImplementationAvailable()) { + BeanValidationValidator validator = new BeanValidationValidator( + beanType, getPropertyIdForField(field).toString()); + field.addValidator(validator); + if (field.getLocale() != null) { + validator.setLocale(field.getLocale()); + } + } + } + +} \ No newline at end of file diff --git a/src/com/vaadin/data/fieldbinder/FieldBinder.java b/src/com/vaadin/data/fieldbinder/FieldBinder.java deleted file mode 100644 index 3df8794079..0000000000 --- a/src/com/vaadin/data/fieldbinder/FieldBinder.java +++ /dev/null @@ -1,722 +0,0 @@ -/* -@VaadinApache2LicenseForJavaFiles@ - */ -package com.vaadin.data.fieldbinder; - -import java.io.Serializable; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.logging.Logger; - -import com.vaadin.data.Item; -import com.vaadin.data.Property; -import com.vaadin.data.TransactionalProperty; -import com.vaadin.data.Validator.InvalidValueException; -import com.vaadin.data.fieldbinder.FormBuilder.FormBuilderException; -import com.vaadin.data.util.TransactionalPropertyWrapper; -import com.vaadin.tools.ReflectTools; -import com.vaadin.ui.Field; - -/** - * FIXME Javadoc - * - * See also {@link BeanFieldBinder} which makes binding fields easier when your - * data is in a bean. - * - * @author Vaadin Ltd - * @version @version@ - * @since 7.0 - */ -public class FieldBinder implements Serializable { - - private static final Logger logger = Logger.getLogger(FieldBinder.class - .getName()); - - private Item itemDataSource; - private boolean fieldsBuffered = true; - - private boolean fieldsEnabled = true; - private boolean fieldsReadOnly = false; - - private HashMap> propertyIdToField = new HashMap>(); - private LinkedHashMap, Object> fieldToPropertyId = new LinkedHashMap, Object>(); - private List commitHandlers = new ArrayList(); - - /** - * Constructs a field binder. Use {@link #setItemDataSource(Item)} to set a - * data source for the field binder. - * - */ - public FieldBinder() { - - } - - /** - * Constructs a field binder that uses the given data source. - * - * @param itemDataSource - * The data source to bind the fields to - */ - public FieldBinder(Item itemDataSource) { - setItemDataSource(itemDataSource); - } - - /** - * Updates the item that is used by this FieldBinder. Rebinds all fields to - * the properties in the new item. - * - * @param itemDataSource - * The new item to use - */ - public void setItemDataSource(Item itemDataSource) { - this.itemDataSource = itemDataSource; - - for (Field f : fieldToPropertyId.keySet()) { - bind(f, fieldToPropertyId.get(f)); - } - } - - /** - * Gets the item used by this FieldBinder. Note that you must call - * {@link #commit()} for the item to be updated unless buffered mode has - * been switched off. - * - * @see #setFieldsBuffered(boolean) - * @see #commit() - * - * @return The item used by this FieldBinder - */ - public Item getItemDataSource() { - return itemDataSource; - } - - /** - * Checks the buffered mode for the bound fields. - *

- * - * @see #setFieldsBuffered(boolean) for more details on buffered mode - * - * @see Field#isFieldsBuffered() - * @return true if buffered mode is on, false otherwise - * - */ - public boolean isFieldsBuffered() { - return fieldsBuffered; - } - - /** - * Sets the buffered mode for the bound fields. - *

- * When buffered mode is on the item will not be updated until - * {@link #commit()} is called. If buffered mode is off the item will be - * updated once the fields are updated. - *

- *

- * The default is to use buffered mode. - *

- * - * @see Field#setFieldsBuffered(boolean) - * @param fieldsBuffered - * true to turn on buffered mode, false otherwise - */ - public void setFieldsBuffered(boolean fieldsBuffered) { - if (fieldsBuffered == this.fieldsBuffered) { - return; - } - - this.fieldsBuffered = fieldsBuffered; - for (Field field : getFields()) { - field.setBuffered(fieldsBuffered); - } - } - - /** - * Returns the enabled status for the fields. - *

- * Note that this will not accurately represent the enabled status of all - * fields if you change the enabled status of the fields through some other - * method than {@link #setFieldsEnabled(boolean)}. - * - * @return true if the fields are enabled, false otherwise - */ - public boolean isFieldsEnabled() { - return fieldsEnabled; - } - - /** - * Updates the enabled state of all bound fields. - * - * @param fieldsEnabled - * true to enable all bound fields, false to disable them - */ - public void setFieldsEnabled(boolean fieldsEnabled) { - this.fieldsEnabled = fieldsEnabled; - for (Field field : getFields()) { - field.setEnabled(fieldsEnabled); - } - } - - /** - * Returns the read only status for the fields. - *

- * Note that this will not accurately represent the read only status of all - * fields if you change the read only status of the fields through some - * other method than {@link #setFieldsReadOnly(boolean)}. - * - * @return true if the fields are set to read only, false otherwise - */ - public boolean isFieldsReadOnly() { - return fieldsReadOnly; - } - - /** - * Updates the read only state of all bound fields. - * - * @param fieldsReadOnly - * true to set all bound fields to read only, false to set them - * to read write - */ - public void setFieldsReadOnly(boolean fieldsReadOnly) { - this.fieldsReadOnly = fieldsReadOnly; - } - - /** - * Returns a collection of all fields that have been bound. - *

- * The fields are not returned in any specific order. - *

- * - * @return A collection with all bound Fields - */ - public Collection> getFields() { - return fieldToPropertyId.keySet(); - } - - /** - * Binds the field with the given propertyId from the current item. If an - * item has not been set then the binding is postponed until the item is set - * using {@link #setItemDataSource(Item)}. - *

- * This method also adds validators when applicable. - *

- * - * @param field - * The field to bind - * @param propertyId - * The propertyId to bind to the field - * @throws BindException - * If the property id is already bound to another field by this - * field binder - */ - public void bind(Field field, Object propertyId) throws BindException { - if (propertyIdToField.containsKey(propertyId) - && propertyIdToField.get(propertyId) != field) { - throw new BindException("Property id " + propertyId - + " is already bound to another field"); - } - fieldToPropertyId.put(field, propertyId); - propertyIdToField.put(propertyId, field); - if (itemDataSource == null) { - // Will be bound when data source is set - return; - } - - field.setPropertyDataSource(wrapInTransactionalProperty(getItemProperty(propertyId))); - configureField(field); - } - - private TransactionalProperty wrapInTransactionalProperty( - Property itemProperty) { - return new TransactionalPropertyWrapper(itemProperty); - } - - /** - * Gets the property with the given property id from the item. - * - * @param propertyId - * The id if the property to find - * @return The property with the given id from the item - * @throws BindException - * If the property was not found in the item or no item has been - * set - */ - protected Property getItemProperty(Object propertyId) - throws BindException { - Item item = getItemDataSource(); - if (item == null) { - throw new BindException("Could not lookup property with id " - + propertyId + " as no item has been set"); - } - Property p = item.getItemProperty(propertyId); - if (p == null) { - throw new BindException("A property with id " + propertyId - + " was not found in the item"); - } - return p; - } - - /** - * Detaches the field from its property id and removes it from this - * FieldBinder. - *

- * Note that the field is not detached from its property data source if it - * is no longer connected to the same property id it was bound to using this - * FieldBinder. - * - * @param field - * The field to detach - * @throws BindException - * If the field is not bound by this field binder or not bound - * to the correct property id - */ - public void remove(Field field) throws BindException { - Object propertyId = fieldToPropertyId.get(field); - if (propertyId == null) { - throw new BindException( - "The given field is not part of this FieldBinder"); - } - - Property fieldDataSource = field.getPropertyDataSource(); - if (fieldDataSource instanceof TransactionalPropertyWrapper) { - fieldDataSource = ((TransactionalPropertyWrapper) fieldDataSource) - .getWrappedProperty(); - } - if (fieldDataSource == getItemProperty(propertyId)) { - field.setPropertyDataSource(null); - } - fieldToPropertyId.remove(field); - propertyIdToField.remove(propertyId); - } - - /** - * Configures a field with the settings set for this FieldBinder. - *

- * By default this updates the buffered, read only and enabled state of the - * field. Also adds validators when applicable. - * - * @param field - * The field to update - */ - protected void configureField(Field field) { - field.setBuffered(isFieldsBuffered()); - - field.setEnabled(isFieldsEnabled()); - field.setReadOnly(isFieldsReadOnly()); - } - - /** - * Gets the type of the property with the given property id. - * - * @param propertyId - * The propertyId. Must be find - * @return The type of the property - */ - protected Class getPropertyType(Object propertyId) throws BindException { - if (getItemDataSource() == null) { - throw new BindException( - "Property type for '" - + propertyId - + "' could not be determined. No item data source has been set."); - } - Property p = getItemDataSource().getItemProperty(propertyId); - if (p == null) { - throw new BindException( - "Property type for '" - + propertyId - + "' could not be determined. No property with that id was found."); - } - - return p.getType(); - } - - /** - * Returns a collection of all property ids that have been bound to fields. - *

- * Note that this will return property ids even before the item has been - * set. In that case it returns the property ids that will be bound once the - * item is set. - *

- *

- * No guarantee is given for the order of the property ids - *

- * - * @return A collection of bound property ids - */ - public Collection getBoundPropertyIds() { - return Collections.unmodifiableCollection(propertyIdToField.keySet()); - } - - /** - * Returns a collection of all property ids that exist in the item set using - * {@link #setItemDataSource(Item)} but have not been bound to fields. - *

- * Will always return an empty collection before an item has been set using - * {@link #setItemDataSource(Item)}. - *

- *

- * No guarantee is given for the order of the property ids - *

- * - * @return A collection of property ids that have not been bound to fields - */ - protected Collection getUnboundPropertyIds() { - if (getItemDataSource() == null) { - return new ArrayList(); - } - List unboundPropertyIds = new ArrayList(); - unboundPropertyIds.addAll(getItemDataSource().getItemPropertyIds()); - unboundPropertyIds.removeAll(propertyIdToField.keySet()); - return unboundPropertyIds; - } - - /** - * Commits all changes done to the bound fields. - *

- * Calls all {@link CommitHandler}s before and after committing the field - * changes to the item data source. The whole commit is aborted and state is - * restored to what it was before commit was called if any - * {@link CommitHandler} throws a CommitException or there is a problem - * committing the fields - * - * @throws CommitException - * If the commit was aborted - */ - public void commit() throws CommitException { - if (!isFieldsBuffered()) { - // Not using buffered mode, nothing to do - return; - } - for (Field f : fieldToPropertyId.keySet()) { - ((TransactionalProperty) f.getPropertyDataSource()) - .startTransaction(); - } - try { - firePreCommitEvent(); - // Commit the field values to the properties - for (Field f : fieldToPropertyId.keySet()) { - f.commit(); - } - firePostCommitEvent(); - - // Commit the properties - for (Field f : fieldToPropertyId.keySet()) { - ((TransactionalProperty) f.getPropertyDataSource()).commit(); - } - - } catch (Exception e) { - for (Field f : fieldToPropertyId.keySet()) { - try { - ((TransactionalProperty) f.getPropertyDataSource()) - .rollback(); - } catch (Exception rollbackException) { - // FIXME: What to do ? - } - } - - throw new CommitException("Commit failed", e); - } - - } - - /** - * Sends a preCommit event to all registered commit handlers - * - * @throws CommitException - * If the commit should be aborted - */ - private void firePreCommitEvent() throws CommitException { - CommitHandler[] handlers = commitHandlers - .toArray(new CommitHandler[commitHandlers.size()]); - - for (CommitHandler handler : handlers) { - handler.preCommit(new CommitEvent(this)); - } - } - - /** - * Sends a postCommit event to all registered commit handlers - * - * @throws CommitException - * If the commit should be aborted - */ - private void firePostCommitEvent() throws CommitException { - CommitHandler[] handlers = commitHandlers - .toArray(new CommitHandler[commitHandlers.size()]); - - for (CommitHandler handler : handlers) { - handler.postCommit(new CommitEvent(this)); - } - } - - /** - * Discards all changes done to the bound fields. - *

- * Only has effect if buffered mode is used. - * - */ - public void discard() { - for (Field f : fieldToPropertyId.keySet()) { - try { - f.discard(); - } catch (Exception e) { - // TODO: handle exception - // What can we do if discard fails other than try to discard all - // other fields? - } - } - } - - /** - * Returns the field that is bound to the given property id - * - * @param propertyId - * The property id to use to lookup the field - * @return The field that is bound to the property id or null if no field is - * bound to that property id - */ - public Field getFieldForPropertyId(Object propertyId) { - return propertyIdToField.get(propertyId); - } - - /** - * Returns the property id that is bound to the given field - * - * @param field - * The field to use to lookup the property id - * @return The property id that is bound to the field or null if the field - * is not bound to any property id by this FieldBinder - */ - public Object getPropertyIdForField(Field field) { - return fieldToPropertyId.get(field); - } - - /** - * Adds a commit handler. - *

- * The commit handler is called before the field values are committed to the - * item ( {@link CommitHandler#preCommit(CommitEvent)}) and after the item - * has been updated ({@link CommitHandler#postCommit(CommitEvent)}). If a - * {@link CommitHandler} throws a CommitException the whole commit is - * aborted and the fields retain their old values. - * - * @param commitHandler - * The commit handler to add - */ - public void addCommitHandler(CommitHandler commitHandler) { - commitHandlers.add(commitHandler); - } - - /** - * Removes the given commit handler. - * - * @see #addCommitHandler(CommitHandler) - * - * @param commitHandler - * The commit handler to remove - */ - public void removeCommitHandler(CommitHandler commitHandler) { - commitHandlers.remove(commitHandler); - } - - /** - * Returns a list of all commit handlers for this {@link FieldBinder}. - *

- * Use {@link #addCommitHandler(CommitHandler)} and - * {@link #removeCommitHandler(CommitHandler)} to register or unregister a - * commit handler. - * - * @return A collection of commit handlers - */ - protected Collection getCommitHandlers() { - return Collections.unmodifiableCollection(commitHandlers); - } - - /** - * FIXME Javadoc - * - */ - public interface CommitHandler extends Serializable { - /** - * Called before changes are committed to the field and the item is - * updated. - *

- * Throw a {@link CommitException} to abort the commit. - * - * @param commitEvent - * An event containing information regarding the commit - * @throws CommitException - * if the commit should be aborted - */ - public void preCommit(CommitEvent commitEvent) throws CommitException; - - /** - * Called after changes are committed to the fields and the item is - * updated.. - *

- * Throw a {@link CommitException} to abort the commit. - * - * @param commitEvent - * An event containing information regarding the commit - * @throws CommitException - * if the commit should be aborted - */ - public void postCommit(CommitEvent commitEvent) throws CommitException; - } - - /** - * FIXME javadoc - * - */ - public static class CommitEvent implements Serializable { - private FieldBinder fieldBinder; - - private CommitEvent(FieldBinder fieldBinder) { - this.fieldBinder = fieldBinder; - } - - /** - * Returns the field binder that this commit relates to - * - * @return The FieldBinder that is being committed. - */ - public FieldBinder getFieldBinder() { - return fieldBinder; - } - - } - - /** - * Checks the validity of the bound fields. - *

- * Call the {@link Field#validate()} for the fields to get the individual - * error messages. - * - * @return true if all bound fields are valid, false otherwise. - */ - public boolean isAllFieldsValid() { - try { - for (Field field : getFields()) { - field.validate(); - } - return true; - } catch (InvalidValueException e) { - return false; - } - } - - /** - * Checks if any bound field has been modified. - * - * @return true if at least on field has been modified, false otherwise - */ - public boolean isAnyFieldModified() { - for (Field field : getFields()) { - if (field.isModified()) { - return true; - } - } - return false; - } - - /** - * 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 - * non-null fields for which a property id can be determined are bound to - * the property id. - * - * @param object - * The object to process - * @throws FormBuilderException - * If there is a problem building or binding a field - */ - public void bindFields(Object object) throws BindException { - Class objectClass = object.getClass(); - - for (java.lang.reflect.Field f : objectClass.getDeclaredFields()) { - - if (!Field.class.isAssignableFrom(f.getType())) { - // Process next field - continue; - } - - PropertyId propertyIdAnnotation = f.getAnnotation(PropertyId.class); - - 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 = getPropertyType(propertyId); - } catch (BindException e) { - // Property id was not found, skip this field - continue; - } - - try { - // Get the field from the object - Field field = (Field) ReflectTools.getJavaFieldValue( - object, f); - // Bind it to the property id - bind(field, propertyId); - } catch (Exception e) { - // If we cannot determine the value, just skip the field and try - // the next one - continue; - } - - } - } - - public static class CommitException extends Exception { - - public CommitException() { - super(); - // TODO Auto-generated constructor stub - } - - public CommitException(String message, Throwable cause) { - super(message, cause); - // TODO Auto-generated constructor stub - } - - public CommitException(String message) { - super(message); - // TODO Auto-generated constructor stub - } - - public CommitException(Throwable cause) { - super(cause); - // TODO Auto-generated constructor stub - } - - } - - public static class BindException extends RuntimeException { - - public BindException(String message) { - super(message); - } - - public BindException(String message, Throwable t) { - super(message, t); - } - - } -} \ No newline at end of file diff --git a/src/com/vaadin/data/fieldbinder/FieldGroup.java b/src/com/vaadin/data/fieldbinder/FieldGroup.java new file mode 100644 index 0000000000..a5cf6b993e --- /dev/null +++ b/src/com/vaadin/data/fieldbinder/FieldGroup.java @@ -0,0 +1,733 @@ +/* +@VaadinApache2LicenseForJavaFiles@ + */ +package com.vaadin.data.fieldbinder; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.logging.Logger; + +import com.vaadin.data.Item; +import com.vaadin.data.Property; +import com.vaadin.data.TransactionalProperty; +import com.vaadin.data.Validator.InvalidValueException; +import com.vaadin.data.fieldbinder.FormBuilder.FormBuilderException; +import com.vaadin.data.util.TransactionalPropertyWrapper; +import com.vaadin.tools.ReflectTools; +import com.vaadin.ui.Field; +import com.vaadin.ui.Form; + +/** + * FieldGroup provides an easy way of binding fields to data and handling + * commits of these fields. + *

+ * The functionality of FieldGroup is similar to {@link Form} but + * {@link FieldGroup} does not handle layouts in any way. The typical use case + * is to create a layout outside the FieldGroup and then use FieldGroup to bind + * the fields to a data source. + *

+ *

+ * {@link FieldGroup} is not a UI component so it cannot be added to a layout. + * Using the buildAndBind methods {@link FieldGroup} can create fields for you + * using a FieldGroupFieldFactory but you still have to add them to the correct + * position in your layout. + *

+ * + * @author Vaadin Ltd + * @version @version@ + * @since 7.0 + */ +public class FieldGroup implements Serializable { + + private static final Logger logger = Logger.getLogger(FieldGroup.class + .getName()); + + private Item itemDataSource; + private boolean fieldsBuffered = true; + + private boolean fieldsEnabled = true; + private boolean fieldsReadOnly = false; + + private HashMap> propertyIdToField = new HashMap>(); + private LinkedHashMap, Object> fieldToPropertyId = new LinkedHashMap, Object>(); + private List commitHandlers = new ArrayList(); + + /** + * Constructs a field binder. Use {@link #setItemDataSource(Item)} to set a + * data source for the field binder. + * + */ + public FieldGroup() { + + } + + /** + * Constructs a field binder that uses the given data source. + * + * @param itemDataSource + * The data source to bind the fields to + */ + public FieldGroup(Item itemDataSource) { + setItemDataSource(itemDataSource); + } + + /** + * Updates the item that is used by this FieldBinder. Rebinds all fields to + * the properties in the new item. + * + * @param itemDataSource + * The new item to use + */ + public void setItemDataSource(Item itemDataSource) { + this.itemDataSource = itemDataSource; + + for (Field f : fieldToPropertyId.keySet()) { + bind(f, fieldToPropertyId.get(f)); + } + } + + /** + * Gets the item used by this FieldBinder. Note that you must call + * {@link #commit()} for the item to be updated unless buffered mode has + * been switched off. + * + * @see #setFieldsBuffered(boolean) + * @see #commit() + * + * @return The item used by this FieldBinder + */ + public Item getItemDataSource() { + return itemDataSource; + } + + /** + * Checks the buffered mode for the bound fields. + *

+ * + * @see #setFieldsBuffered(boolean) for more details on buffered mode + * + * @see Field#isFieldsBuffered() + * @return true if buffered mode is on, false otherwise + * + */ + public boolean isFieldsBuffered() { + return fieldsBuffered; + } + + /** + * Sets the buffered mode for the bound fields. + *

+ * When buffered mode is on the item will not be updated until + * {@link #commit()} is called. If buffered mode is off the item will be + * updated once the fields are updated. + *

+ *

+ * The default is to use buffered mode. + *

+ * + * @see Field#setFieldsBuffered(boolean) + * @param fieldsBuffered + * true to turn on buffered mode, false otherwise + */ + public void setFieldsBuffered(boolean fieldsBuffered) { + if (fieldsBuffered == this.fieldsBuffered) { + return; + } + + this.fieldsBuffered = fieldsBuffered; + for (Field field : getFields()) { + field.setBuffered(fieldsBuffered); + } + } + + /** + * Returns the enabled status for the fields. + *

+ * Note that this will not accurately represent the enabled status of all + * fields if you change the enabled status of the fields through some other + * method than {@link #setFieldsEnabled(boolean)}. + * + * @return true if the fields are enabled, false otherwise + */ + public boolean isFieldsEnabled() { + return fieldsEnabled; + } + + /** + * Updates the enabled state of all bound fields. + * + * @param fieldsEnabled + * true to enable all bound fields, false to disable them + */ + public void setFieldsEnabled(boolean fieldsEnabled) { + this.fieldsEnabled = fieldsEnabled; + for (Field field : getFields()) { + field.setEnabled(fieldsEnabled); + } + } + + /** + * Returns the read only status for the fields. + *

+ * Note that this will not accurately represent the read only status of all + * fields if you change the read only status of the fields through some + * other method than {@link #setFieldsReadOnly(boolean)}. + * + * @return true if the fields are set to read only, false otherwise + */ + public boolean isFieldsReadOnly() { + return fieldsReadOnly; + } + + /** + * Updates the read only state of all bound fields. + * + * @param fieldsReadOnly + * true to set all bound fields to read only, false to set them + * to read write + */ + public void setFieldsReadOnly(boolean fieldsReadOnly) { + this.fieldsReadOnly = fieldsReadOnly; + } + + /** + * Returns a collection of all fields that have been bound. + *

+ * The fields are not returned in any specific order. + *

+ * + * @return A collection with all bound Fields + */ + public Collection> getFields() { + return fieldToPropertyId.keySet(); + } + + /** + * Binds the field with the given propertyId from the current item. If an + * item has not been set then the binding is postponed until the item is set + * using {@link #setItemDataSource(Item)}. + *

+ * This method also adds validators when applicable. + *

+ * + * @param field + * The field to bind + * @param propertyId + * The propertyId to bind to the field + * @throws BindException + * If the property id is already bound to another field by this + * field binder + */ + public void bind(Field field, Object propertyId) throws BindException { + if (propertyIdToField.containsKey(propertyId) + && propertyIdToField.get(propertyId) != field) { + throw new BindException("Property id " + propertyId + + " is already bound to another field"); + } + fieldToPropertyId.put(field, propertyId); + propertyIdToField.put(propertyId, field); + if (itemDataSource == null) { + // Will be bound when data source is set + return; + } + + field.setPropertyDataSource(wrapInTransactionalProperty(getItemProperty(propertyId))); + configureField(field); + } + + private TransactionalProperty wrapInTransactionalProperty( + Property itemProperty) { + return new TransactionalPropertyWrapper(itemProperty); + } + + /** + * Gets the property with the given property id from the item. + * + * @param propertyId + * The id if the property to find + * @return The property with the given id from the item + * @throws BindException + * If the property was not found in the item or no item has been + * set + */ + protected Property getItemProperty(Object propertyId) + throws BindException { + Item item = getItemDataSource(); + if (item == null) { + throw new BindException("Could not lookup property with id " + + propertyId + " as no item has been set"); + } + Property p = item.getItemProperty(propertyId); + if (p == null) { + throw new BindException("A property with id " + propertyId + + " was not found in the item"); + } + return p; + } + + /** + * Detaches the field from its property id and removes it from this + * FieldBinder. + *

+ * Note that the field is not detached from its property data source if it + * is no longer connected to the same property id it was bound to using this + * FieldBinder. + * + * @param field + * The field to detach + * @throws BindException + * If the field is not bound by this field binder or not bound + * to the correct property id + */ + public void remove(Field field) throws BindException { + Object propertyId = fieldToPropertyId.get(field); + if (propertyId == null) { + throw new BindException( + "The given field is not part of this FieldBinder"); + } + + Property fieldDataSource = field.getPropertyDataSource(); + if (fieldDataSource instanceof TransactionalPropertyWrapper) { + fieldDataSource = ((TransactionalPropertyWrapper) fieldDataSource) + .getWrappedProperty(); + } + if (fieldDataSource == getItemProperty(propertyId)) { + field.setPropertyDataSource(null); + } + fieldToPropertyId.remove(field); + propertyIdToField.remove(propertyId); + } + + /** + * Configures a field with the settings set for this FieldBinder. + *

+ * By default this updates the buffered, read only and enabled state of the + * field. Also adds validators when applicable. + * + * @param field + * The field to update + */ + protected void configureField(Field field) { + field.setBuffered(isFieldsBuffered()); + + field.setEnabled(isFieldsEnabled()); + field.setReadOnly(isFieldsReadOnly()); + } + + /** + * Gets the type of the property with the given property id. + * + * @param propertyId + * The propertyId. Must be find + * @return The type of the property + */ + protected Class getPropertyType(Object propertyId) throws BindException { + if (getItemDataSource() == null) { + throw new BindException( + "Property type for '" + + propertyId + + "' could not be determined. No item data source has been set."); + } + Property p = getItemDataSource().getItemProperty(propertyId); + if (p == null) { + throw new BindException( + "Property type for '" + + propertyId + + "' could not be determined. No property with that id was found."); + } + + return p.getType(); + } + + /** + * Returns a collection of all property ids that have been bound to fields. + *

+ * Note that this will return property ids even before the item has been + * set. In that case it returns the property ids that will be bound once the + * item is set. + *

+ *

+ * No guarantee is given for the order of the property ids + *

+ * + * @return A collection of bound property ids + */ + public Collection getBoundPropertyIds() { + return Collections.unmodifiableCollection(propertyIdToField.keySet()); + } + + /** + * Returns a collection of all property ids that exist in the item set using + * {@link #setItemDataSource(Item)} but have not been bound to fields. + *

+ * Will always return an empty collection before an item has been set using + * {@link #setItemDataSource(Item)}. + *

+ *

+ * No guarantee is given for the order of the property ids + *

+ * + * @return A collection of property ids that have not been bound to fields + */ + protected Collection getUnboundPropertyIds() { + if (getItemDataSource() == null) { + return new ArrayList(); + } + List unboundPropertyIds = new ArrayList(); + unboundPropertyIds.addAll(getItemDataSource().getItemPropertyIds()); + unboundPropertyIds.removeAll(propertyIdToField.keySet()); + return unboundPropertyIds; + } + + /** + * Commits all changes done to the bound fields. + *

+ * Calls all {@link CommitHandler}s before and after committing the field + * changes to the item data source. The whole commit is aborted and state is + * restored to what it was before commit was called if any + * {@link CommitHandler} throws a CommitException or there is a problem + * committing the fields + * + * @throws CommitException + * If the commit was aborted + */ + public void commit() throws CommitException { + if (!isFieldsBuffered()) { + // Not using buffered mode, nothing to do + return; + } + for (Field f : fieldToPropertyId.keySet()) { + ((TransactionalProperty) f.getPropertyDataSource()) + .startTransaction(); + } + try { + firePreCommitEvent(); + // Commit the field values to the properties + for (Field f : fieldToPropertyId.keySet()) { + f.commit(); + } + firePostCommitEvent(); + + // Commit the properties + for (Field f : fieldToPropertyId.keySet()) { + ((TransactionalProperty) f.getPropertyDataSource()).commit(); + } + + } catch (Exception e) { + for (Field f : fieldToPropertyId.keySet()) { + try { + ((TransactionalProperty) f.getPropertyDataSource()) + .rollback(); + } catch (Exception rollbackException) { + // FIXME: What to do ? + } + } + + throw new CommitException("Commit failed", e); + } + + } + + /** + * Sends a preCommit event to all registered commit handlers + * + * @throws CommitException + * If the commit should be aborted + */ + private void firePreCommitEvent() throws CommitException { + CommitHandler[] handlers = commitHandlers + .toArray(new CommitHandler[commitHandlers.size()]); + + for (CommitHandler handler : handlers) { + handler.preCommit(new CommitEvent(this)); + } + } + + /** + * Sends a postCommit event to all registered commit handlers + * + * @throws CommitException + * If the commit should be aborted + */ + private void firePostCommitEvent() throws CommitException { + CommitHandler[] handlers = commitHandlers + .toArray(new CommitHandler[commitHandlers.size()]); + + for (CommitHandler handler : handlers) { + handler.postCommit(new CommitEvent(this)); + } + } + + /** + * Discards all changes done to the bound fields. + *

+ * Only has effect if buffered mode is used. + * + */ + public void discard() { + for (Field f : fieldToPropertyId.keySet()) { + try { + f.discard(); + } catch (Exception e) { + // TODO: handle exception + // What can we do if discard fails other than try to discard all + // other fields? + } + } + } + + /** + * Returns the field that is bound to the given property id + * + * @param propertyId + * The property id to use to lookup the field + * @return The field that is bound to the property id or null if no field is + * bound to that property id + */ + public Field getFieldForPropertyId(Object propertyId) { + return propertyIdToField.get(propertyId); + } + + /** + * Returns the property id that is bound to the given field + * + * @param field + * The field to use to lookup the property id + * @return The property id that is bound to the field or null if the field + * is not bound to any property id by this FieldBinder + */ + public Object getPropertyIdForField(Field field) { + return fieldToPropertyId.get(field); + } + + /** + * Adds a commit handler. + *

+ * The commit handler is called before the field values are committed to the + * item ( {@link CommitHandler#preCommit(CommitEvent)}) and after the item + * has been updated ({@link CommitHandler#postCommit(CommitEvent)}). If a + * {@link CommitHandler} throws a CommitException the whole commit is + * aborted and the fields retain their old values. + * + * @param commitHandler + * The commit handler to add + */ + public void addCommitHandler(CommitHandler commitHandler) { + commitHandlers.add(commitHandler); + } + + /** + * Removes the given commit handler. + * + * @see #addCommitHandler(CommitHandler) + * + * @param commitHandler + * The commit handler to remove + */ + public void removeCommitHandler(CommitHandler commitHandler) { + commitHandlers.remove(commitHandler); + } + + /** + * Returns a list of all commit handlers for this {@link FieldGroup}. + *

+ * Use {@link #addCommitHandler(CommitHandler)} and + * {@link #removeCommitHandler(CommitHandler)} to register or unregister a + * commit handler. + * + * @return A collection of commit handlers + */ + protected Collection getCommitHandlers() { + return Collections.unmodifiableCollection(commitHandlers); + } + + /** + * FIXME Javadoc + * + */ + public interface CommitHandler extends Serializable { + /** + * Called before changes are committed to the field and the item is + * updated. + *

+ * Throw a {@link CommitException} to abort the commit. + * + * @param commitEvent + * An event containing information regarding the commit + * @throws CommitException + * if the commit should be aborted + */ + public void preCommit(CommitEvent commitEvent) throws CommitException; + + /** + * Called after changes are committed to the fields and the item is + * updated.. + *

+ * Throw a {@link CommitException} to abort the commit. + * + * @param commitEvent + * An event containing information regarding the commit + * @throws CommitException + * if the commit should be aborted + */ + public void postCommit(CommitEvent commitEvent) throws CommitException; + } + + /** + * FIXME javadoc + * + */ + public static class CommitEvent implements Serializable { + private FieldGroup fieldBinder; + + private CommitEvent(FieldGroup fieldBinder) { + this.fieldBinder = fieldBinder; + } + + /** + * Returns the field binder that this commit relates to + * + * @return The FieldBinder that is being committed. + */ + public FieldGroup getFieldBinder() { + return fieldBinder; + } + + } + + /** + * Checks the validity of the bound fields. + *

+ * Call the {@link Field#validate()} for the fields to get the individual + * error messages. + * + * @return true if all bound fields are valid, false otherwise. + */ + public boolean isAllFieldsValid() { + try { + for (Field field : getFields()) { + field.validate(); + } + return true; + } catch (InvalidValueException e) { + return false; + } + } + + /** + * Checks if any bound field has been modified. + * + * @return true if at least on field has been modified, false otherwise + */ + public boolean isAnyFieldModified() { + for (Field field : getFields()) { + if (field.isModified()) { + return true; + } + } + return false; + } + + /** + * 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 + * non-null fields for which a property id can be determined are bound to + * the property id. + * + * @param object + * The object to process + * @throws FormBuilderException + * If there is a problem building or binding a field + */ + public void bindFields(Object object) throws BindException { + Class objectClass = object.getClass(); + + for (java.lang.reflect.Field f : objectClass.getDeclaredFields()) { + + if (!Field.class.isAssignableFrom(f.getType())) { + // Process next field + continue; + } + + PropertyId propertyIdAnnotation = f.getAnnotation(PropertyId.class); + + 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 = getPropertyType(propertyId); + } catch (BindException e) { + // Property id was not found, skip this field + continue; + } + + try { + // Get the field from the object + Field field = (Field) ReflectTools.getJavaFieldValue( + object, f); + // Bind it to the property id + bind(field, propertyId); + } catch (Exception e) { + // If we cannot determine the value, just skip the field and try + // the next one + continue; + } + + } + } + + public static class CommitException extends Exception { + + public CommitException() { + super(); + // TODO Auto-generated constructor stub + } + + public CommitException(String message, Throwable cause) { + super(message, cause); + // TODO Auto-generated constructor stub + } + + public CommitException(String message) { + super(message); + // TODO Auto-generated constructor stub + } + + public CommitException(Throwable cause) { + super(cause); + // TODO Auto-generated constructor stub + } + + } + + public static class BindException extends RuntimeException { + + public BindException(String message) { + super(message); + } + + public BindException(String message, Throwable t) { + super(message, t); + } + + } +} \ No newline at end of file diff --git a/src/com/vaadin/data/fieldbinder/FormBuilder.java b/src/com/vaadin/data/fieldbinder/FormBuilder.java index 4597d520b3..ccf060ec97 100644 --- a/src/com/vaadin/data/fieldbinder/FormBuilder.java +++ b/src/com/vaadin/data/fieldbinder/FormBuilder.java @@ -7,7 +7,7 @@ import java.io.Serializable; import java.lang.reflect.InvocationTargetException; import java.util.logging.Logger; -import com.vaadin.data.fieldbinder.FieldBinder.BindException; +import com.vaadin.data.fieldbinder.FieldGroup.BindException; import com.vaadin.tools.ReflectTools; import com.vaadin.ui.DefaultFieldFactory; import com.vaadin.ui.Field; @@ -21,7 +21,7 @@ import com.vaadin.ui.Field; public class FormBuilder implements Serializable { private FormBuilderFieldFactory fieldFactory = new DefaultFormBuilderFieldFactory(); - private FieldBinder fieldBinder; + private FieldGroup fieldBinder; private static final Logger logger = Logger.getLogger(FormBuilder.class .getName()); @@ -32,14 +32,14 @@ public class FormBuilder implements Serializable { * The FieldBinder to use for binding the fields to the data * source */ - public FormBuilder(FieldBinder fieldBinder) { + public FormBuilder(FieldGroup fieldBinder) { this.fieldBinder = fieldBinder; } /** * TODO: javadoc */ - protected FieldBinder getFieldBinder() { + protected FieldGroup getFieldBinder() { return fieldBinder; } diff --git a/tests/testbench/com/vaadin/tests/fieldbinder/AbstractBeanFieldBinderTest.java b/tests/testbench/com/vaadin/tests/fieldbinder/AbstractBeanFieldBinderTest.java index b35d85995c..8b4dac2d6f 100644 --- a/tests/testbench/com/vaadin/tests/fieldbinder/AbstractBeanFieldBinderTest.java +++ b/tests/testbench/com/vaadin/tests/fieldbinder/AbstractBeanFieldBinderTest.java @@ -1,7 +1,7 @@ package com.vaadin.tests.fieldbinder; -import com.vaadin.data.fieldbinder.BeanFieldBinder; -import com.vaadin.data.fieldbinder.FieldBinder.CommitException; +import com.vaadin.data.fieldbinder.BeanFieldGroup; +import com.vaadin.data.fieldbinder.FieldGroup.CommitException; import com.vaadin.tests.components.TestBase; import com.vaadin.tests.util.Log; import com.vaadin.ui.Button; @@ -16,7 +16,7 @@ public abstract class AbstractBeanFieldBinderTest extends TestBase { private Button discardButton; private Button showBeanButton; - private BeanFieldBinder fieldBinder; + private BeanFieldGroup fieldBinder; @Override protected void setup() { @@ -73,11 +73,11 @@ public abstract class AbstractBeanFieldBinderTest extends TestBase { return commitButton; } - protected BeanFieldBinder getFieldBinder() { + protected BeanFieldGroup getFieldBinder() { return fieldBinder; } - protected void setFieldBinder(BeanFieldBinder beanFieldBinder) { + protected void setFieldBinder(BeanFieldGroup beanFieldBinder) { fieldBinder = beanFieldBinder; } diff --git a/tests/testbench/com/vaadin/tests/fieldbinder/BasicPersonForm.java b/tests/testbench/com/vaadin/tests/fieldbinder/BasicPersonForm.java index de7193d849..24901e655c 100644 --- a/tests/testbench/com/vaadin/tests/fieldbinder/BasicPersonForm.java +++ b/tests/testbench/com/vaadin/tests/fieldbinder/BasicPersonForm.java @@ -1,10 +1,10 @@ package com.vaadin.tests.fieldbinder; -import com.vaadin.data.fieldbinder.BeanFieldBinder; -import com.vaadin.data.fieldbinder.FieldBinder; -import com.vaadin.data.fieldbinder.FieldBinder.CommitEvent; -import com.vaadin.data.fieldbinder.FieldBinder.CommitException; -import com.vaadin.data.fieldbinder.FieldBinder.CommitHandler; +import com.vaadin.data.fieldbinder.BeanFieldGroup; +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; @@ -65,7 +65,7 @@ public class BasicPersonForm extends TestBase { super("Configuration"); BeanItem bi = new BeanItem( configuration); - FieldBinder confBinder = new FieldBinder(bi); + FieldGroup confBinder = new FieldGroup(bi); confBinder.setItemDataSource(bi); confBinder.setFieldsBuffered(false); @@ -83,7 +83,7 @@ public class BasicPersonForm extends TestBase { Panel confPanel = new ConfigurationPanel(); addComponent(confPanel); - final FieldBinder binder = new BeanFieldBinder(Person.class); + final FieldGroup binder = new BeanFieldGroup(Person.class); binder.addCommitHandler(new CommitHandler() { public void preCommit(CommitEvent commitEvent) @@ -176,7 +176,7 @@ public class BasicPersonForm extends TestBase { binder.setItemDataSource(new BeanItem(p)); } - public static Person getPerson(FieldBinder binder) { + public static Person getPerson(FieldGroup binder) { return ((BeanItem) binder.getItemDataSource()).getBean(); } diff --git a/tests/testbench/com/vaadin/tests/fieldbinder/FieldBinderWithBeanValidation.java b/tests/testbench/com/vaadin/tests/fieldbinder/FieldBinderWithBeanValidation.java index 43ed23e5ad..9af14cb9fd 100644 --- a/tests/testbench/com/vaadin/tests/fieldbinder/FieldBinderWithBeanValidation.java +++ b/tests/testbench/com/vaadin/tests/fieldbinder/FieldBinderWithBeanValidation.java @@ -1,8 +1,8 @@ package com.vaadin.tests.fieldbinder; -import com.vaadin.data.fieldbinder.BeanFieldBinder; -import com.vaadin.data.fieldbinder.FieldBinder; -import com.vaadin.data.fieldbinder.FieldBinder.CommitException; +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; @@ -33,7 +33,7 @@ public class FieldBinderWithBeanValidation extends TestBase { protected void setup() { addComponent(log); - final BeanFieldBinder binder = new BeanFieldBinder( + final BeanFieldGroup binder = new BeanFieldGroup( PersonWithBeanValidationAnnotations.class); FormBuilder builder = new FormBuilder(binder); @@ -88,7 +88,7 @@ public class FieldBinderWithBeanValidation extends TestBase { p)); } - public static Person getPerson(FieldBinder binder) { + public static Person getPerson(FieldGroup binder) { return ((BeanItem) binder.getItemDataSource()).getBean(); } diff --git a/tests/testbench/com/vaadin/tests/fieldbinder/FormBuilderWithNestedProperties.java b/tests/testbench/com/vaadin/tests/fieldbinder/FormBuilderWithNestedProperties.java index 72f3d4f343..284d69aa81 100644 --- a/tests/testbench/com/vaadin/tests/fieldbinder/FormBuilderWithNestedProperties.java +++ b/tests/testbench/com/vaadin/tests/fieldbinder/FormBuilderWithNestedProperties.java @@ -1,7 +1,7 @@ package com.vaadin.tests.fieldbinder; -import com.vaadin.data.fieldbinder.BeanFieldBinder; -import com.vaadin.data.fieldbinder.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; @@ -21,7 +21,7 @@ public class FormBuilderWithNestedProperties extends TestBase { @Override protected void setup() { - FieldBinder fieldBinder = new BeanFieldBinder(Person.class); + FieldGroup fieldBinder = new BeanFieldGroup(Person.class); FormBuilder b = new FormBuilder(fieldBinder); b.buildAndBindFields(this); diff --git a/tests/testbench/com/vaadin/tests/fieldbinder/FormWithNestedProperties.java b/tests/testbench/com/vaadin/tests/fieldbinder/FormWithNestedProperties.java index 0d29cc3004..69eac04d48 100644 --- a/tests/testbench/com/vaadin/tests/fieldbinder/FormWithNestedProperties.java +++ b/tests/testbench/com/vaadin/tests/fieldbinder/FormWithNestedProperties.java @@ -1,6 +1,6 @@ package com.vaadin.tests.fieldbinder; -import com.vaadin.data.fieldbinder.BeanFieldBinder; +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; @@ -31,7 +31,7 @@ public class FormWithNestedProperties extends AbstractBeanFieldBinderTest { protected void setup() { super.setup(); - setFieldBinder(new BeanFieldBinder(Person.class)); + setFieldBinder(new BeanFieldGroup(Person.class)); getFieldBinder().bindFields(this); country = new FormBuilder(getFieldBinder()).buildAndBind("country", "address.country", NativeSelect.class);