summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/com/vaadin/data/Property.java24
-rw-r--r--src/com/vaadin/data/util/AbstractBeanContainer.java10
-rw-r--r--src/com/vaadin/data/util/AbstractProperty.java5
-rw-r--r--src/com/vaadin/data/util/MethodProperty.java14
-rw-r--r--src/com/vaadin/data/util/NestedMethodProperty.java13
-rw-r--r--src/com/vaadin/data/util/ObjectProperty.java13
-rw-r--r--src/com/vaadin/data/util/PropertyFormatter.java29
-rw-r--r--src/com/vaadin/data/util/TextFileProperty.java6
-rw-r--r--src/com/vaadin/ui/AbstractField.java49
-rw-r--r--src/com/vaadin/ui/AbstractSelect.java3
-rw-r--r--src/com/vaadin/ui/AbstractTextField.java10
-rw-r--r--src/com/vaadin/ui/Button.java13
-rw-r--r--src/com/vaadin/ui/DateField.java12
-rw-r--r--src/com/vaadin/ui/Field.java8
-rw-r--r--src/com/vaadin/ui/Form.java4
-rw-r--r--src/com/vaadin/ui/Label.java1
-rw-r--r--src/com/vaadin/ui/ProgressIndicator.java11
-rw-r--r--src/com/vaadin/ui/RichTextArea.java6
-rw-r--r--src/com/vaadin/ui/Slider.java9
-rw-r--r--tests/server-side/com/vaadin/data/util/ObjectPropertyTest.java8
-rw-r--r--tests/server-side/com/vaadin/data/util/filter/AbstractFilterTest.java6
-rw-r--r--tests/server-side/com/vaadin/tests/server/validation/TestReadOnlyValidation.java2
-rw-r--r--tests/testbench/com/vaadin/tests/components/popupview/PopupViewWithRTE.java2
-rw-r--r--tests/testbench/com/vaadin/tests/components/table/FooterClick.java2
-rw-r--r--tests/testbench/com/vaadin/tests/components/table/HeaderClick.java2
-rw-r--r--tests/testbench/com/vaadin/tests/components/table/HugeRowCount.java2
-rw-r--r--tests/testbench/com/vaadin/tests/tickets/Ticket2119.java4
-rw-r--r--tests/testbench/com/vaadin/tests/tickets/Ticket2151.java20
-rw-r--r--tests/testbench/com/vaadin/tests/tickets/Ticket2998.java2
29 files changed, 143 insertions, 147 deletions
diff --git a/src/com/vaadin/data/Property.java b/src/com/vaadin/data/Property.java
index 3f0da39514..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,26 +55,19 @@ 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.
*
- * TODO correct this comment as eliminating Property.toString()
+ * 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;
@@ -85,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 2297f13734..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,8 +56,7 @@ 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()}
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 5f97d4d0c7..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&lt;String&gt;)
+ *
* @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;
@@ -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,7 +139,7 @@ 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() {
+ public String getValue() {
return getStringValue();
}
@@ -147,7 +152,7 @@ public abstract class PropertyFormatter extends AbstractProperty implements
*/
@Override
public String getStringValue() {
- Object value = dataSource == null ? false : dataSource.getValue();
+ T value = dataSource == null ? null : dataSource.getValue();
if (value == null) {
return null;
}
@@ -170,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.
@@ -184,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.
@@ -211,7 +216,7 @@ public abstract class PropertyFormatter extends AbstractProperty implements
}
} else {
try {
- dataSource.setValue(parse((String) newValue));
+ dataSource.setValue(parse(newValue.toString()));
if (!newValue.equals(getStringValue())) {
fireValueChange();
}
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/ui/AbstractField.java b/src/com/vaadin/ui/AbstractField.java
index 7b686fd397..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) {
@@ -325,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);
}
@@ -393,6 +395,7 @@ public abstract class AbstractField extends AbstractComponent implements Field,
if (String.class == getType() && newValue != null) {
newValue = newValue.toString();
}
+ // TODO use converter
setInternalValue(newValue);
fireValueChange(false);
}
@@ -416,12 +419,11 @@ public abstract class AbstractField extends AbstractComponent implements Field,
}
/**
- * Returns the (UI type) value of the field converted to a String using
- * 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, access getValue()
- * directly. This method may disappear in future Vaadin versions.
+ * 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
@@ -440,27 +442,25 @@ 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()) {
@@ -468,10 +468,11 @@ public abstract class AbstractField extends AbstractComponent implements Field,
}
Object result = dataSource.getValue();
+ // TODO perform correct conversion, no cast or toString()
if (String.class == getType() && result != null) {
result = result.toString();
}
- return result;
+ return (T) result;
}
/**
@@ -537,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;
@@ -643,6 +644,7 @@ public abstract class AbstractField extends AbstractComponent implements Field,
if (String.class == getType() && newValue != null) {
newValue = newValue.toString();
}
+ // TODO use converter
setInternalValue(newValue);
}
modified = false;
@@ -1070,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());
}
@@ -1134,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();
}
diff --git a/src/com/vaadin/ui/AbstractSelect.java b/src/com/vaadin/ui/AbstractSelect.java
index eaac3bb4c5..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 {
diff --git a/src/com/vaadin/ui/AbstractTextField.java b/src/com/vaadin/ui/AbstractTextField.java
index 8d775c862e..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;
}
@@ -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();
}
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 1f9bea311f..5cc81a9e92 100644
--- a/src/com/vaadin/ui/Field.java
+++ b/src/com/vaadin/ui/Field.java
@@ -9,9 +9,15 @@ import com.vaadin.data.Property;
import com.vaadin.ui.Component.Focusable;
/**
+ * 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 {
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 1249f20a62..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> {
diff --git a/src/com/vaadin/ui/ProgressIndicator.java b/src/com/vaadin/ui/ProgressIndicator.java
index 6f2758f323..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) {
@@ -163,7 +164,7 @@ public class ProgressIndicator extends AbstractField implements Property,
* @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 612cc24e8b..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;
}
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/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/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/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/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/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);