diff options
author | Felype Santiago Ferreira <felype@vaadin.com> | 2016-07-29 14:45:59 +0300 |
---|---|---|
committer | Felype Santiago Ferreira <felype@vaadin.com> | 2016-07-29 14:45:59 +0300 |
commit | 77ad774461cb7a609878515172605787631a1b15 (patch) | |
tree | 02c826042d70e6d74ee64d3454dc2edea3936f2f /server | |
parent | 5aee23ed30ae1cffce205888acd6ea76e599a46c (diff) | |
download | vaadin-framework-77ad774461cb7a609878515172605787631a1b15.tar.gz vaadin-framework-77ad774461cb7a609878515172605787631a1b15.zip |
Changed logic to retrieve readonly state (#8643)
Change-Id: Ibc86d36ce4c8f68eec400ad264546651353709f1
Diffstat (limited to 'server')
-rw-r--r-- | server/src/main/java/com/vaadin/ui/AbstractField.java | 15 | ||||
-rw-r--r-- | server/src/test/java/com/vaadin/tests/server/component/abstractfield/AbstractFieldReadOnlyTest.java | 51 |
2 files changed, 63 insertions, 3 deletions
diff --git a/server/src/main/java/com/vaadin/ui/AbstractField.java b/server/src/main/java/com/vaadin/ui/AbstractField.java index 49eb5b050f..6d25076526 100644 --- a/server/src/main/java/com/vaadin/ui/AbstractField.java +++ b/server/src/main/java/com/vaadin/ui/AbstractField.java @@ -1087,8 +1087,8 @@ public abstract class AbstractField<T> extends AbstractComponent implements return new CompositeErrorMessage( new ErrorMessage[] { superError, - AbstractErrorMessage - .getErrorMessageForException(validationError), + AbstractErrorMessage + .getErrorMessageForException(validationError), AbstractErrorMessage .getErrorMessageForException(getCurrentBufferedSourceException()) }); @@ -1191,7 +1191,16 @@ public abstract class AbstractField<T> extends AbstractComponent implements */ @Override public void readOnlyStatusChange(Property.ReadOnlyStatusChangeEvent event) { - getState().propertyReadOnly = event.getProperty().isReadOnly(); + boolean readOnly = event.getProperty().isReadOnly(); + + boolean shouldFireChange = isReadOnly() != readOnly + || getState().propertyReadOnly != readOnly; + + getState().propertyReadOnly = readOnly; + + if (shouldFireChange) { + fireReadOnlyStatusChange(); + } } /** diff --git a/server/src/test/java/com/vaadin/tests/server/component/abstractfield/AbstractFieldReadOnlyTest.java b/server/src/test/java/com/vaadin/tests/server/component/abstractfield/AbstractFieldReadOnlyTest.java new file mode 100644 index 0000000000..756004a662 --- /dev/null +++ b/server/src/test/java/com/vaadin/tests/server/component/abstractfield/AbstractFieldReadOnlyTest.java @@ -0,0 +1,51 @@ +package com.vaadin.tests.server.component.abstractfield; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +import com.vaadin.data.Property.ReadOnlyStatusChangeEvent; +import com.vaadin.data.Property.ReadOnlyStatusChangeListener; +import com.vaadin.data.util.MethodProperty; +import com.vaadin.tests.data.bean.Address; +import com.vaadin.tests.data.bean.Country; +import com.vaadin.tests.data.bean.Person; +import com.vaadin.tests.data.bean.Sex; +import com.vaadin.ui.Label; +import com.vaadin.ui.TextField; + +public class AbstractFieldReadOnlyTest { + + Person paulaBean = new Person("Paula", "Brilliant", "paula@brilliant.com", + 34, Sex.FEMALE, new Address("Paula street 1", 12345, "P-town", + Country.FINLAND)); + + @Test + public void testReadOnlyProperty() { + TextField tf = new TextField(); + tf.setPropertyDataSource(new MethodProperty<String>(paulaBean, + "firstName")); + assertFalse(tf.isReadOnly()); + tf.getPropertyDataSource().setReadOnly(true); + assertTrue(tf.isReadOnly()); + } + + @Test + public void testReadOnlyEventFromProperty() { + final Label valueStore = new Label(""); + TextField tf = new TextField(); + tf.addReadOnlyStatusChangeListener(new ReadOnlyStatusChangeListener() { + @Override + public void readOnlyStatusChange(ReadOnlyStatusChangeEvent event) { + valueStore.setValue("event received!"); + } + }); + tf.setPropertyDataSource(new MethodProperty<String>(paulaBean, + "firstName")); + assertTrue(valueStore.getValue().isEmpty()); + tf.getPropertyDataSource().setReadOnly(true); + assertFalse(valueStore.getValue().isEmpty()); + } + +} |