Browse Source

Parameterize Property and Field with the value type.

The interfaces Property and Field and most of their implementations are
now parameterized with the type of their value. The method getValue()
returns the Property type but setValue() takes Object as its parameter.
No implicit conversions between value type and strings are performed in
most locations (fields).

Among others, AbstractTextField, DateField and RichTextArea not have
specific value types and do not accept arbitrary values.

Most locations requiring migration will be visible as compilation
errors, with the exception of some cases where a non-parameterized
Property or Field (or one parametrized with Object) is used.

Not yet done:
- Label
- converters
- setValue() parameterization (causes much more migration effort)
tags/7.0.0.alpha1
Henri Sara 12 years ago
parent
commit
0ab1d01c8d
29 changed files with 143 additions and 147 deletions
  1. 10
    14
      src/com/vaadin/data/Property.java
  2. 5
    5
      src/com/vaadin/data/util/AbstractBeanContainer.java
  3. 2
    3
      src/com/vaadin/data/util/AbstractProperty.java
  4. 6
    8
      src/com/vaadin/data/util/MethodProperty.java
  5. 7
    6
      src/com/vaadin/data/util/NestedMethodProperty.java
  6. 6
    7
      src/com/vaadin/data/util/ObjectProperty.java
  7. 17
    12
      src/com/vaadin/data/util/PropertyFormatter.java
  8. 3
    3
      src/com/vaadin/data/util/TextFileProperty.java
  9. 26
    23
      src/com/vaadin/ui/AbstractField.java
  10. 2
    1
      src/com/vaadin/ui/AbstractSelect.java
  11. 5
    5
      src/com/vaadin/ui/AbstractTextField.java
  12. 7
    6
      src/com/vaadin/ui/Button.java
  13. 6
    6
      src/com/vaadin/ui/DateField.java
  14. 7
    1
      src/com/vaadin/ui/Field.java
  15. 2
    2
      src/com/vaadin/ui/Form.java
  16. 1
    0
      src/com/vaadin/ui/Label.java
  17. 6
    5
      src/com/vaadin/ui/ProgressIndicator.java
  18. 3
    3
      src/com/vaadin/ui/RichTextArea.java
  19. 4
    5
      src/com/vaadin/ui/Slider.java
  20. 3
    5
      tests/server-side/com/vaadin/data/util/ObjectPropertyTest.java
  21. 3
    3
      tests/server-side/com/vaadin/data/util/filter/AbstractFilterTest.java
  22. 1
    1
      tests/server-side/com/vaadin/tests/server/validation/TestReadOnlyValidation.java
  23. 1
    1
      tests/testbench/com/vaadin/tests/components/popupview/PopupViewWithRTE.java
  24. 1
    1
      tests/testbench/com/vaadin/tests/components/table/FooterClick.java
  25. 1
    1
      tests/testbench/com/vaadin/tests/components/table/HeaderClick.java
  26. 1
    1
      tests/testbench/com/vaadin/tests/components/table/HugeRowCount.java
  27. 3
    1
      tests/testbench/com/vaadin/tests/tickets/Ticket2119.java
  28. 3
    17
      tests/testbench/com/vaadin/tests/tickets/Ticket2151.java
  29. 1
    1
      tests/testbench/com/vaadin/tests/tickets/Ticket2998.java

+ 10
- 14
src/com/vaadin/data/Property.java View File

@@ -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

+ 5
- 5
src/com/vaadin/data/util/AbstractBeanContainer.java View File

@@ -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

+ 2
- 3
src/com/vaadin/data/util/AbstractProperty.java View File

@@ -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()}

+ 6
- 8
src/com/vaadin/data/util/MethodProperty.java View File

@@ -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 {


+ 7
- 6
src/com/vaadin/data/util/NestedMethodProperty.java View File

@@ -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);
}

+ 6
- 7
src/com/vaadin/data/util/ObjectProperty.java View File

@@ -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);
}

+ 17
- 12
src/com/vaadin/data/util/PropertyFormatter.java View File

@@ -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();
}

+ 3
- 3
src/com/vaadin/data/util/TextFileProperty.java View File

@@ -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;
}

+ 26
- 23
src/com/vaadin/ui/AbstractField.java View File

@@ -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();
}

+ 2
- 1
src/com/vaadin/ui/AbstractSelect.java View File

@@ -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 {

+ 5
- 5
src/com/vaadin/ui/AbstractTextField.java View File

@@ -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();
}

+ 7
- 6
src/com/vaadin/ui/Button.java View File

@@ -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;
}


+ 6
- 6
src/com/vaadin/ui/DateField.java View File

@@ -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);
}

+ 7
- 1
src/com/vaadin/ui/Field.java View File

@@ -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 {


+ 2
- 2
src/com/vaadin/ui/Form.java View File

@@ -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;


+ 1
- 0
src/com/vaadin/ui/Label.java View File

@@ -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> {

+ 6
- 5
src/com/vaadin/ui/ProgressIndicator.java View File

@@ -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");
}

+ 3
- 3
src/com/vaadin/ui/RichTextArea.java View File

@@ -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;
}

+ 4
- 5
src/com/vaadin/ui/Slider.java View File

@@ -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;
}


+ 3
- 5
tests/server-side/com/vaadin/data/util/ObjectPropertyTest.java View File

@@ -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());
}

+ 3
- 3
tests/server-side/com/vaadin/data/util/filter/AbstractFilterTest.java View File

@@ -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;
}


+ 1
- 1
tests/server-side/com/vaadin/tests/server/validation/TestReadOnlyValidation.java View File

@@ -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();
}
}

+ 1
- 1
tests/testbench/com/vaadin/tests/components/popupview/PopupViewWithRTE.java View File

@@ -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);

+ 1
- 1
tests/testbench/com/vaadin/tests/components/table/FooterClick.java View File

@@ -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());
}
});

+ 1
- 1
tests/testbench/com/vaadin/tests/components/table/HeaderClick.java View File

@@ -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()));
}
});


+ 1
- 1
tests/testbench/com/vaadin/tests/components/table/HugeRowCount.java View File

@@ -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()));

+ 3
- 1
tests/testbench/com/vaadin/tests/tickets/Ticket2119.java View File

@@ -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);
}
});


+ 3
- 17
tests/testbench/com/vaadin/tests/tickets/Ticket2151.java View File

@@ -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");

}


+ 1
- 1
tests/testbench/com/vaadin/tests/tickets/Ticket2998.java View File

@@ -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);

Loading…
Cancel
Save