diff options
49 files changed, 354 insertions, 248 deletions
diff --git a/src/com/vaadin/data/Property.java b/src/com/vaadin/data/Property.java index 4592fa3351..4e711141e8 100644 --- a/src/com/vaadin/data/Property.java +++ b/src/com/vaadin/data/Property.java @@ -30,12 +30,15 @@ import java.io.Serializable; * needs to be changed through the implementing class. * </p> * + * @param T + * type of values of the property + * * @author IT Mill Ltd * @version * @VERSION@ * @since 3.0 */ -public interface Property extends Serializable { +public interface Property<T> extends Serializable { /** * Gets the value stored in the Property. The returned object is compatible @@ -43,7 +46,7 @@ public interface Property extends Serializable { * * @return the value stored in the Property */ - public Object getValue(); + public T getValue(); /** * Sets the value of the Property. @@ -52,39 +55,24 @@ public interface Property extends Serializable { * missing, one should declare the Property to be in read-only mode and * throw <code>Property.ReadOnlyException</code> in this function. * </p> - * Note : It is not required, but highly recommended to support setting the - * value also as a <code>String</code> in addition to the native type of the - * Property (as given by the <code>getType</code> method). If the - * <code>String</code> conversion fails or is unsupported, the method should - * throw <code>Property.ConversionException</code>. The string conversion - * should at least understand the format returned by the - * <code>toString</code> method of the Property. + * + * Note : Since Vaadin 7.0, setting the value of a non-String property as a + * String is no longer supported. * * @param newValue * New value of the Property. This should be assignable to the - * type returned by getType, but also String type should be - * supported + * type returned by getType * * @throws Property.ReadOnlyException * if the object is in read-only mode * @throws Property.ConversionException * if newValue can't be converted into the Property's native - * type directly or through String + * type directly or using a converter */ public void setValue(Object newValue) throws Property.ReadOnlyException, Property.ConversionException; /** - * Returns the value of the Property 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 - * Property - */ - public String toString(); - - /** * Returns the type of the Property. The methods <code>getValue</code> and * <code>setValue</code> must be compatible with this type: one must be able * to safely cast the value returned from <code>getValue</code> to the given @@ -93,7 +81,7 @@ public interface Property extends Serializable { * * @return type of the Property */ - public Class<?> getType(); + public Class<? extends T> getType(); /** * Tests if the Property is in read-only mode. In read-only mode calls to diff --git a/src/com/vaadin/data/util/AbstractBeanContainer.java b/src/com/vaadin/data/util/AbstractBeanContainer.java index b1d0b0672b..c1e1b58b5a 100644 --- a/src/com/vaadin/data/util/AbstractBeanContainer.java +++ b/src/com/vaadin/data/util/AbstractBeanContainer.java @@ -104,8 +104,8 @@ public abstract class AbstractBeanContainer<IDTYPE, BEANTYPE> extends + " not found"); } try { - Property property = pd.createProperty(bean); - return (IDTYPE) property.getValue(); + Property<IDTYPE> property = pd.createProperty(bean); + return property.getValue(); } catch (MethodException e) { throw new IllegalArgumentException(e); } @@ -746,9 +746,9 @@ public abstract class AbstractBeanContainer<IDTYPE, BEANTYPE> extends } model.put(propertyId, propertyDescriptor); - for (BeanItem item : itemIdToItem.values()) { - item.addItemProperty(propertyId, propertyDescriptor - .createProperty((BEANTYPE) item.getBean())); + for (BeanItem<BEANTYPE> item : itemIdToItem.values()) { + item.addItemProperty(propertyId, + propertyDescriptor.createProperty(item.getBean())); } // Sends a change event diff --git a/src/com/vaadin/data/util/AbstractProperty.java b/src/com/vaadin/data/util/AbstractProperty.java index 2c1204438d..bc421755a9 100644 --- a/src/com/vaadin/data/util/AbstractProperty.java +++ b/src/com/vaadin/data/util/AbstractProperty.java @@ -17,7 +17,7 @@ import com.vaadin.data.Property; * * @since 6.6 */ -public abstract class AbstractProperty implements Property, +public abstract class AbstractProperty<T> implements Property<T>, Property.ValueChangeNotifier, Property.ReadOnlyStatusChangeNotifier { /** @@ -56,13 +56,28 @@ public abstract class AbstractProperty implements Property, /** * 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. + * format. * * @return String representation of the value stored in the Property + * @deprecated use the property value directly, or {@link #getStringValue()} + * during migration period */ + @Deprecated @Override public String toString() { + throw new UnsupportedOperationException( + "Use Property.getValue() instead of " + getClass() + + ".toString()"); + } + + /** + * Returns the value of the <code>Property</code> in human readable textual + * format. + * + * @return String representation of the value stored in the Property + * @since 7.0 + */ + public String getStringValue() { final Object value = getValue(); if (value == null) { return null; diff --git a/src/com/vaadin/data/util/IndexedContainer.java b/src/com/vaadin/data/util/IndexedContainer.java index a6f9c55aa2..a6e03970cc 100644 --- a/src/com/vaadin/data/util/IndexedContainer.java +++ b/src/com/vaadin/data/util/IndexedContainer.java @@ -691,8 +691,8 @@ public class IndexedContainer extends /** * Gets the <code>String</code> representation of the contents of the * Item. The format of the string is a space separated catenation of the - * <code>String</code> representations of the Properties contained by - * the Item. + * <code>String</code> representations of the values of the Properties + * contained by the Item. * * @return <code>String</code> representation of the Item contents */ @@ -702,7 +702,7 @@ public class IndexedContainer extends for (final Iterator<?> i = propertyIds.iterator(); i.hasNext();) { final Object propertyId = i.next(); - retValue += getItemProperty(propertyId).toString(); + retValue += getItemProperty(propertyId).getValue(); if (i.hasNext()) { retValue += " "; } @@ -910,9 +910,24 @@ public class IndexedContainer extends * * @return <code>String</code> representation of the value stored in the * Property + * @deprecated use the property value directly, or + * {@link #getStringValue()} during migration period */ + @Deprecated @Override public String toString() { + throw new UnsupportedOperationException( + "Use Property.getValue() instead of IndexedContainerProperty.toString()"); + } + + /** + * Returns the value of the <code>Property</code> in human readable + * textual format. + * + * @return String representation of the value stored in the Property + * @since 7.0 + */ + public String getStringValue() { final Object value = getValue(); if (value == null) { return null; diff --git a/src/com/vaadin/data/util/MethodProperty.java b/src/com/vaadin/data/util/MethodProperty.java index deb3177094..3809029223 100644 --- a/src/com/vaadin/data/util/MethodProperty.java +++ b/src/com/vaadin/data/util/MethodProperty.java @@ -47,7 +47,7 @@ import com.vaadin.util.SerializerHelper; * @since 3.0 */ @SuppressWarnings("serial") -public class MethodProperty<T> extends AbstractProperty { +public class MethodProperty<T> extends AbstractProperty<T> { private static final Logger logger = Logger.getLogger(MethodProperty.class .getName()); @@ -349,7 +349,7 @@ public class MethodProperty<T> extends AbstractProperty { } // Tests the parameter types - final Class[] c = m[i].getParameterTypes(); + final Class<?>[] c = m[i].getParameterTypes(); if (c.length != getArgs.length) { // not the right amount of parameters, try next method @@ -398,7 +398,7 @@ public class MethodProperty<T> extends AbstractProperty { } // Checks parameter compatibility - final Class[] c = m[i].getParameterTypes(); + final Class<?>[] c = m[i].getParameterTypes(); if (c.length != setArgs.length) { // not the right amount of parameters, try next method @@ -569,8 +569,7 @@ public class MethodProperty<T> extends AbstractProperty { * * @return type of the Property */ - @SuppressWarnings("unchecked") - public final Class getType() { + public final Class<? extends T> getType() { return type; } @@ -593,9 +592,9 @@ public class MethodProperty<T> extends AbstractProperty { * * @return the value of the Property */ - public Object getValue() { + public T getValue() { try { - return getMethod.invoke(instance, getArgs); + return (T) getMethod.invoke(instance, getArgs); } catch (final Throwable e) { throw new MethodException(this, e); } @@ -642,7 +641,6 @@ public class MethodProperty<T> extends AbstractProperty { * native type directly or through <code>String</code>. * @see #invokeSetMethod(Object) */ - @SuppressWarnings("unchecked") public void setValue(Object newValue) throws Property.ReadOnlyException, Property.ConversionException { diff --git a/src/com/vaadin/data/util/NestedMethodProperty.java b/src/com/vaadin/data/util/NestedMethodProperty.java index 41d743aa11..1c636fd0c4 100644 --- a/src/com/vaadin/data/util/NestedMethodProperty.java +++ b/src/com/vaadin/data/util/NestedMethodProperty.java @@ -26,7 +26,7 @@ import com.vaadin.data.util.MethodProperty.MethodException; * * @since 6.6 */ -public class NestedMethodProperty extends AbstractProperty { +public class NestedMethodProperty<T> extends AbstractProperty<T> { // needed for de-serialization private String propertyName; @@ -43,7 +43,7 @@ public class NestedMethodProperty extends AbstractProperty { */ private Object instance; - private Class<?> type; + private Class<? extends T> type; /* Special serialization to handle method references */ private void writeObject(java.io.ObjectOutputStream out) throws IOException { @@ -158,13 +158,14 @@ public class NestedMethodProperty extends AbstractProperty { } catch (final NoSuchMethodException skipped) { } - this.type = MethodProperty.convertPrimitiveType(type); + this.type = (Class<? extends T>) MethodProperty + .convertPrimitiveType(type); this.propertyName = propertyName; this.getMethods = getMethods; this.setMethod = setMethod; } - public Class<?> getType() { + public Class<? extends T> getType() { return type; } @@ -179,13 +180,13 @@ public class NestedMethodProperty extends AbstractProperty { * * @return the value of the Property */ - public Object getValue() { + public T getValue() { try { Object object = instance; for (Method m : getMethods) { object = m.invoke(object); } - return object; + return (T) object; } catch (final Throwable e) { throw new MethodException(this, e); } diff --git a/src/com/vaadin/data/util/ObjectProperty.java b/src/com/vaadin/data/util/ObjectProperty.java index 8286e3c6db..fbae448f30 100644 --- a/src/com/vaadin/data/util/ObjectProperty.java +++ b/src/com/vaadin/data/util/ObjectProperty.java @@ -19,7 +19,7 @@ import com.vaadin.data.Property; * @since 3.0 */ @SuppressWarnings("serial") -public class ObjectProperty<T> extends AbstractProperty { +public class ObjectProperty<T> extends AbstractProperty<T> { /** * The value contained by the Property. @@ -48,9 +48,8 @@ public class ObjectProperty<T> extends AbstractProperty { /** * Creates a new instance of ObjectProperty with the given value and type. * - * Any value of type Object is accepted because, if the type class contains - * a string constructor, the toString of the value is used to create the new - * value. See {@link #setValue(Object)}. + * Since Vaadin 7, only values of the correct type are accepted, and no + * automatic conversions are performed. * * @param value * the Initial value of the Property. @@ -58,7 +57,7 @@ public class ObjectProperty<T> extends AbstractProperty { * the type of the value. The value must be assignable to given * type. */ - public ObjectProperty(Object value, Class<T> type) { + public ObjectProperty(T value, Class<T> type) { // Set the values this.type = type; @@ -69,7 +68,7 @@ public class ObjectProperty<T> extends AbstractProperty { * Creates a new instance of ObjectProperty with the given value, type and * read-only mode status. * - * Any value of type Object is accepted, see + * Since Vaadin 7, only the correct type of values is accepted, see * {@link #ObjectProperty(Object, Class)}. * * @param value @@ -80,7 +79,7 @@ public class ObjectProperty<T> extends AbstractProperty { * @param readOnly * Sets the read-only mode. */ - public ObjectProperty(Object value, Class<T> type, boolean readOnly) { + public ObjectProperty(T value, Class<T> type, boolean readOnly) { this(value, type); setReadOnly(readOnly); } diff --git a/src/com/vaadin/data/util/PropertyFormatter.java b/src/com/vaadin/data/util/PropertyFormatter.java index c43a4771dc..9d3559ecf2 100644 --- a/src/com/vaadin/data/util/PropertyFormatter.java +++ b/src/com/vaadin/data/util/PropertyFormatter.java @@ -29,15 +29,20 @@ import com.vaadin.data.Property; * standard "1.0" notation with more zeroes. * </p> * + * @param T + * type of the underlying property (a PropertyFormatter is always a + * Property<String>) + * * @author IT Mill Ltd. * @since 5.3.0 */ @SuppressWarnings("serial") -public abstract class PropertyFormatter extends AbstractProperty implements - Property.ValueChangeListener, Property.ReadOnlyStatusChangeListener { +public abstract class PropertyFormatter<T> extends AbstractProperty<String> + implements Property.ValueChangeListener, + Property.ReadOnlyStatusChangeListener { /** Datasource that stores the actual value. */ - Property dataSource; + Property<T> dataSource; /** * Construct a new {@code PropertyFormatter} that is not connected to any @@ -56,7 +61,7 @@ public abstract class PropertyFormatter extends AbstractProperty implements * @param propertyDataSource * to connect this property to. */ - public PropertyFormatter(Property propertyDataSource) { + public PropertyFormatter(Property<T> propertyDataSource) { setPropertyDataSource(propertyDataSource); } @@ -67,7 +72,7 @@ public abstract class PropertyFormatter extends AbstractProperty implements * @return the current data source as a Property, or <code>null</code> if * none defined. */ - public Property getPropertyDataSource() { + public Property<T> getPropertyDataSource() { return dataSource; } @@ -83,7 +88,7 @@ public abstract class PropertyFormatter extends AbstractProperty implements * @param newDataSource * the new data source Property. */ - public void setPropertyDataSource(Property newDataSource) { + public void setPropertyDataSource(Property<T> newDataSource) { boolean readOnly = false; String prevValue = null; @@ -98,7 +103,7 @@ public abstract class PropertyFormatter extends AbstractProperty implements .removeListener(this); } readOnly = isReadOnly(); - prevValue = toString(); + prevValue = getStringValue(); } dataSource = newDataSource; @@ -116,7 +121,7 @@ public abstract class PropertyFormatter extends AbstractProperty implements if (isReadOnly() != readOnly) { fireReadOnlyStatusChange(); } - String newVal = toString(); + String newVal = getStringValue(); if ((prevValue == null && newVal != null) || (prevValue != null && !prevValue.equals(newVal))) { fireValueChange(); @@ -124,7 +129,7 @@ public abstract class PropertyFormatter extends AbstractProperty implements } /* Documented in the interface */ - public Class getType() { + public Class<String> getType() { return String.class; } @@ -134,19 +139,20 @@ public abstract class PropertyFormatter extends AbstractProperty implements * @return If the datasource returns null, this is null. Otherwise this is * String given by format(). */ - public Object getValue() { - return toString(); + public String getValue() { + return getStringValue(); } /** - * Get the formatted value. + * Get the formatted value. For PropertyFormatter, this is identical with + * {@link #getValue()}. * * @return If the datasource returns null, this is null. Otherwise this is * String given by format(). */ @Override - public String toString() { - Object value = dataSource == null ? false : dataSource.getValue(); + public String getStringValue() { + T value = dataSource == null ? null : dataSource.getValue(); if (value == null) { return null; } @@ -154,6 +160,7 @@ public abstract class PropertyFormatter extends AbstractProperty implements } /** Reflects the read-only status of the datasource. */ + @Override public boolean isReadOnly() { return dataSource == null ? false : dataSource.isReadOnly(); } @@ -168,7 +175,7 @@ public abstract class PropertyFormatter extends AbstractProperty implements * datasource. * @return */ - abstract public String format(Object value); + abstract public String format(T value); /** * Parse string and convert it to format compatible with datasource. @@ -182,7 +189,7 @@ public abstract class PropertyFormatter extends AbstractProperty implements * Any type of exception can be thrown to indicate that the * conversion was not succesful. */ - abstract public Object parse(String formattedValue) throws Exception; + abstract public T parse(String formattedValue) throws Exception; /** * Sets the Property's read-only mode to the specified status. @@ -190,6 +197,7 @@ public abstract class PropertyFormatter extends AbstractProperty implements * @param newStatus * the new read-only status of the Property. */ + @Override public void setReadOnly(boolean newStatus) { if (dataSource != null) { dataSource.setReadOnly(newStatus); @@ -208,8 +216,8 @@ public abstract class PropertyFormatter extends AbstractProperty implements } } else { try { - dataSource.setValue(parse((String) newValue)); - if (!newValue.equals(toString())) { + dataSource.setValue(parse(newValue.toString())); + if (!newValue.equals(getStringValue())) { fireValueChange(); } } catch (Exception e) { diff --git a/src/com/vaadin/data/util/PropertysetItem.java b/src/com/vaadin/data/util/PropertysetItem.java index 38be8561d0..09d12dd9a0 100644 --- a/src/com/vaadin/data/util/PropertysetItem.java +++ b/src/com/vaadin/data/util/PropertysetItem.java @@ -143,7 +143,7 @@ public class PropertysetItem implements Item, Item.PropertySetChangeNotifier, for (final Iterator<?> i = getItemPropertyIds().iterator(); i.hasNext();) { final Object propertyId = i.next(); - retValue += getItemProperty(propertyId).toString(); + retValue += getItemProperty(propertyId).getValue(); if (i.hasNext()) { retValue += " "; } diff --git a/src/com/vaadin/data/util/TextFileProperty.java b/src/com/vaadin/data/util/TextFileProperty.java index dba5aa49f0..a2e1a32986 100644 --- a/src/com/vaadin/data/util/TextFileProperty.java +++ b/src/com/vaadin/data/util/TextFileProperty.java @@ -26,7 +26,7 @@ import java.nio.charset.Charset; *
*/
@SuppressWarnings("serial")
-public class TextFileProperty extends AbstractProperty {
+public class TextFileProperty extends AbstractProperty<String> {
private File file;
private Charset charset = null;
@@ -64,7 +64,7 @@ public class TextFileProperty extends AbstractProperty { *
* @see com.vaadin.data.Property#getType()
*/
- public Class<?> getType() {
+ public Class<String> getType() {
return String.class;
}
@@ -73,7 +73,7 @@ public class TextFileProperty extends AbstractProperty { *
* @see com.vaadin.data.Property#getValue()
*/
- public Object getValue() {
+ public String getValue() {
if (file == null) {
return null;
}
diff --git a/src/com/vaadin/data/util/filter/SimpleStringFilter.java b/src/com/vaadin/data/util/filter/SimpleStringFilter.java index 6a1d75eab8..0dbf1fc43b 100644 --- a/src/com/vaadin/data/util/filter/SimpleStringFilter.java +++ b/src/com/vaadin/data/util/filter/SimpleStringFilter.java @@ -41,11 +41,15 @@ public final class SimpleStringFilter implements Filter { public boolean passesFilter(Object itemId, Item item) { final Property p = item.getItemProperty(propertyId); - if (p == null || p.toString() == null) { + if (p == null) { return false; } - final String value = ignoreCase ? p.toString().toLowerCase() : p - .toString(); + Object propertyValue = p.getValue(); + if (propertyValue == null) { + return false; + } + final String value = ignoreCase ? propertyValue.toString() + .toLowerCase() : propertyValue.toString(); if (onlyMatchPrefix) { if (!value.startsWith(filterString)) { return false; diff --git a/src/com/vaadin/data/util/sqlcontainer/ColumnProperty.java b/src/com/vaadin/data/util/sqlcontainer/ColumnProperty.java index 8d6175d426..c1474fc760 100644 --- a/src/com/vaadin/data/util/sqlcontainer/ColumnProperty.java +++ b/src/com/vaadin/data/util/sqlcontainer/ColumnProperty.java @@ -168,13 +168,38 @@ final public class ColumnProperty implements Property { return propertyId; } + /** + * Returns the value of the Property in human readable textual format. + * + * @see java.lang.Object#toString() + * @deprecated get the string representation from the value, or use + * getStringValue() during migration + */ + @Deprecated @Override public String toString() { - Object val = getValue(); - if (val == null) { + throw new UnsupportedOperationException( + "Use ColumnProperty.getValue() instead of ColumnProperty.toString()"); + } + + /** + * Returns the (UI type) value of the field converted to a String using + * toString(). + * + * This method exists to help migration from the use of Property.toString() + * to get the field value - for new applications, access getValue() + * directly. This method may disappear in future Vaadin versions. + * + * @return string representation of the field value or null if the value is + * null + * @since 7.0 + */ + public String getStringValue() { + final Object value = getValue(); + if (value == null) { return null; } - return val.toString(); + return value.toString(); } public void setOwner(RowItem owner) { diff --git a/src/com/vaadin/data/util/sqlcontainer/RowItem.java b/src/com/vaadin/data/util/sqlcontainer/RowItem.java index fa0c3c418e..fbcee76f37 100644 --- a/src/com/vaadin/data/util/sqlcontainer/RowItem.java +++ b/src/com/vaadin/data/util/sqlcontainer/RowItem.java @@ -113,7 +113,8 @@ public final class RowItem implements Item { s.append("|"); s.append(propId.toString()); s.append(":"); - s.append(getItemProperty(propId).toString()); + Object value = getItemProperty(propId).getValue(); + s.append((null != value) ? value.toString() : null); } return s.toString(); } diff --git a/src/com/vaadin/ui/AbstractField.java b/src/com/vaadin/ui/AbstractField.java index 7899569ea8..0f209ce04d 100644 --- a/src/com/vaadin/ui/AbstractField.java +++ b/src/com/vaadin/ui/AbstractField.java @@ -53,8 +53,8 @@ import com.vaadin.terminal.PaintTarget; * @since 3.0 */ @SuppressWarnings("serial") -public abstract class AbstractField extends AbstractComponent implements Field, - Property.ReadOnlyStatusChangeListener, +public abstract class AbstractField<T> extends AbstractComponent implements + Field<T>, Property.ReadOnlyStatusChangeListener, Property.ReadOnlyStatusChangeNotifier, Action.ShortcutNotifier { /* Private members */ @@ -62,12 +62,12 @@ public abstract class AbstractField extends AbstractComponent implements Field, /** * Value of the abstract field. */ - private Object value; + private T value; /** * Connected data-source. */ - private Property dataSource = null; + private Property<?> dataSource = null; /** * The list of validators. @@ -189,7 +189,7 @@ public abstract class AbstractField extends AbstractComponent implements Field, * Gets the field type Don't add a JavaDoc comment here, we use the default * documentation from the implemented interface. */ - public abstract Class<?> getType(); + public abstract Class<? extends T> getType(); /** * The abstract field is read only also if the data source is in read only @@ -237,13 +237,14 @@ public abstract class AbstractField extends AbstractComponent implements Field, public void commit() throws Buffered.SourceException, InvalidValueException { if (dataSource != null && !dataSource.isReadOnly()) { if ((isInvalidCommitted() || isValid())) { - final Object newValue = getValue(); + final T newValue = getValue(); try { // Commits the value to datasource. valueWasModifiedByDataSourceDuringCommit = false; committingValueToDataSource = true; - dataSource.setValue(newValue); + // TODO cast required until conversions applied + ((Property) dataSource).setValue(newValue); } catch (final Throwable e) { @@ -298,8 +299,10 @@ public abstract class AbstractField extends AbstractComponent implements Field, try { // Discards buffer by overwriting from datasource - newValue = String.class == getType() ? dataSource.toString() - : dataSource.getValue(); + newValue = dataSource.getValue(); + if (String.class == getType() && newValue != null) { + newValue = newValue.toString(); + } // If successful, remove set the buffering state to be ok if (currentBufferedSourceException != null) { @@ -323,6 +326,7 @@ public abstract class AbstractField extends AbstractComponent implements Field, // If the new value differs from the previous one if ((newValue == null && value != null) || (newValue != null && !newValue.equals(value))) { + // TODO use converter setInternalValue(newValue); fireValueChange(false); } @@ -387,8 +391,12 @@ public abstract class AbstractField extends AbstractComponent implements Field, } readThroughMode = readThrough; if (!isModified() && readThroughMode && dataSource != null) { - setInternalValue(String.class == getType() ? dataSource.toString() - : dataSource.getValue()); + Object newValue = dataSource.getValue(); + if (String.class == getType() && newValue != null) { + newValue = newValue.toString(); + } + // TODO use converter + setInternalValue(newValue); fireValueChange(false); } } @@ -399,14 +407,34 @@ public abstract class AbstractField extends AbstractComponent implements Field, * Returns the value of the Property in human readable textual format. * * @see java.lang.Object#toString() + * @deprecated get the string representation from the data source, or use + * getStringValue() during migration */ + @Deprecated @Override public String toString() { + throw new UnsupportedOperationException( + "Use Property.getValue() instead of " + getClass() + + ".toString()"); + } + + /** + * Returns the (UI type) value of the field converted to a String. + * + * This method exists to help migration from the use of Property.toString() + * to get the field value. For new applications, it is often better to + * access getValue() directly. + * + * @return string representation of the field value or null if the value is + * null + * @since 7.0 + */ + public String getStringValue() { final Object value = getValue(); if (value == null) { return null; } - return getValue().toString(); + return value.toString(); } /** @@ -414,37 +442,37 @@ public abstract class AbstractField extends AbstractComponent implements Field, * * <p> * This is the visible, modified and possible invalid value the user have - * entered to the field. In the read-through mode, the abstract buffer is - * also updated and validation is performed. + * entered to the field. * </p> * * <p> * Note that the object returned is compatible with getType(). For example, * if the type is String, this returns Strings even when the underlying - * datasource is of some other type. In order to access the datasources - * native type, use getPropertyDatasource().getValue() instead. + * datasource is of some other type. In order to access the native type of + * the datasource, use getPropertyDatasource().getValue() instead. * </p> * * <p> - * Note that when you extend AbstractField, you must reimplement this method - * if datasource.getValue() is not assignable to class returned by getType() - * AND getType() is not String. In case of Strings, getValue() calls - * datasource.toString() instead of datasource.getValue(). + * Since Vaadin 7.0, no implicit conversions between other data types and + * String are performed, but the converter is used if set. * </p> * * @return the current value of the field. + * @throws Property.ConversionException */ - public Object getValue() { + public T getValue() { // Give the value from abstract buffers if the field if possible if (dataSource == null || !isReadThrough() || isModified()) { return value; } - Object newValue = String.class == getType() ? dataSource.toString() - : dataSource.getValue(); - - return newValue; + Object result = dataSource.getValue(); + // TODO perform correct conversion, no cast or toString() + if (String.class == getType() && result != null) { + result = result.toString(); + } + return (T) result; } /** @@ -510,7 +538,7 @@ public abstract class AbstractField extends AbstractComponent implements Field, // Commits the value to datasource committingValueToDataSource = true; - dataSource.setValue(newValue); + ((Property) dataSource).setValue(newValue); // The buffer is now unmodified modified = false; @@ -612,8 +640,12 @@ public abstract class AbstractField extends AbstractComponent implements Field, // Gets the value from source try { if (dataSource != null) { - setInternalValue(String.class == getType() ? dataSource - .toString() : dataSource.getValue()); + Object newValue = dataSource.getValue(); + if (String.class == getType() && newValue != null) { + newValue = newValue.toString(); + } + // TODO use converter + setInternalValue(newValue); } modified = false; } catch (final Throwable e) { @@ -1040,6 +1072,7 @@ public abstract class AbstractField extends AbstractComponent implements Field, } private void readValueFromProperty(Property.ValueChangeEvent event) { + // TODO use converter or check type otherwise setInternalValue(event.getProperty().getValue()); } @@ -1104,7 +1137,7 @@ public abstract class AbstractField extends AbstractComponent implements Field, * the new value to be set. */ protected void setInternalValue(Object newValue) { - value = newValue; + value = (T) newValue; if (validators != null && !validators.isEmpty()) { requestRepaint(); } @@ -1329,4 +1362,4 @@ public abstract class AbstractField extends AbstractComponent implements Field, focusable.focus(); } } -}
\ No newline at end of file +} diff --git a/src/com/vaadin/ui/AbstractSelect.java b/src/com/vaadin/ui/AbstractSelect.java index 646d898a54..d4bf600651 100644 --- a/src/com/vaadin/ui/AbstractSelect.java +++ b/src/com/vaadin/ui/AbstractSelect.java @@ -55,7 +55,8 @@ import com.vaadin.terminal.gwt.client.ui.dd.VerticalDropLocation; * @since 5.0 */ @SuppressWarnings("serial") -public abstract class AbstractSelect extends AbstractField implements +// TODO currently cannot specify type more precisely in case of multi-select +public abstract class AbstractSelect extends AbstractField<Object> implements Container, Container.Viewer, Container.PropertySetChangeListener, Container.PropertySetChangeNotifier, Container.ItemSetChangeNotifier, Container.ItemSetChangeListener { @@ -1080,7 +1081,10 @@ public abstract class AbstractSelect extends AbstractField implements final Property p = getContainerProperty(itemId, getItemCaptionPropertyId()); if (p != null) { - caption = p.toString(); + Object value = p.getValue(); + if (value != null) { + caption = value.toString(); + } } break; } diff --git a/src/com/vaadin/ui/AbstractTextField.java b/src/com/vaadin/ui/AbstractTextField.java index 62904330c2..1bcb794eba 100644 --- a/src/com/vaadin/ui/AbstractTextField.java +++ b/src/com/vaadin/ui/AbstractTextField.java @@ -20,7 +20,7 @@ import com.vaadin.terminal.PaintException; import com.vaadin.terminal.PaintTarget; import com.vaadin.terminal.gwt.client.ui.VTextField; -public abstract class AbstractTextField extends AbstractField implements +public abstract class AbstractTextField extends AbstractField<String> implements BlurNotifier, FocusNotifier, TextChangeNotifier { /** @@ -171,8 +171,8 @@ public abstract class AbstractTextField extends AbstractField implements } @Override - public Object getValue() { - Object v = super.getValue(); + public String getValue() { + String v = super.getValue(); if (format == null || v == null) { return v; } @@ -250,7 +250,7 @@ public abstract class AbstractTextField extends AbstractField implements } @Override - public Class getType() { + public Class<String> getType() { return String.class; } @@ -373,7 +373,7 @@ public abstract class AbstractTextField extends AbstractField implements @Override protected boolean isEmpty() { - return super.isEmpty() || toString().length() == 0; + return super.isEmpty() || getStringValue().length() == 0; } /** @@ -513,7 +513,7 @@ public abstract class AbstractTextField extends AbstractField implements * case. AbstractField optimizes value change if the existing value is * reset. Also we need to force repaint if the flag is on. */ - if(lastKnownTextContent != null) { + if (lastKnownTextContent != null) { lastKnownTextContent = null; requestRepaint(); } @@ -751,4 +751,4 @@ public abstract class AbstractTextField extends AbstractField implements removeListener(BlurEvent.EVENT_ID, BlurEvent.class, listener); } -}
\ No newline at end of file +} diff --git a/src/com/vaadin/ui/Button.java b/src/com/vaadin/ui/Button.java index 16314f94c3..2c8e17f071 100644 --- a/src/com/vaadin/ui/Button.java +++ b/src/com/vaadin/ui/Button.java @@ -36,8 +36,9 @@ import com.vaadin.ui.themes.BaseTheme; */ @SuppressWarnings("serial") @ClientWidget(value = VButton.class, loadStyle = LoadStyle.EAGER) -public class Button extends AbstractField implements FieldEvents.BlurNotifier, - FieldEvents.FocusNotifier { +// FIXME Button should not be a Field, but CheckBox should +public class Button extends AbstractField<Boolean> implements + FieldEvents.BlurNotifier, FieldEvents.FocusNotifier { /* Private members */ @@ -125,7 +126,7 @@ public class Button extends AbstractField implements FieldEvents.BlurNotifier, * @deprecated use {@link CheckBox} instead of Button in "switchmode" */ @Deprecated - public Button(String caption, Property dataSource) { + public Button(String caption, Property<Boolean> dataSource) { setCaption(caption); setSwitchMode(true); setPropertyDataSource(dataSource); @@ -178,7 +179,7 @@ public class Button extends AbstractField implements FieldEvents.BlurNotifier, if (!isReadOnly() && variables.containsKey("state")) { // Gets the new and old button states final Boolean newValue = (Boolean) variables.get("state"); - final Boolean oldValue = (Boolean) getValue(); + final Boolean oldValue = getValue(); if (isSwitchMode()) { @@ -265,7 +266,7 @@ public class Button extends AbstractField implements FieldEvents.BlurNotifier, * @return True iff the button is pressed down or checked. */ public boolean booleanValue() { - Boolean value = (Boolean) getValue(); + Boolean value = getValue(); return (null == value) ? false : value.booleanValue(); } @@ -286,7 +287,7 @@ public class Button extends AbstractField implements FieldEvents.BlurNotifier, * @see com.vaadin.data.Property#getType() */ @Override - public Class getType() { + public Class<Boolean> getType() { return Boolean.class; } diff --git a/src/com/vaadin/ui/DateField.java b/src/com/vaadin/ui/DateField.java index b6e3d1e8cb..040a2a4dd4 100644 --- a/src/com/vaadin/ui/DateField.java +++ b/src/com/vaadin/ui/DateField.java @@ -48,7 +48,7 @@ import com.vaadin.terminal.gwt.client.ui.VPopupCalendar; */ @SuppressWarnings("serial") @ClientWidget(VPopupCalendar.class) -public class DateField extends AbstractField implements +public class DateField extends AbstractField<Date> implements FieldEvents.BlurNotifier, FieldEvents.FocusNotifier { /* Private members */ @@ -228,7 +228,7 @@ public class DateField extends AbstractField implements // Gets the calendar final Calendar calendar = getCalendar(); - final Date currentDate = (Date) getValue(); + final Date currentDate = getValue(); for (int r = resolution; r <= largestModifiable; r++) { switch (r) { @@ -298,10 +298,10 @@ public class DateField extends AbstractField implements || variables.containsKey("min") || variables.containsKey("sec") || variables.containsKey("msec") || variables - .containsKey("dateString"))) { + .containsKey("dateString"))) { // Old and new dates - final Date oldDate = (Date) getValue(); + final Date oldDate = getValue(); Date newDate = null; // this enables analyzing invalid input on the server @@ -469,7 +469,7 @@ public class DateField extends AbstractField implements * the default documentation from implemented interface. */ @Override - public Class<?> getType() { + public Class<Date> getType() { return Date.class; } @@ -642,7 +642,7 @@ public class DateField extends AbstractField implements final Calendar newCal = (Calendar) calendar.clone(); // Assigns the current time tom calendar. - final Date currentDate = (Date) getValue(); + final Date currentDate = getValue(); if (currentDate != null) { newCal.setTime(currentDate); } diff --git a/src/com/vaadin/ui/Field.java b/src/com/vaadin/ui/Field.java index 72dc3130c3..5cc81a9e92 100644 --- a/src/com/vaadin/ui/Field.java +++ b/src/com/vaadin/ui/Field.java @@ -9,30 +9,19 @@ import com.vaadin.data.Property; import com.vaadin.ui.Component.Focusable; /** - * @author IT Mill Ltd. + * TODO document + * + * @param T + * the type of values in the field, which might not be the same type + * as that of the data source if converters are used * + * @author IT Mill Ltd. */ -public interface Field extends Component, BufferedValidatable, Property, +public interface Field<T> extends Component, BufferedValidatable, Property<T>, Property.ValueChangeNotifier, Property.ValueChangeListener, Property.Editor, Focusable { /** - * Sets the Caption. - * - * @param caption - */ - void setCaption(String caption); - - String getDescription(); - - /** - * Sets the Description. - * - * @param caption - */ - void setDescription(String caption); - - /** * Is this field required. * * Required fields must filled by the user. diff --git a/src/com/vaadin/ui/Form.java b/src/com/vaadin/ui/Form.java index 8ee702bbb4..b00a34ad42 100644 --- a/src/com/vaadin/ui/Form.java +++ b/src/com/vaadin/ui/Form.java @@ -61,8 +61,8 @@ import com.vaadin.terminal.gwt.client.ui.VForm; */ @SuppressWarnings("serial") @ClientWidget(VForm.class) -public class Form extends AbstractField implements Item.Editor, Buffered, Item, - Validatable, Action.Notifier { +public class Form extends AbstractField<Object> implements Item.Editor, + Buffered, Item, Validatable, Action.Notifier { private Object propertyValue; diff --git a/src/com/vaadin/ui/Label.java b/src/com/vaadin/ui/Label.java index d1952dc2b3..9bae47dbae 100644 --- a/src/com/vaadin/ui/Label.java +++ b/src/com/vaadin/ui/Label.java @@ -40,6 +40,7 @@ import com.vaadin.ui.ClientWidget.LoadStyle; */ @SuppressWarnings("serial") @ClientWidget(value = VLabel.class, loadStyle = LoadStyle.EAGER) +// TODO generics for interface Property public class Label extends AbstractComponent implements Property, Property.Viewer, Property.ValueChangeListener, Property.ValueChangeNotifier, Comparable<Object> { @@ -194,24 +195,24 @@ public class Label extends AbstractComponent implements Property, target.addAttribute("mode", CONTENT_MODE_NAME[contentMode]); } if (contentMode == CONTENT_TEXT) { - target.addText(toString()); + target.addText(getStringValue()); } else if (contentMode == CONTENT_UIDL) { - target.addUIDL(toString()); + target.addUIDL(getStringValue()); } else if (contentMode == CONTENT_XHTML) { target.startTag("data"); - target.addXMLSection("div", toString(), + target.addXMLSection("div", getStringValue(), "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"); target.endTag("data"); } else if (contentMode == CONTENT_PREFORMATTED) { target.startTag("pre"); - target.addText(toString()); + target.addText(getStringValue()); target.endTag("pre"); } else if (contentMode == CONTENT_XML) { - target.addXMLSection("data", toString(), null); + target.addXMLSection("data", getStringValue(), null); } else if (contentMode == CONTENT_RAW) { target.startTag("data"); target.addAttribute("escape", false); - target.addText(toString()); + target.addText(getStringValue()); target.endTag("data"); } @@ -246,13 +247,33 @@ public class Label extends AbstractComponent implements Property, /** * @see java.lang.Object#toString() + * @deprecated use the data source value or {@link #getStringValue()} + * instead */ + @Deprecated @Override public String toString() { + throw new UnsupportedOperationException( + "Use Property.getValue() instead of Label.toString()"); + } + + /** + * Returns the value of the <code>Property</code> in human readable textual + * format. + * + * This method exists to help migration from previous Vaadin versions by + * providing a simple replacement for {@link #toString()}. However, it is + * normally better to use the value of the label directly. + * + * @return String representation of the value stored in the Property + * @since 7.0 + */ + public String getStringValue() { if (dataSource == null) { throw new IllegalStateException(DATASOURCE_MUST_BE_SET); } - return dataSource.toString(); + Object value = dataSource.getValue(); + return (null != value) ? value.toString() : null; } /** @@ -489,17 +510,19 @@ public class Label extends AbstractComponent implements Property, if (contentMode == CONTENT_XML || contentMode == CONTENT_UIDL || contentMode == CONTENT_XHTML) { - thisValue = stripTags(toString()); + thisValue = stripTags(getStringValue()); } else { - thisValue = toString(); + thisValue = getStringValue(); } if (other instanceof Label && (((Label) other).getContentMode() == CONTENT_XML || ((Label) other).getContentMode() == CONTENT_UIDL || ((Label) other) .getContentMode() == CONTENT_XHTML)) { - otherValue = stripTags(other.toString()); + otherValue = stripTags(((Label) other).getStringValue()); } else { + // TODO not a good idea - and might assume that Field.toString() + // returns a string representation of the value otherValue = other.toString(); } diff --git a/src/com/vaadin/ui/ProgressIndicator.java b/src/com/vaadin/ui/ProgressIndicator.java index c4fd759eed..7bf4bc56af 100644 --- a/src/com/vaadin/ui/ProgressIndicator.java +++ b/src/com/vaadin/ui/ProgressIndicator.java @@ -26,7 +26,7 @@ import com.vaadin.terminal.gwt.client.ui.VProgressIndicator; */ @SuppressWarnings("serial") @ClientWidget(VProgressIndicator.class) -public class ProgressIndicator extends AbstractField implements Property, +public class ProgressIndicator extends AbstractField<Number> implements Property.Viewer, Property.ValueChangeListener { /** @@ -125,11 +125,12 @@ public class ProgressIndicator extends AbstractField implements Property, * @see com.vaadin.ui.AbstractField#getValue() */ @Override - public Object getValue() { + public Number getValue() { if (dataSource == null) { throw new IllegalStateException("Datasource must be set"); } - return dataSource.getValue(); + // TODO conversions to eliminate cast + return (Number) dataSource.getValue(); } /** @@ -138,7 +139,7 @@ public class ProgressIndicator extends AbstractField implements Property, * * @param newValue * the New value of the ProgressIndicator. - * @see com.vaadin.ui.AbstractField#setValue(java.lang.Object) + * @see com.vaadin.ui.AbstractField#setValue() */ @Override public void setValue(Object newValue) { @@ -150,20 +151,20 @@ public class ProgressIndicator extends AbstractField implements Property, /** * @see com.vaadin.ui.AbstractField#toString() + * @deprecated use the data source value instead of toString() */ + @Deprecated @Override public String toString() { - if (dataSource == null) { - throw new IllegalStateException("Datasource must be set"); - } - return dataSource.toString(); + throw new UnsupportedOperationException( + "Use Property.getValue() instead of ProgressIndicator.toString()"); } /** * @see com.vaadin.ui.AbstractField#getType() */ @Override - public Class<?> getType() { + public Class<? extends Number> getType() { if (dataSource == null) { throw new IllegalStateException("Datasource must be set"); } diff --git a/src/com/vaadin/ui/RichTextArea.java b/src/com/vaadin/ui/RichTextArea.java index d371e3c181..0f7a2b376c 100644 --- a/src/com/vaadin/ui/RichTextArea.java +++ b/src/com/vaadin/ui/RichTextArea.java @@ -21,7 +21,7 @@ import com.vaadin.ui.ClientWidget.LoadStyle; * into length of field. */ @ClientWidget(value = VRichTextArea.class, loadStyle = LoadStyle.LAZY) -public class RichTextArea extends AbstractField { +public class RichTextArea extends AbstractField<String> { /** * Value formatter used to format the string contents. @@ -175,8 +175,8 @@ public class RichTextArea extends AbstractField { } @Override - public Object getValue() { - Object v = super.getValue(); + public String getValue() { + String v = super.getValue(); if (format == null || v == null) { return v; } @@ -342,7 +342,7 @@ public class RichTextArea extends AbstractField { @Override protected boolean isEmpty() { - return super.isEmpty() || toString().length() == 0; + return super.isEmpty() || getStringValue().length() == 0; } } diff --git a/src/com/vaadin/ui/Slider.java b/src/com/vaadin/ui/Slider.java index c07913d5fe..ae10e91e22 100644 --- a/src/com/vaadin/ui/Slider.java +++ b/src/com/vaadin/ui/Slider.java @@ -48,7 +48,7 @@ import com.vaadin.terminal.gwt.client.ui.VSlider; */ @SuppressWarnings("serial") @ClientWidget(VSlider.class) -public class Slider extends AbstractField { +public class Slider extends AbstractField<Number> { public static final int ORIENTATION_HORIZONTAL = 0; @@ -408,10 +408,9 @@ public class Slider extends AbstractField { target.addAttribute("resolution", resolution); if (resolution > 0) { - target.addVariable(this, "value", - ((Double) getValue()).doubleValue()); + target.addVariable(this, "value", getValue().doubleValue()); } else { - target.addVariable(this, "value", ((Double) getValue()).intValue()); + target.addVariable(this, "value", getValue().intValue()); } if (orientation == ORIENTATION_VERTICAL) { @@ -493,7 +492,7 @@ public class Slider extends AbstractField { } @Override - public Class getType() { + public Class<Double> getType() { return Double.class; } diff --git a/src/com/vaadin/ui/Table.java b/src/com/vaadin/ui/Table.java index 5efb2545e0..5fa63531bb 100644 --- a/src/com/vaadin/ui/Table.java +++ b/src/com/vaadin/ui/Table.java @@ -3431,7 +3431,8 @@ public class Table extends AbstractSelect implements Action.Container, if (property == null) { return ""; } - return property.toString(); + Object value = property.getValue(); + return (null != value) ? value.toString() : ""; } /* Action container */ diff --git a/tests/server-side/com/vaadin/data/util/ObjectPropertyTest.java b/tests/server-side/com/vaadin/data/util/ObjectPropertyTest.java index a934b40dce..0ed554a1a0 100644 --- a/tests/server-side/com/vaadin/data/util/ObjectPropertyTest.java +++ b/tests/server-side/com/vaadin/data/util/ObjectPropertyTest.java @@ -4,8 +4,6 @@ import junit.framework.TestCase; import org.junit.Assert;
-import com.vaadin.data.util.ObjectProperty;
-
public class ObjectPropertyTest extends TestCase {
public static class TestSuperClass {
@@ -70,7 +68,7 @@ public class ObjectPropertyTest extends TestCase { ObjectProperty<TestSuperClass> prop = new ObjectProperty<TestSuperClass>(
super1, TestSuperClass.class);
Assert.assertEquals("super1", prop.getValue().getName());
- prop.setValue("super2");
+ prop.setValue(new TestSuperClass("super2"));
Assert.assertEquals("super1", super1.getName());
Assert.assertEquals("super2", prop.getValue().getName());
}
@@ -79,7 +77,7 @@ public class ObjectPropertyTest extends TestCase { ObjectProperty<TestSubClass> prop = new ObjectProperty<TestSubClass>(
sub1, TestSubClass.class);
Assert.assertEquals("Subclass: sub1", prop.getValue().getName());
- prop.setValue("sub2");
+ prop.setValue(new TestSubClass("sub2"));
Assert.assertEquals("Subclass: sub1", sub1.getName());
Assert.assertEquals("Subclass: sub2", prop.getValue().getName());
}
@@ -92,7 +90,7 @@ public class ObjectPropertyTest extends TestCase { // create correct subclass based on the runtime type of the instance
// given to ObjectProperty constructor, which is a subclass of the type
// parameter
- prop.setValue("sub2");
+ prop.setValue(new TestSubClass("sub2"));
Assert.assertEquals("Subclass: sub2", prop.getValue().getName());
}
diff --git a/tests/server-side/com/vaadin/data/util/PropertySetItemTest.java b/tests/server-side/com/vaadin/data/util/PropertySetItemTest.java index 4516e8d109..a3169332ec 100644 --- a/tests/server-side/com/vaadin/data/util/PropertySetItemTest.java +++ b/tests/server-side/com/vaadin/data/util/PropertySetItemTest.java @@ -9,8 +9,6 @@ import org.easymock.EasyMock; import com.vaadin.data.Item.PropertySetChangeEvent; import com.vaadin.data.Item.PropertySetChangeListener; -import com.vaadin.data.util.ObjectProperty; -import com.vaadin.data.util.PropertysetItem; public class PropertySetItemTest extends TestCase { @@ -395,13 +393,13 @@ public class PropertySetItemTest extends TestCase { item.addItemProperty(ID1, prop1); - Assert.assertEquals(String.valueOf(prop1), item.toString()); + Assert.assertEquals(String.valueOf(prop1.getValue()), item.toString()); item.addItemProperty(ID2, prop2); Assert.assertEquals( - String.valueOf(prop1) + " " + String.valueOf(prop2), - item.toString()); + String.valueOf(prop1.getValue()) + " " + + String.valueOf(prop2.getValue()), item.toString()); } } diff --git a/tests/server-side/com/vaadin/data/util/filter/AbstractFilterTest.java b/tests/server-side/com/vaadin/data/util/filter/AbstractFilterTest.java index beaa1c4e8f..c26847fb63 100644 --- a/tests/server-side/com/vaadin/data/util/filter/AbstractFilterTest.java +++ b/tests/server-side/com/vaadin/data/util/filter/AbstractFilterTest.java @@ -22,9 +22,9 @@ public abstract class AbstractFilterTest<FILTERTYPE extends Filter> extends } } - protected static class NullProperty implements Property { + protected static class NullProperty implements Property<String> { - public Object getValue() { + public String getValue() { return null; } @@ -33,7 +33,7 @@ public abstract class AbstractFilterTest<FILTERTYPE extends Filter> extends throw new ReadOnlyException(); } - public Class<?> getType() { + public Class<String> getType() { return String.class; } diff --git a/tests/server-side/com/vaadin/data/util/sqlcontainer/SQLContainerTest.java b/tests/server-side/com/vaadin/data/util/sqlcontainer/SQLContainerTest.java index 56c9921a0b..c273bbf590 100644 --- a/tests/server-side/com/vaadin/data/util/sqlcontainer/SQLContainerTest.java +++ b/tests/server-side/com/vaadin/data/util/sqlcontainer/SQLContainerTest.java @@ -1344,7 +1344,7 @@ public class SQLContainerTest { Statement statement = conn.createStatement(); statement .executeUpdate("DELETE FROM people WHERE \"ID\"=" - + item.getItemProperty("ID")); + + item.getItemProperty("ID").getValue()); statement.close(); return true; } diff --git a/tests/server-side/com/vaadin/tests/server/TestSerialization.java b/tests/server-side/com/vaadin/tests/server/TestSerialization.java index 03a9d3e262..e3b6a47855 100644 --- a/tests/server-side/com/vaadin/tests/server/TestSerialization.java +++ b/tests/server-side/com/vaadin/tests/server/TestSerialization.java @@ -10,6 +10,7 @@ import java.io.Serializable; import junit.framework.TestCase; import com.vaadin.data.Item; +import com.vaadin.data.Property; import com.vaadin.data.util.IndexedContainer; import com.vaadin.data.util.MethodProperty; import com.vaadin.data.validator.RegexpValidator; @@ -78,15 +79,25 @@ public class TestSerialization extends TestCase { data)); Serializable s2 = (Serializable) in.readObject(); + // using special toString(Object) method to avoid calling + // Property.toString(), which will be temporarily disabled if (s.equals(s2)) { - System.out.println(s + " equals " + s2); + System.out.println(toString(s) + " equals " + toString(s2)); } else { - System.out.println(s + " does NOT equal " + s2); + System.out.println(toString(s) + " does NOT equal " + toString(s2)); } return s2; } + private static String toString(Object o) { + if (o instanceof Property) { + return String.valueOf(((Property) o).getValue()); + } else { + return String.valueOf(o); + } + } + public static class Data implements Serializable { private String dummyGetter; private String dummyGetterAndSetter; diff --git a/tests/server-side/com/vaadin/tests/server/validation/TestReadOnlyValidation.java b/tests/server-side/com/vaadin/tests/server/validation/TestReadOnlyValidation.java index 6939ce27d2..fdf1586a44 100644 --- a/tests/server-side/com/vaadin/tests/server/validation/TestReadOnlyValidation.java +++ b/tests/server-side/com/vaadin/tests/server/validation/TestReadOnlyValidation.java @@ -11,7 +11,7 @@ public class TestReadOnlyValidation { public void testIntegerValidation() {
TextField field = new TextField();
field.addValidator(new IntegerValidator("Enter a Valid Number"));
- field.setValue(Integer.valueOf(10));
+ field.setValue(String.valueOf(10));
field.validate();
}
}
diff --git a/tests/testbench/com/vaadin/tests/TestForContainerFilterable.java b/tests/testbench/com/vaadin/tests/TestForContainerFilterable.java index 7b5124b4f3..9acccc8464 100644 --- a/tests/testbench/com/vaadin/tests/TestForContainerFilterable.java +++ b/tests/testbench/com/vaadin/tests/TestForContainerFilterable.java @@ -62,12 +62,12 @@ public class TestForContainerFilterable extends CustomComponent { filterButton.addListener(new Button.ClickListener() { public void buttonClick(ClickEvent event) { ic.removeAllContainerFilters(); - if (fooFilter.toString().length() > 0) { - ic.addContainerFilter("foo", fooFilter.toString(), false, + if (fooFilter.getStringValue().length() > 0) { + ic.addContainerFilter("foo", fooFilter.getStringValue(), false, false); } - if (barFilter.toString().length() > 0) { - ic.addContainerFilter("bar", barFilter.toString(), true, + if (barFilter.getStringValue().length() > 0) { + ic.addContainerFilter("bar", barFilter.getStringValue(), true, true); } count.setValue("Rows in table: " + ic.size()); diff --git a/tests/testbench/com/vaadin/tests/TestForPreconfiguredComponents.java b/tests/testbench/com/vaadin/tests/TestForPreconfiguredComponents.java index e009489683..caea457ccd 100644 --- a/tests/testbench/com/vaadin/tests/TestForPreconfiguredComponents.java +++ b/tests/testbench/com/vaadin/tests/TestForPreconfiguredComponents.java @@ -160,6 +160,7 @@ public class TestForPreconfiguredComponents extends CustomComponent implements t.addListener(new Listener() { public void componentEvent(Event event) { status.addComponent(new Label(event.getClass().getName())); + // TODO should not use Field.toString() status.addComponent(new Label("selected: " + event.getSource().toString())); } diff --git a/tests/testbench/com/vaadin/tests/TestForTrees.java b/tests/testbench/com/vaadin/tests/TestForTrees.java index 32139511e1..c5f66a2b00 100644 --- a/tests/testbench/com/vaadin/tests/TestForTrees.java +++ b/tests/testbench/com/vaadin/tests/TestForTrees.java @@ -142,6 +142,7 @@ public class TestForTrees extends CustomComponent implements Handler { t.addListener(new Listener() { public void componentEvent(Event event) { status.addComponent(new Label(event.getClass().getName())); + // TODO should not use Field.toString() status.addComponent(new Label("selected: " + event.getSource().toString())); } diff --git a/tests/testbench/com/vaadin/tests/components/datefield/DefaultHandleUnparsableDateField.java b/tests/testbench/com/vaadin/tests/components/datefield/DefaultHandleUnparsableDateField.java index bcdc8260b0..14c0198270 100644 --- a/tests/testbench/com/vaadin/tests/components/datefield/DefaultHandleUnparsableDateField.java +++ b/tests/testbench/com/vaadin/tests/components/datefield/DefaultHandleUnparsableDateField.java @@ -17,7 +17,7 @@ public class DefaultHandleUnparsableDateField extends TestBase { date.addListener(new Property.ValueChangeListener() { public void valueChange(ValueChangeEvent event) { if (date.isValid()) { - getMainWindow().showNotification(date.toString()); + getMainWindow().showNotification(date.getStringValue()); } } diff --git a/tests/testbench/com/vaadin/tests/components/popupview/PopupViewWithRTE.java b/tests/testbench/com/vaadin/tests/components/popupview/PopupViewWithRTE.java index ea94ee2185..53d2e78927 100644 --- a/tests/testbench/com/vaadin/tests/components/popupview/PopupViewWithRTE.java +++ b/tests/testbench/com/vaadin/tests/components/popupview/PopupViewWithRTE.java @@ -28,7 +28,7 @@ public class PopupViewWithRTE extends TestBase { VerticalLayout vl = new VerticalLayout();
public String getMinimizedValueAsHTML() {
- Object value = rte.getValue();
+ String value = rte.getValue();
if (value == null || "".equals(value)) {
value = "Initial <b>content</b> for <h3>rte</h3>.";
rte.setValue(value);
diff --git a/tests/testbench/com/vaadin/tests/components/table/FooterClick.java b/tests/testbench/com/vaadin/tests/components/table/FooterClick.java index b92d6ef362..e3bad29c90 100644 --- a/tests/testbench/com/vaadin/tests/components/table/FooterClick.java +++ b/tests/testbench/com/vaadin/tests/components/table/FooterClick.java @@ -43,7 +43,7 @@ public class FooterClick extends TestBase { // Add a footer click listener table.addListener(new Table.FooterClickListener() { public void footerClick(FooterClickEvent event) { - columnField.setValue(event.getPropertyId()); + columnField.setValue(String.valueOf(event.getPropertyId())); log.log("Clicked on footer: " + event.getPropertyId()); } }); diff --git a/tests/testbench/com/vaadin/tests/components/table/HeaderClick.java b/tests/testbench/com/vaadin/tests/components/table/HeaderClick.java index 3cb11781b1..ead88094f6 100644 --- a/tests/testbench/com/vaadin/tests/components/table/HeaderClick.java +++ b/tests/testbench/com/vaadin/tests/components/table/HeaderClick.java @@ -29,7 +29,7 @@ public class HeaderClick extends TestBase { // Add a header click listener table.addListener(new Table.HeaderClickListener() { public void headerClick(HeaderClickEvent event) { - columnField.setValue(event.getPropertyId()); + columnField.setValue(String.valueOf(event.getPropertyId())); } }); diff --git a/tests/testbench/com/vaadin/tests/components/table/HugeRowCount.java b/tests/testbench/com/vaadin/tests/components/table/HugeRowCount.java index 5cd9f964a3..3478750622 100644 --- a/tests/testbench/com/vaadin/tests/components/table/HugeRowCount.java +++ b/tests/testbench/com/vaadin/tests/components/table/HugeRowCount.java @@ -20,7 +20,7 @@ public class HugeRowCount extends TestBase { container.setSize(100000); final TextField tf = new TextField("Rows"); - tf.setValue(100000); + tf.setValue(String.valueOf(100000)); tf.addListener(new Property.ValueChangeListener() { public void valueChange(ValueChangeEvent event) { container.setSize(Integer.parseInt(tf.getValue().toString())); diff --git a/tests/testbench/com/vaadin/tests/components/textfield/TextChangeEventsWithNonImmediateValueChange.java b/tests/testbench/com/vaadin/tests/components/textfield/TextChangeEventsWithNonImmediateValueChange.java index a893739bff..f44527bc1c 100644 --- a/tests/testbench/com/vaadin/tests/components/textfield/TextChangeEventsWithNonImmediateValueChange.java +++ b/tests/testbench/com/vaadin/tests/components/textfield/TextChangeEventsWithNonImmediateValueChange.java @@ -33,7 +33,7 @@ public class TextChangeEventsWithNonImmediateValueChange extends TestBase { tf.addListener(new ValueChangeListener() { public void valueChange(ValueChangeEvent event) { - l.log("Value change:" + event.getProperty().toString()); + l.log("Value change:" + event.getProperty().getValue()); } }); diff --git a/tests/testbench/com/vaadin/tests/components/tree/TreeFocusGaining.java b/tests/testbench/com/vaadin/tests/components/tree/TreeFocusGaining.java index e784009bce..87170214ca 100644 --- a/tests/testbench/com/vaadin/tests/components/tree/TreeFocusGaining.java +++ b/tests/testbench/com/vaadin/tests/components/tree/TreeFocusGaining.java @@ -21,7 +21,7 @@ public class TreeFocusGaining extends TestBase { textField.addListener(new Property.ValueChangeListener() { public void valueChange(ValueChangeEvent event) { - log.log("TF value now:" + event.getProperty()); + log.log("TF value now:" + event.getProperty().getValue()); } }); @@ -31,7 +31,7 @@ public class TreeFocusGaining extends TestBase { tree.addListener(new Property.ValueChangeListener() { public void valueChange(ValueChangeEvent event) { - log.log("Tree value now:" + event.getProperty()); + log.log("Tree value now:" + event.getProperty().getValue()); } }); tree.setImmediate(true); diff --git a/tests/testbench/com/vaadin/tests/dd/DDTest2.java b/tests/testbench/com/vaadin/tests/dd/DDTest2.java index 69af2d3f1d..961a60f776 100644 --- a/tests/testbench/com/vaadin/tests/dd/DDTest2.java +++ b/tests/testbench/com/vaadin/tests/dd/DDTest2.java @@ -94,12 +94,13 @@ public class DDTest2 extends TestBase { if (transferable instanceof TableTransferable) { TableTransferable tr = (TableTransferable) transferable; System.out.println("From table row" + tr.getPropertyId()); - data = tr.getSourceContainer().getItem(tr.getItemId()) - .getItemProperty(tr.getPropertyId()).toString(); - + Object value = tr.getSourceContainer() + .getItem(tr.getItemId()) + .getItemProperty(tr.getPropertyId()).getValue(); + data = (null != value) ? value.toString() : null; } if (data == null) { - data = "-no Text data flawor-"; + data = "-no Text data flavor-"; } tree3.addItem(data); AbstractSelect.AbstractSelectTargetDetails dropTargetData = (AbstractSelect.AbstractSelectTargetDetails) dropEvent @@ -137,7 +138,7 @@ public class DDTest2 extends TestBase { public void drop(DragAndDropEvent event) { /* * We know transferrable is from table, so it is of type - * DataBindedTransferrable + * DataBoundTransferrable */ DataBoundTransferable tr = (DataBoundTransferable) event .getTransferable(); @@ -147,8 +148,10 @@ public class DDTest2 extends TestBase { // if the source is from table (not from tree1 itself), // transfer Name property and use it as an identifier in // tree1 - String name = sourceContainer.getItem(itemId) - .getItemProperty("Name").toString(); + Object nameValue = sourceContainer.getItem(itemId) + .getItemProperty("Name").getValue(); + String name = (null != nameValue) ? nameValue.toString() + : null; tree1.addItem(name); tree1.setChildrenAllowed(name, false); diff --git a/tests/testbench/com/vaadin/tests/tickets/Ticket1397.java b/tests/testbench/com/vaadin/tests/tickets/Ticket1397.java index 282df33d89..29f59dd13c 100644 --- a/tests/testbench/com/vaadin/tests/tickets/Ticket1397.java +++ b/tests/testbench/com/vaadin/tests/tickets/Ticket1397.java @@ -31,7 +31,7 @@ public class Ticket1397 extends Application { PopupView.Content content = new PopupView.Content() { public String getMinimizedValueAsHTML() { - return prop.toString(); + return String.valueOf(prop.getValue()); } public Component getPopupComponent() { @@ -69,7 +69,7 @@ public class Ticket1397 extends Application { panel2.addComponent(new myButton()); PopupView.Content content2 = new PopupView.Content() { public String getMinimizedValueAsHTML() { - return prop2.toString(); + return String.valueOf(prop2.getValue()); } public Component getPopupComponent() { @@ -90,7 +90,7 @@ public class Ticket1397 extends Application { PopupView.Content content3 = new PopupView.Content() { public String getMinimizedValueAsHTML() { - return op.toString(); + return String.valueOf(op.getValue()); } public Component getPopupComponent() { @@ -114,7 +114,7 @@ public class Ticket1397 extends Application { final InlineDateField df = new InlineDateField("", new Date()); PopupView pp = new PopupView(new PopupView.Content() { public String getMinimizedValueAsHTML() { - return df.toString(); + return String.valueOf(df.getValue()); } public Component getPopupComponent() { @@ -131,7 +131,8 @@ public class Ticket1397 extends Application { + " and see how the overview-version changes."); public String getMinimizedValueAsHTML() { - return "" + tf.toString().length() + " characters of info"; + return "" + String.valueOf(tf.getValue()).length() + + " characters of info"; } public Component getPopupComponent() { diff --git a/tests/testbench/com/vaadin/tests/tickets/Ticket2053.java b/tests/testbench/com/vaadin/tests/tickets/Ticket2053.java index f784b40aed..5b83c3033b 100644 --- a/tests/testbench/com/vaadin/tests/tickets/Ticket2053.java +++ b/tests/testbench/com/vaadin/tests/tickets/Ticket2053.java @@ -42,7 +42,7 @@ public class Ticket2053 extends Application { tf.addListener(new Property.ValueChangeListener() { public void valueChange(ValueChangeEvent event) { main.addComponent(new Label(name + " send text:" - + tf.toString())); + + tf.getStringValue())); } }); for (int i = 0; i < 3; i++) { diff --git a/tests/testbench/com/vaadin/tests/tickets/Ticket2090.java b/tests/testbench/com/vaadin/tests/tickets/Ticket2090.java index 5bc69e0a64..669a3e29fe 100644 --- a/tests/testbench/com/vaadin/tests/tickets/Ticket2090.java +++ b/tests/testbench/com/vaadin/tests/tickets/Ticket2090.java @@ -30,7 +30,7 @@ public class Ticket2090 extends Application { height.addListener(new Property.ValueChangeListener() { public void valueChange(ValueChangeEvent event) { try { - target.setHeight(height.toString()); + target.setHeight(height.getStringValue()); height.setComponentError(null); updateLabel(); } catch (Exception e) { @@ -41,7 +41,7 @@ public class Ticket2090 extends Application { width.addListener(new Property.ValueChangeListener() { public void valueChange(ValueChangeEvent event) { try { - target.setWidth(width.toString()); + target.setWidth(width.getStringValue()); width.setComponentError(null); updateLabel(); } catch (Exception e) { diff --git a/tests/testbench/com/vaadin/tests/tickets/Ticket2119.java b/tests/testbench/com/vaadin/tests/tickets/Ticket2119.java index c1e0d64dde..220fd168da 100644 --- a/tests/testbench/com/vaadin/tests/tickets/Ticket2119.java +++ b/tests/testbench/com/vaadin/tests/tickets/Ticket2119.java @@ -74,7 +74,9 @@ public class Ticket2119 extends Application { globalValue.addListener(new Property.ValueChangeListener() { public void valueChange(Property.ValueChangeEvent event) { - valueProperty.setValue(event.getProperty().getValue()); + Object value = event.getProperty().getValue(); + valueProperty.setValue((null != value) ? value.toString() + : null); } }); diff --git a/tests/testbench/com/vaadin/tests/tickets/Ticket2151.java b/tests/testbench/com/vaadin/tests/tickets/Ticket2151.java index 5a48156367..ca0f2cf367 100644 --- a/tests/testbench/com/vaadin/tests/tickets/Ticket2151.java +++ b/tests/testbench/com/vaadin/tests/tickets/Ticket2151.java @@ -46,31 +46,17 @@ public class Ticket2151 extends Application { } private void check(Class<? extends Button> class1) { - boolean ok = false; Button b; try { b = class1.newInstance(); - b.setCaption("Button of type " + class1.getSimpleName()); - try { - // This should throw an exception - b.setValue("ON"); - } catch (IllegalArgumentException e) { - ok = true; - } catch (Exception e) { - e.printStackTrace(); - } } catch (Exception e1) { e1.printStackTrace(); return; } - if (ok) { - status.setValue(status.getValue() + " " - + class1.getClass().getSimpleName() + ": OK"); - } else { - status.setValue(status.getValue() + " " - + class1.getClass().getSimpleName() + ": FAILED"); - } + b.setCaption("Button of type " + class1.getSimpleName()); + status.setValue(status.getValue() + " " + + class1.getClass().getSimpleName() + ": OK"); } diff --git a/tests/testbench/com/vaadin/tests/tickets/Ticket2998.java b/tests/testbench/com/vaadin/tests/tickets/Ticket2998.java index 81ffcf5a01..297a357f08 100644 --- a/tests/testbench/com/vaadin/tests/tickets/Ticket2998.java +++ b/tests/testbench/com/vaadin/tests/tickets/Ticket2998.java @@ -129,7 +129,7 @@ public class Ticket2998 extends Application { close();
} else {
date.setValue(run.getDate());
- kilomiters.setValue(run.getKilometers());
+ kilomiters.setValue(String.valueOf(run.getKilometers()));
title.setValue(run.getTitle());
if (getParent() == null) {
workoutLog.getMainWindow().addWindow(this);
diff --git a/tests/testbench/com/vaadin/tests/tickets/Ticket736.java b/tests/testbench/com/vaadin/tests/tickets/Ticket736.java index c530b7ca99..407242e06c 100644 --- a/tests/testbench/com/vaadin/tests/tickets/Ticket736.java +++ b/tests/testbench/com/vaadin/tests/tickets/Ticket736.java @@ -50,7 +50,7 @@ public class Ticket736 extends Application { // Add some validators for the form f.getField("zip").addValidator(new IsInteger()); - f.getField("zip").setDescription("Jepjep"); + ((AbstractComponent) f.getField("zip")).setDescription("Jepjep"); ((AbstractComponent) f.getField("zip")).setIcon(new ThemeResource( "../runo/icons/16/folder.png")); f.getField("state").addValidator(new IsValidState()); |