summaryrefslogtreecommitdiffstats
path: root/src/com/vaadin/data/util/TextFileProperty.java
diff options
context:
space:
mode:
authorHenri Sara <henri.sara@itmill.com>2011-04-18 14:14:35 +0000
committerHenri Sara <henri.sara@itmill.com>2011-04-18 14:14:35 +0000
commitb3d92ad4bdcd3568db2c01478bdfaa48e915a90c (patch)
treee62b52159fa812d5ab6fd47d50a9b5758238d242 /src/com/vaadin/data/util/TextFileProperty.java
parent4b13cfab7c0adaefdf8b4cfcb3c68bddf9111dc2 (diff)
downloadvaadin-framework-b3d92ad4bdcd3568db2c01478bdfaa48e915a90c.tar.gz
vaadin-framework-b3d92ad4bdcd3568db2c01478bdfaa48e915a90c.zip
#6860 introduced AbstractProperty with common functionality of most property implementations (listener management etc.), TextFileProperty now implements ReadOnlyStatusChangeListener
svn changeset:18360/svn branch:6.6
Diffstat (limited to 'src/com/vaadin/data/util/TextFileProperty.java')
-rw-r--r--src/com/vaadin/data/util/TextFileProperty.java95
1 files changed, 11 insertions, 84 deletions
diff --git a/src/com/vaadin/data/util/TextFileProperty.java b/src/com/vaadin/data/util/TextFileProperty.java
index 8d99112338..005372a04b 100644
--- a/src/com/vaadin/data/util/TextFileProperty.java
+++ b/src/com/vaadin/data/util/TextFileProperty.java
@@ -14,23 +14,23 @@ import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.nio.charset.Charset;
-import java.util.LinkedList;
-
-import com.vaadin.data.Property;
/**
* Property implementation for wrapping a text file.
*
- * Supports reading and writing of a File from/to String. ValueChangeNotifiers
- * are supported, but only fire when setValue(Object) is explicitly called.
+ * Supports reading and writing of a File from/to String.
+ *
+ * {@link ValueChangeListener}s are supported, but only fire when
+ * setValue(Object) is explicitly called. {@link ReadOnlyStatusChangeListener}s
+ * are supported but only fire when setReadOnly(boolean) is explicitly called.
+ *
*/
@SuppressWarnings("serial")
-public class TextFileProperty implements Property, Property.ValueChangeNotifier {
+public class TextFileProperty extends AbstractProperty {
private File file;
private boolean readonly;
private Charset charset = null;
- private LinkedList<Property.ValueChangeListener> valueChangeListeners = null;
/**
* Wrap given file with property interface.
@@ -115,7 +115,11 @@ public class TextFileProperty implements Property, Property.ValueChangeNotifier
* @see com.vaadin.data.Property#setReadOnly(boolean)
*/
public void setReadOnly(boolean newStatus) {
+ boolean oldStatus = readonly;
readonly = newStatus;
+ if (isReadOnly() != oldStatus) {
+ fireReadOnlyStatusChange();
+ }
}
/*
@@ -147,81 +151,4 @@ public class TextFileProperty implements Property, Property.ValueChangeNotifier
}
}
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString() {
- return (String) getValue();
- }
-
- /* Events */
-
- /**
- * An <code>Event</code> object specifying the TextFileProperty whose value
- * has changed.
- */
- private class ValueChangeEvent extends java.util.EventObject implements
- Property.ValueChangeEvent {
-
- /**
- * Constructs a new value change event for this object.
- *
- * @param source
- * the source object of the event.
- */
- protected ValueChangeEvent(TextFileProperty source) {
- super(source);
- }
-
- /**
- * Gets the Property whose read-only state has changed.
- *
- * @return source the Property of the event.
- */
- public Property getProperty() {
- return (Property) getSource();
- }
- }
-
- /**
- * Removes a previously registered value change listener.
- *
- * @param listener
- * the listener to be removed.
- */
- public void removeListener(Property.ValueChangeListener listener) {
- if (valueChangeListeners != null) {
- valueChangeListeners.remove(listener);
- }
- }
-
- /**
- * Registers a new value change listener for this TextFileProperty.
- *
- * @param listener
- * the new Listener to be registered
- */
- public void addListener(Property.ValueChangeListener listener) {
- if (valueChangeListeners == null) {
- valueChangeListeners = new LinkedList<Property.ValueChangeListener>();
- }
- valueChangeListeners.add(listener);
- }
-
- /**
- * Sends a value change event to all registered listeners.
- */
- private void fireValueChange() {
- if (valueChangeListeners != null) {
- final Object[] l = valueChangeListeners.toArray();
- final ValueChangeEvent event = new ValueChangeEvent(this);
- for (int i = 0; i < l.length; i++) {
- ((ValueChangeListener) l[i]).valueChange(event);
- }
- }
- }
-
}