]> source.dussan.org Git - vaadin-framework.git/commitdiff
Allow to override transactional property wrapper strategy (#13883).
authorDenis Anisimov <denis@vaadin.com>
Thu, 8 Jan 2015 15:59:21 +0000 (17:59 +0200)
committerVaadin Code Review <review@vaadin.com>
Tue, 13 Jan 2015 20:22:30 +0000 (20:22 +0000)
Change-Id: I38acc3c6cfbe66ac9e9ce246accbb9a0b058dddb

server/src/com/vaadin/data/fieldgroup/FieldGroup.java
server/tests/src/com/vaadin/data/fieldgroup/FieldGroupTests.java

index a8cabc5887f3b6fb07ac7b4a82c001cbfd73f0b5..4790d786e7689130553d1073d6b2c30b9f6dc4b7 100644 (file)
@@ -266,6 +266,14 @@ public class FieldGroup implements Serializable {
         configureField(field);
     }
 
+    /**
+     * Wrap property to transactional property.
+     */
+    protected <T> Property.Transactional<T> wrapInTransactionalProperty(
+            Property<T> itemProperty) {
+        return new TransactionalPropertyWrapper<T>(itemProperty);
+    }
+
     private void throwIfFieldIsNull(Field<?> field, Object propertyId) {
         if (field == null) {
             throw new BindException(
@@ -283,11 +291,6 @@ public class FieldGroup implements Serializable {
         }
     }
 
-    private <T> Property.Transactional<T> wrapInTransactionalProperty(
-            Property<T> itemProperty) {
-        return new TransactionalPropertyWrapper<T>(itemProperty);
-    }
-
     /**
      * Gets the property with the given property id from the item.
      * 
index eb8f21c839de089c58161c27475e5eae9f3b5f04..fc267fc7dae287003b29201c8427dd04263c2bca 100644 (file)
@@ -4,10 +4,16 @@ import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.core.Is.is;
 import static org.mockito.Mockito.mock;
 
+import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 
+import com.vaadin.data.Property;
+import com.vaadin.data.Property.Transactional;
+import com.vaadin.data.util.BeanItem;
+import com.vaadin.data.util.TransactionalPropertyWrapper;
 import com.vaadin.ui.Field;
+import com.vaadin.ui.TextField;
 
 public class FieldGroupTests {
 
@@ -37,4 +43,45 @@ public class FieldGroupTests {
     public void cannotBindNullField() {
         sut.bind(null, "foobar");
     }
+
+    @Test
+    public void wrapInTransactionalProperty_provideCustomImpl_customTransactionalWrapperIsUsed() {
+        Bean bean = new Bean();
+        FieldGroup group = new FieldGroup() {
+            @Override
+            protected <T> Transactional<T> wrapInTransactionalProperty(
+                    Property<T> itemProperty) {
+                return new TransactionalPropertyImpl(itemProperty);
+            }
+        };
+        group.setItemDataSource(new BeanItem<Bean>(bean));
+        TextField field = new TextField();
+        group.bind(field, "name");
+
+        Property propertyDataSource = field.getPropertyDataSource();
+        Assert.assertTrue("Custom implementation of transactional property "
+                + "has not been used",
+                propertyDataSource instanceof TransactionalPropertyImpl);
+    }
+
+    public static class TransactionalPropertyImpl<T> extends
+            TransactionalPropertyWrapper<T> {
+
+        public TransactionalPropertyImpl(Property<T> wrappedProperty) {
+            super(wrappedProperty);
+        }
+
+    }
+
+    public static class Bean {
+        private String name;
+
+        public String getName() {
+            return name;
+        }
+
+        public void setName(String name) {
+            this.name = name;
+        }
+    }
 }