--- /dev/null
+package com.vaadin.data.util;
+
+import java.util.LinkedList;
+
+import com.vaadin.data.Property;
+
+/**
+ * Abstract base class for {@link Property} implementations.
+ *
+ * Handles listener management for {@link ValueChangeListener}s and
+ * {@link ReadOnlyStatusChangeListener}s.
+ *
+ * @since 6.6
+ */
+public abstract class AbstractProperty implements Property,
+ Property.ValueChangeNotifier, Property.ReadOnlyStatusChangeNotifier {
+
+ /**
+ * List of listeners who are interested in the read-only status changes of
+ * the Property
+ */
+ private LinkedList<ReadOnlyStatusChangeListener> readOnlyStatusChangeListeners = null;
+
+ /**
+ * List of listeners who are interested in the value changes of the Property
+ */
+ private LinkedList<ValueChangeListener> valueChangeListeners = null;
+
+ /**
+ * Returns the value of the <code>Property</code> in human readable textual
+ * format. The return value should be assignable to the
+ * <code>setValue</code> method if the Property is not in read-only mode.
+ *
+ * @return String representation of the value stored in the Property
+ */
+ @Override
+ public String toString() {
+ final Object value = getValue();
+ if (value == null) {
+ return null;
+ }
+ return value.toString();
+ }
+
+ /* Events */
+
+ /**
+ * An <code>Event</code> object specifying the Property whose read-only
+ * status has been changed.
+ */
+ protected class ReadOnlyStatusChangeEvent extends java.util.EventObject
+ implements Property.ReadOnlyStatusChangeEvent {
+
+ /**
+ * Constructs a new read-only status change event for this object.
+ *
+ * @param source
+ * source object of the event.
+ */
+ protected ReadOnlyStatusChangeEvent(Property source) {
+ super(source);
+ }
+
+ /**
+ * Gets the Property whose read-only state has changed.
+ *
+ * @return source Property of the event.
+ */
+ public Property getProperty() {
+ return (Property) getSource();
+ }
+
+ }
+
+ /**
+ * Registers a new read-only status change listener for this Property.
+ *
+ * @param listener
+ * the new Listener to be registered.
+ */
+ public void addListener(Property.ReadOnlyStatusChangeListener listener) {
+ if (readOnlyStatusChangeListeners == null) {
+ readOnlyStatusChangeListeners = new LinkedList<ReadOnlyStatusChangeListener>();
+ }
+ readOnlyStatusChangeListeners.add(listener);
+ }
+
+ /**
+ * Removes a previously registered read-only status change listener.
+ *
+ * @param listener
+ * the listener to be removed.
+ */
+ public void removeListener(Property.ReadOnlyStatusChangeListener listener) {
+ if (readOnlyStatusChangeListeners != null) {
+ readOnlyStatusChangeListeners.remove(listener);
+ }
+ }
+
+ /**
+ * Sends a read only status change event to all registered listeners.
+ */
+ protected void fireReadOnlyStatusChange() {
+ if (readOnlyStatusChangeListeners != null) {
+ final Object[] l = readOnlyStatusChangeListeners.toArray();
+ final Property.ReadOnlyStatusChangeEvent event = new ReadOnlyStatusChangeEvent(
+ this);
+ for (int i = 0; i < l.length; i++) {
+ ((Property.ReadOnlyStatusChangeListener) l[i])
+ .readOnlyStatusChange(event);
+ }
+ }
+ }
+
+ /**
+ * An <code>Event</code> object specifying the Property whose value has been
+ * changed.
+ */
+ 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(Property 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<ValueChangeListener>();
+ }
+ valueChangeListeners.add(listener);
+
+ }
+
+ public void removeListener(ValueChangeListener listener) {
+ if (valueChangeListeners != null) {
+ valueChangeListeners.remove(listener);
+ }
+
+ }
+
+ /**
+ * Sends a value change event to all registered listeners.
+ */
+ protected void fireValueChange() {
+ if (valueChangeListeners != null) {
+ final Object[] l = valueChangeListeners.toArray();
+ final Property.ValueChangeEvent event = new ValueChangeEvent(this);
+ for (int i = 0; i < l.length; i++) {
+ ((Property.ValueChangeListener) l[i]).valueChange(event);
+ }
+ }
+ }
+
+}
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
-import java.util.LinkedList;
import java.util.logging.Level;
import java.util.logging.Logger;
* @since 3.0
*/
@SuppressWarnings("serial")
-public class MethodProperty<T> implements Property,
- Property.ValueChangeNotifier, Property.ReadOnlyStatusChangeNotifier {
+public class MethodProperty<T> extends AbstractProperty {
private static final Logger logger = Logger.getLogger(MethodProperty.class
.getName());
*/
private transient Class<? extends T> type;
- /**
- * List of listeners who are interested in the read-only status changes of
- * the MethodProperty
- */
- private LinkedList<ReadOnlyStatusChangeListener> readOnlyStatusChangeListeners = null;
-
- /**
- * List of listeners who are interested in the value changes of the
- * MethodProperty
- */
- private LinkedList<ValueChangeListener> valueChangeListeners = null;
-
/* Special serialization to handle method references */
private void writeObject(java.io.ObjectOutputStream out) throws IOException {
out.defaultWriteObject();
}
}
- /**
- * Returns the value of the <code>MethodProperty</code> in human readable
- * textual format. The return value should be assignable to the
- * <code>setValue</code> method if the Property is not in read-only mode.
- *
- * @return String representation of the value stored in the Property
- */
- @Override
- public String toString() {
- final Object value = getValue();
- if (value == null) {
- return null;
- }
- return value.toString();
- }
-
/**
* <p>
* Sets the setter method and getter method argument lists.
}
}
- /* Events */
-
- /**
- * An <code>Event</code> object specifying the Property whose read-only
- * status has been changed.
- *
- * @author IT Mill Ltd.
- * @version
- * @VERSION@
- * @since 3.0
- */
- private class ReadOnlyStatusChangeEvent extends java.util.EventObject
- implements Property.ReadOnlyStatusChangeEvent {
-
- /**
- * Constructs a new read-only status change event for this object.
- *
- * @param source
- * source object of the event.
- */
- protected ReadOnlyStatusChangeEvent(MethodProperty<T> source) {
- super(source);
- }
-
- /**
- * Gets the Property whose read-only state has changed.
- *
- * @return source Property of the event.
- */
- public Property getProperty() {
- return (Property) getSource();
- }
-
- }
-
- /**
- * Registers a new read-only status change listener for this Property.
- *
- * @param listener
- * the new Listener to be registered.
- */
- public void addListener(Property.ReadOnlyStatusChangeListener listener) {
- if (readOnlyStatusChangeListeners == null) {
- readOnlyStatusChangeListeners = new LinkedList<ReadOnlyStatusChangeListener>();
- }
- readOnlyStatusChangeListeners.add(listener);
- }
-
- /**
- * Removes a previously registered read-only status change listener.
- *
- * @param listener
- * the listener to be removed.
- */
- public void removeListener(Property.ReadOnlyStatusChangeListener listener) {
- if (readOnlyStatusChangeListeners != null) {
- readOnlyStatusChangeListeners.remove(listener);
- }
- }
-
- /**
- * Sends a read only status change event to all registered listeners.
- */
- private void fireReadOnlyStatusChange() {
- if (readOnlyStatusChangeListeners != null) {
- final Object[] l = readOnlyStatusChangeListeners.toArray();
- final Property.ReadOnlyStatusChangeEvent event = new ReadOnlyStatusChangeEvent(
- this);
- for (int i = 0; i < l.length; i++) {
- ((Property.ReadOnlyStatusChangeListener) l[i])
- .readOnlyStatusChange(event);
- }
- }
- }
-
- /**
- * 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<T> 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<ValueChangeListener>();
- }
- valueChangeListeners.add(listener);
-
- }
-
- public void removeListener(ValueChangeListener listener) {
- if (valueChangeListeners != null) {
- valueChangeListeners.remove(listener);
- }
-
- }
-
/**
* Sends a value change event to all registered listeners.
+ *
+ * Public for backwards compatibility, visibility may be reduced in future
+ * versions.
*/
+ @Override
public void fireValueChange() {
- if (valueChangeListeners != null) {
- final Object[] l = valueChangeListeners.toArray();
- final Property.ValueChangeEvent event = new ValueChangeEvent(this);
- for (int i = 0; i < l.length; i++) {
- ((Property.ValueChangeListener) l[i]).valueChange(event);
- }
- }
+ super.fireValueChange();
}
}
package com.vaadin.data.util;
import java.lang.reflect.Constructor;
-import java.util.LinkedList;
import com.vaadin.data.Property;
* @since 3.0
*/
@SuppressWarnings("serial")
-public class ObjectProperty<T> implements Property,
- Property.ValueChangeNotifier, Property.ReadOnlyStatusChangeNotifier {
+public class ObjectProperty<T> extends AbstractProperty {
/**
* A boolean value storing the Property's read-only status information.
*/
private final Class<T> type;
- /**
- * Internal list of registered value change listeners.
- */
- private LinkedList<ValueChangeListener> valueChangeListeners = null;
-
- /**
- * Internal list of registered read-only status change listeners.
- */
- private LinkedList<ReadOnlyStatusChangeListener> readOnlyStatusChangeListeners = null;
-
/**
* Creates a new instance of ObjectProperty with the given value. The type
* of the property is automatically initialized to be the type of the given
return value;
}
- /**
- * Returns the value of the ObjectProperty in human readable textual format.
- * The return value should be assignable to the <code>setValue</code> method
- * if the Property is not in read-only mode.
- *
- * @return <code>String</code> representation of the value stored in the
- * ObjectProperty
- */
- @Override
- public String toString() {
- final Object value = getValue();
- if (value != null) {
- return value.toString();
- } else {
- return null;
- }
- }
-
/**
* Tests if the Property is in read-only mode. In read-only mode calls to
* the method <code>setValue</code> will throw
fireValueChange();
}
- /* Events */
-
- /**
- * An <code>Event</code> object specifying the ObjectProperty whose value
- * has changed.
- *
- * @author IT Mill Ltd.
- * @version
- * @VERSION@
- * @since 3.0
- */
- 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(ObjectProperty<T> 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();
- }
- }
-
- /**
- * An <code>Event</code> object specifying the Property whose read-only
- * status has been changed.
- *
- * @author IT Mill Ltd.
- * @version
- * @VERSION@
- * @since 3.0
- */
- private class ReadOnlyStatusChangeEvent extends java.util.EventObject
- implements Property.ReadOnlyStatusChangeEvent {
-
- /**
- * Constructs a new read-only status change event for this object.
- *
- * @param source
- * source object of the event
- */
- protected ReadOnlyStatusChangeEvent(ObjectProperty<T> source) {
- super(source);
- }
-
- /**
- * Gets the Property whose read-only state has changed.
- *
- * @return source 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 ObjectProperty.
- *
- * @param listener
- * the new Listener to be registered
- */
- public void addListener(Property.ValueChangeListener listener) {
- if (valueChangeListeners == null) {
- valueChangeListeners = new LinkedList<ValueChangeListener>();
- }
- valueChangeListeners.add(listener);
- }
-
- /**
- * Registers a new read-only status change listener for this Property.
- *
- * @param listener
- * the new Listener to be registered
- */
- public void addListener(Property.ReadOnlyStatusChangeListener listener) {
- if (readOnlyStatusChangeListeners == null) {
- readOnlyStatusChangeListeners = new LinkedList<ReadOnlyStatusChangeListener>();
- }
- readOnlyStatusChangeListeners.add(listener);
- }
-
- /**
- * Removes a previously registered read-only status change listener.
- *
- * @param listener
- * the listener to be removed.
- */
- public void removeListener(Property.ReadOnlyStatusChangeListener listener) {
- if (readOnlyStatusChangeListeners != null) {
- readOnlyStatusChangeListeners.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 ValueChangeEvent(this);
- for (int i = 0; i < l.length; i++) {
- ((Property.ValueChangeListener) l[i]).valueChange(event);
- }
- }
- }
-
- /**
- * Sends a read only status change event to all registered listeners.
- */
- private void fireReadOnlyStatusChange() {
- if (readOnlyStatusChangeListeners != null) {
- final Object[] l = readOnlyStatusChangeListeners.toArray();
- final Property.ReadOnlyStatusChangeEvent event = new ReadOnlyStatusChangeEvent(
- this);
- for (int i = 0; i < l.length; i++) {
- ((Property.ReadOnlyStatusChangeListener) l[i])
- .readOnlyStatusChange(event);
- }
- }
- }
}
*/
package com.vaadin.data.util;
-import java.util.LinkedList;
-
import com.vaadin.data.Property;
/**
* @since 5.3.0
*/
@SuppressWarnings("serial")
-public abstract class PropertyFormatter implements Property,
- Property.ValueChangeNotifier, Property.ValueChangeListener,
- Property.ReadOnlyStatusChangeListener,
- Property.ReadOnlyStatusChangeNotifier {
-
- /**
- * Internal list of registered value change listeners.
- */
- private LinkedList<Property.ValueChangeListener> valueChangeListeners = null;
-
- /**
- * Internal list of registered read-only status change listeners.
- */
- private LinkedList<Property.ReadOnlyStatusChangeListener> readOnlyStatusChangeListeners = null;
+public abstract class PropertyFormatter extends AbstractProperty implements
+ Property.ValueChangeListener, Property.ReadOnlyStatusChangeListener {
/** Datasource that stores the actual value. */
Property dataSource;
}
}
- /**
- * An <code>Event</code> object specifying the ObjectProperty whose value
- * has changed.
- *
- * @author IT Mill Ltd.
- * @since 5.3.0
- */
- 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(PropertyFormatter 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();
- }
- }
-
- /**
- * An <code>Event</code> object specifying the Property whose read-only
- * status has been changed.
- *
- * @author IT Mill Ltd.
- * @since 5.3.0
- */
- private class ReadOnlyStatusChangeEvent extends java.util.EventObject
- implements Property.ReadOnlyStatusChangeEvent {
-
- /**
- * Constructs a new read-only status change event for this object.
- *
- * @param source
- * source object of the event
- */
- protected ReadOnlyStatusChangeEvent(PropertyFormatter source) {
- super(source);
- }
-
- /**
- * Gets the Property whose read-only state has changed.
- *
- * @return source 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 ObjectProperty.
- *
- * @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);
- }
-
- /**
- * Registers a new read-only status change listener for this Property.
- *
- * @param listener
- * the new Listener to be registered
- */
- public void addListener(Property.ReadOnlyStatusChangeListener listener) {
- if (readOnlyStatusChangeListeners == null) {
- readOnlyStatusChangeListeners = new LinkedList<Property.ReadOnlyStatusChangeListener>();
- }
- readOnlyStatusChangeListeners.add(listener);
- }
-
- /**
- * Removes a previously registered read-only status change listener.
- *
- * @param listener
- * the listener to be removed.
- */
- public void removeListener(Property.ReadOnlyStatusChangeListener listener) {
- if (readOnlyStatusChangeListeners != null) {
- readOnlyStatusChangeListeners.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 ValueChangeEvent(this);
- for (int i = 0; i < l.length; i++) {
- ((Property.ValueChangeListener) l[i]).valueChange(event);
- }
- }
- }
-
- /**
- * Sends a read only status change event to all registered listeners.
- */
- private void fireReadOnlyStatusChange() {
- if (readOnlyStatusChangeListeners != null) {
- final Object[] l = readOnlyStatusChangeListeners.toArray();
- final Property.ReadOnlyStatusChangeEvent event = new ReadOnlyStatusChangeEvent(
- this);
- for (int i = 0; i < l.length; i++) {
- ((Property.ReadOnlyStatusChangeListener) l[i])
- .readOnlyStatusChange(event);
- }
- }
- }
-
/**
* Listens for changes in the datasource.
*
import java.io.InputStreamReader;\r
import java.io.OutputStreamWriter;\r
import java.nio.charset.Charset;\r
-import java.util.LinkedList;\r
-\r
-import com.vaadin.data.Property;\r
\r
/**\r
* Property implementation for wrapping a text file.\r
* \r
- * Supports reading and writing of a File from/to String. ValueChangeNotifiers\r
- * are supported, but only fire when setValue(Object) is explicitly called.\r
+ * Supports reading and writing of a File from/to String.\r
+ * \r
+ * {@link ValueChangeListener}s are supported, but only fire when\r
+ * setValue(Object) is explicitly called. {@link ReadOnlyStatusChangeListener}s\r
+ * are supported but only fire when setReadOnly(boolean) is explicitly called.\r
+ * \r
*/\r
@SuppressWarnings("serial")\r
-public class TextFileProperty implements Property, Property.ValueChangeNotifier {\r
+public class TextFileProperty extends AbstractProperty {\r
\r
private File file;\r
private boolean readonly;\r
private Charset charset = null;\r
- private LinkedList<Property.ValueChangeListener> valueChangeListeners = null;\r
\r
/**\r
* Wrap given file with property interface.\r
* @see com.vaadin.data.Property#setReadOnly(boolean)\r
*/\r
public void setReadOnly(boolean newStatus) {\r
+ boolean oldStatus = readonly;\r
readonly = newStatus;\r
+ if (isReadOnly() != oldStatus) {\r
+ fireReadOnlyStatusChange();\r
+ }\r
}\r
\r
/*\r
}\r
}\r
\r
- /*\r
- * (non-Javadoc)\r
- * \r
- * @see java.lang.Object#toString()\r
- */\r
- @Override\r
- public String toString() {\r
- return (String) getValue();\r
- }\r
-\r
- /* Events */\r
-\r
- /**\r
- * An <code>Event</code> object specifying the TextFileProperty whose value\r
- * has changed.\r
- */\r
- private class ValueChangeEvent extends java.util.EventObject implements\r
- Property.ValueChangeEvent {\r
-\r
- /**\r
- * Constructs a new value change event for this object.\r
- * \r
- * @param source\r
- * the source object of the event.\r
- */\r
- protected ValueChangeEvent(TextFileProperty source) {\r
- super(source);\r
- }\r
-\r
- /**\r
- * Gets the Property whose read-only state has changed.\r
- * \r
- * @return source the Property of the event.\r
- */\r
- public Property getProperty() {\r
- return (Property) getSource();\r
- }\r
- }\r
-\r
- /**\r
- * Removes a previously registered value change listener.\r
- * \r
- * @param listener\r
- * the listener to be removed.\r
- */\r
- public void removeListener(Property.ValueChangeListener listener) {\r
- if (valueChangeListeners != null) {\r
- valueChangeListeners.remove(listener);\r
- }\r
- }\r
-\r
- /**\r
- * Registers a new value change listener for this TextFileProperty.\r
- * \r
- * @param listener\r
- * the new Listener to be registered\r
- */\r
- public void addListener(Property.ValueChangeListener listener) {\r
- if (valueChangeListeners == null) {\r
- valueChangeListeners = new LinkedList<Property.ValueChangeListener>();\r
- }\r
- valueChangeListeners.add(listener);\r
- }\r
-\r
- /**\r
- * Sends a value change event to all registered listeners.\r
- */\r
- private void fireValueChange() {\r
- if (valueChangeListeners != null) {\r
- final Object[] l = valueChangeListeners.toArray();\r
- final ValueChangeEvent event = new ValueChangeEvent(this);\r
- for (int i = 0; i < l.length; i++) {\r
- ((ValueChangeListener) l[i]).valueChange(event);\r
- }\r
- }\r
- }\r
-\r
}\r