diff options
author | Matti Tahvonen <matti.tahvonen@itmill.com> | 2011-11-16 13:17:56 +0000 |
---|---|---|
committer | Matti Tahvonen <matti.tahvonen@itmill.com> | 2011-11-16 13:17:56 +0000 |
commit | 47adbf4e327896791d7adfd7e8c270d524d754ac (patch) | |
tree | e72288602ab22d23fe17fd3ddb9e66a49c8e605c /src | |
parent | 6719076bfb58ae8b8083512a91f697238680abe1 (diff) | |
download | vaadin-framework-47adbf4e327896791d7adfd7e8c270d524d754ac.tar.gz vaadin-framework-47adbf4e327896791d7adfd7e8c270d524d754ac.zip |
Form and Table now sets property to fields Viewer property if one exists. fixes #7942
svn changeset:22019/svn branch:6.7
Diffstat (limited to 'src')
-rw-r--r-- | src/com/vaadin/data/util/PropertyFormatter.java | 2 | ||||
-rw-r--r-- | src/com/vaadin/ui/Form.java | 30 | ||||
-rw-r--r-- | src/com/vaadin/ui/Table.java | 29 |
3 files changed, 57 insertions, 4 deletions
diff --git a/src/com/vaadin/data/util/PropertyFormatter.java b/src/com/vaadin/data/util/PropertyFormatter.java index 3afb1cede8..18e1890259 100644 --- a/src/com/vaadin/data/util/PropertyFormatter.java +++ b/src/com/vaadin/data/util/PropertyFormatter.java @@ -33,7 +33,7 @@ import com.vaadin.data.Property; * @since 5.3.0 */ @SuppressWarnings("serial") -public abstract class PropertyFormatter extends AbstractProperty implements +public abstract class PropertyFormatter extends AbstractProperty implements Property.Viewer, Property.ValueChangeListener, Property.ReadOnlyStatusChangeListener { /** Datasource that stores the actual value. */ diff --git a/src/com/vaadin/ui/Form.java b/src/com/vaadin/ui/Form.java index 8ee702bbb4..1a28c679f9 100644 --- a/src/com/vaadin/ui/Form.java +++ b/src/com/vaadin/ui/Form.java @@ -491,7 +491,7 @@ public class Form extends AbstractField implements Item.Editor, Buffered, Item, } // Configures the field - field.setPropertyDataSource(property); + bindPropertyToField(id, property, field); // Register and attach the created field addField(id, field); @@ -755,7 +755,7 @@ public class Form extends AbstractField implements Item.Editor, Buffered, Item, final Field f = fieldFactory.createField(itemDatasource, id, this); if (f != null) { - f.setPropertyDataSource(property); + bindPropertyToField(id, property, f); addField(id, f); } } @@ -763,6 +763,32 @@ public class Form extends AbstractField implements Item.Editor, Buffered, Item, } /** + * Binds an item property to a field. The default behavior is to bind + * property straight to Field. If Property.Viewer type property (e.g. + * PropertyFormatter) is already set for field, the property is bound to + * that Property.Viewer. + * + * @param propertyId + * @param property + * @param field + * @since 6.7.3 + */ + protected void bindPropertyToField(final Object propertyId, + final Property property, final Field field) { + // check if field has a property that is Viewer set. In that case we + // expect developer has e.g. PropertyFormatter that he wishes to use and + // assign the property to the Viewer instead. + boolean hasFilterProperty = field.getPropertyDataSource() != null + && (field.getPropertyDataSource() instanceof Property.Viewer); + if (hasFilterProperty) { + ((Property.Viewer) field.getPropertyDataSource()) + .setPropertyDataSource(property); + } else { + field.setPropertyDataSource(property); + } + } + + /** * Gets the layout of the form. * * <p> diff --git a/src/com/vaadin/ui/Table.java b/src/com/vaadin/ui/Table.java index 5efb2545e0..c16505e57f 100644 --- a/src/com/vaadin/ui/Table.java +++ b/src/com/vaadin/ui/Table.java @@ -3405,7 +3405,7 @@ public class Table extends AbstractSelect implements Action.Container, // Remember that we have made this association so we can remove // it when the component is removed associatedProperties.put(f, property); - f.setPropertyDataSource(property); + bindPropertyToField(rowId, colId, property, f); return f; } } @@ -3414,6 +3414,33 @@ public class Table extends AbstractSelect implements Action.Container, } /** + * Binds an item property to a field generated by TableFieldFactory. The + * default behavior is to bind property straight to Field. If + * Property.Viewer type property (e.g. PropertyFormatter) is already set for + * field, the property is bound to that Property.Viewer. + * + * @param rowId + * @param colId + * @param property + * @param field + * @since 6.7.3 + */ + protected void bindPropertyToField(Object rowId, Object colId, + Property property, Field field) { + // check if field has a property that is Viewer set. In that case we + // expect developer has e.g. PropertyFormatter that he wishes to use and + // assign the property to the Viewer instead. + boolean hasFilterProperty = field.getPropertyDataSource() != null + && (field.getPropertyDataSource() instanceof Property.Viewer); + if (hasFilterProperty) { + ((Property.Viewer) field.getPropertyDataSource()) + .setPropertyDataSource(property); + } else { + field.setPropertyDataSource(property); + } + } + + /** * Formats table cell property values. By default the property.toString() * and return a empty string for null properties. * |