aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMarc Englund <marc.englund@itmill.com>2008-08-20 07:44:17 +0000
committerMarc Englund <marc.englund@itmill.com>2008-08-20 07:44:17 +0000
commitd7acda5109167312aea83aa926fbfe1fae8c9c78 (patch)
tree8207b156aa5acb08956ac73962335e7bce158a56 /src
parent704021b711976f08a32dfd655bc2ff66d17982f0 (diff)
downloadvaadin-framework-d7acda5109167312aea83aa926fbfe1fae8c9c78.tar.gz
vaadin-framework-d7acda5109167312aea83aa926fbfe1fae8c9c78.zip
Now implements ValueChangeNotifier. Fixes #1978.
svn changeset:5221/svn branch:trunk
Diffstat (limited to 'src')
-rw-r--r--src/com/itmill/toolkit/data/util/MethodProperty.java79
1 files changed, 78 insertions, 1 deletions
diff --git a/src/com/itmill/toolkit/data/util/MethodProperty.java b/src/com/itmill/toolkit/data/util/MethodProperty.java
index 6bedad2729..f5ed070960 100644
--- a/src/com/itmill/toolkit/data/util/MethodProperty.java
+++ b/src/com/itmill/toolkit/data/util/MethodProperty.java
@@ -31,12 +31,20 @@ import com.itmill.toolkit.data.Property;
* resulting MethodProperty is read-only.
* </p>
*
+ * <p>
+ * MethodProperty implements Property.ValueChangeNotifier, but does not
+ * automatically know whether or not the getter method will actually return a
+ * new value - value change listeners are always notified when setValue is
+ * called, without verifying what the getter returns.
+ * </p>
+ *
* @author IT Mill Ltd.
* @version
* @VERSION@
* @since 3.0
*/
-public class MethodProperty implements Property {
+public class MethodProperty implements Property, Property.ValueChangeNotifier,
+ Property.ReadOnlyStatusChangeNotifier {
/**
* The object that includes the property the MethodProperty is bound to.
@@ -77,6 +85,12 @@ public class MethodProperty implements Property {
private LinkedList readOnlyStatusChangeListeners = null;
/**
+ * List of listeners who are interested in the value changes of the
+ * MethodProperty
+ */
+ private LinkedList valueChangeListeners = null;
+
+ /**
* <p>
* Creates a new instance of <code>MethodProperty</code> from a named bean
* property. This constructor takes an object and the name of a bean
@@ -628,6 +642,7 @@ public class MethodProperty implements Property {
// Creates new object from the string
invokeSetMethod(value);
}
+ fireValueChange();
}
/**
@@ -816,4 +831,66 @@ public class MethodProperty implements Property {
}
}
+ /**
+ * An <code>Event</code> object specifying the Property whose value has
+ * been changed.
+ *
+ * @author IT Mill Ltd.
+ * @version
+ * @VERSION@
+ * @since 5.3
+ */
+ private class ValueChangeEvent extends java.util.EventObject implements
+ Property.ValueChangeEvent {
+
+ /**
+ * Constructs a new value change event for this object.
+ *
+ * @param source
+ * source object of the event.
+ */
+ protected ValueChangeEvent(MethodProperty source) {
+ super(source);
+ }
+
+ /**
+ * Gets the Property whose value has changed.
+ *
+ * @return source Property of the event.
+ */
+ public Property getProperty() {
+ return (Property) getSource();
+ }
+
+ }
+
+ public void addListener(ValueChangeListener listener) {
+ if (valueChangeListeners == null) {
+ valueChangeListeners = new LinkedList();
+ }
+ valueChangeListeners.add(listener);
+
+ }
+
+ public void removeListener(ValueChangeListener listener) {
+ if (valueChangeListeners != null) {
+ valueChangeListeners.remove(listener);
+ }
+
+ }
+
+ /**
+ * Sends a value change event to all registered listeners.
+ */
+ private void fireValueChange() {
+ if (valueChangeListeners != null) {
+ final Object[] l = valueChangeListeners.toArray();
+ final Property.ValueChangeEvent event = new MethodProperty.ValueChangeEvent(
+ this);
+ for (int i = 0; i < l.length; i++) {
+ ((Property.ValueChangeListener) l[i]).valueChange(event);
+ }
+ }
+ }
+
}