From 5ebd63ba8d1399f510b424846d9be5af8b164e17 Mon Sep 17 00:00:00 2001 From: Henri Sara Date: Tue, 19 Apr 2011 11:59:35 +0000 Subject: [PATCH] #6860 Moved much of the read-only logic to AbstractProperty svn changeset:18380/svn branch:6.6 --- .../vaadin/data/util/AbstractProperty.java | 23 ++++++++++++++ src/com/vaadin/data/util/ObjectProperty.java | 31 ------------------- .../vaadin/data/util/TextFileProperty.java | 17 ++-------- 3 files changed, 25 insertions(+), 46 deletions(-) diff --git a/src/com/vaadin/data/util/AbstractProperty.java b/src/com/vaadin/data/util/AbstractProperty.java index 9db9013d70..2b3fcf2c93 100644 --- a/src/com/vaadin/data/util/AbstractProperty.java +++ b/src/com/vaadin/data/util/AbstractProperty.java @@ -26,6 +26,29 @@ public abstract class AbstractProperty implements Property, */ private LinkedList valueChangeListeners = null; + /** + * Is the Property read-only? + */ + private boolean readOnly; + + /** + * {@inheritDoc} + * + * Override for additional restrictions on what is considered a read-only + * property. + */ + public boolean isReadOnly() { + return readOnly; + } + + public void setReadOnly(boolean newStatus) { + boolean oldStatus = isReadOnly(); + readOnly = newStatus; + if (oldStatus != isReadOnly()) { + fireReadOnlyStatusChange(); + } + } + /** * Returns the value of the Property in human readable textual * format. The return value should be assignable to the diff --git a/src/com/vaadin/data/util/ObjectProperty.java b/src/com/vaadin/data/util/ObjectProperty.java index ee38bc0797..8286e3c6db 100644 --- a/src/com/vaadin/data/util/ObjectProperty.java +++ b/src/com/vaadin/data/util/ObjectProperty.java @@ -21,11 +21,6 @@ import com.vaadin.data.Property; @SuppressWarnings("serial") public class ObjectProperty extends AbstractProperty { - /** - * A boolean value storing the Property's read-only status information. - */ - private boolean readOnly = false; - /** * The value contained by the Property. */ @@ -112,32 +107,6 @@ public class ObjectProperty extends AbstractProperty { return value; } - /** - * Tests if the Property is in read-only mode. In read-only mode calls to - * the method setValue will throw - * ReadOnlyExceptions and will not modify the value of the - * Property. - * - * @return true if the Property is in read-only mode, - * false if it's not - */ - public boolean isReadOnly() { - return readOnly; - } - - /** - * Sets the Property's read-only mode to the specified status. - * - * @param newStatus - * the new read-only status of the Property. - */ - public void setReadOnly(boolean newStatus) { - if (newStatus != readOnly) { - readOnly = newStatus; - fireReadOnlyStatusChange(); - } - } - /** * Sets the value of the property. This method supports setting from * String if either String is directly assignable diff --git a/src/com/vaadin/data/util/TextFileProperty.java b/src/com/vaadin/data/util/TextFileProperty.java index 5915ddd664..dba5aa49f0 100644 --- a/src/com/vaadin/data/util/TextFileProperty.java +++ b/src/com/vaadin/data/util/TextFileProperty.java @@ -29,7 +29,6 @@ import java.nio.charset.Charset; public class TextFileProperty extends AbstractProperty { private File file; - private boolean readonly; private Charset charset = null; /** @@ -105,21 +104,9 @@ public class TextFileProperty extends AbstractProperty { * * @see com.vaadin.data.Property#isReadOnly() */ + @Override public boolean isReadOnly() { - return file == null || readonly || !file.canWrite(); - } - - /* - * (non-Javadoc) - * - * @see com.vaadin.data.Property#setReadOnly(boolean) - */ - public void setReadOnly(boolean newStatus) { - boolean oldStatus = isReadOnly(); - readonly = newStatus; - if (isReadOnly() != oldStatus) { - fireReadOnlyStatusChange(); - } + return file == null || super.isReadOnly() || !file.canWrite(); } /* -- 2.39.5