From b8a5152089990aa2b2454bc11dadbfd1d5362709 Mon Sep 17 00:00:00 2001
From: Artur Signell
Date: Wed, 21 Dec 2011 19:08:08 +0200
Subject: [PATCH] #8101 Renamed source type to presentation and target type to
model for clarity
---
.../converter/BooleanToStringConverter.java | 8 +--
.../vaadin/data/util/converter/Converter.java | 53 +++++++++----------
.../util/converter/DateToStringConverter.java | 14 ++---
.../converter/DoubleToStringConverter.java | 14 ++---
.../converter/IntegerToStringConverter.java | 14 ++---
.../util/converter/LongToDateConverter.java | 8 +--
.../converter/NumberToStringConverter.java | 14 ++---
.../data/util/converter/ReverseConverter.java | 28 +++++-----
src/com/vaadin/ui/AbstractField.java | 12 ++---
src/com/vaadin/ui/Table.java | 33 ++++++++++--
.../AbstractFieldValueConversions.java | 26 ++++-----
.../Vaadin6ImplicitDoubleConverter.java | 8 +--
.../components/table/DoublesInTable.java | 32 +++++------
13 files changed, 143 insertions(+), 121 deletions(-)
diff --git a/src/com/vaadin/data/util/converter/BooleanToStringConverter.java b/src/com/vaadin/data/util/converter/BooleanToStringConverter.java
index 466f0f3b79..9c6add7c99 100644
--- a/src/com/vaadin/data/util/converter/BooleanToStringConverter.java
+++ b/src/com/vaadin/data/util/converter/BooleanToStringConverter.java
@@ -27,7 +27,7 @@ public class BooleanToStringConverter implements Converter {
* com.vaadin.data.util.converter.Converter#convertFromTargetToSource(java
* .lang.Object, java.util.Locale)
*/
- public Boolean convertFromTargetToSource(String value, Locale locale)
+ public Boolean convertToModel(String value, Locale locale)
throws ConversionException {
if (value == null) {
return null;
@@ -61,7 +61,7 @@ public class BooleanToStringConverter implements Converter {
* com.vaadin.data.util.converter.Converter#convertFromSourceToTarget(java
* .lang.Object, java.util.Locale)
*/
- public String convertFromSourceToTarget(Boolean value, Locale locale)
+ public String convertToPresentation(Boolean value, Locale locale)
throws ConversionException {
if (value == null) {
return null;
@@ -78,7 +78,7 @@ public class BooleanToStringConverter implements Converter {
*
* @see com.vaadin.data.util.converter.Converter#getSourceType()
*/
- public Class getSourceType() {
+ public Class getModelType() {
return Boolean.class;
}
@@ -87,7 +87,7 @@ public class BooleanToStringConverter implements Converter {
*
* @see com.vaadin.data.util.converter.Converter#getTargetType()
*/
- public Class getTargetType() {
+ public Class getPresentationType() {
return String.class;
}
diff --git a/src/com/vaadin/data/util/converter/Converter.java b/src/com/vaadin/data/util/converter/Converter.java
index 943d6ec76a..2a2c3025d9 100644
--- a/src/com/vaadin/data/util/converter/Converter.java
+++ b/src/com/vaadin/data/util/converter/Converter.java
@@ -8,13 +8,13 @@ import java.io.Serializable;
import java.util.Locale;
/**
- * Interface that implements conversion between objects of one type to another
- * and back.
+ * Interface that implements conversion between objects between model and
+ * presentation types.
*
- * Typically {@link #convertFromSourceToTarget(Object, Locale)} and
- * {@link #convertFromTargetToSource(Object, Locale)} should be symmetric so
- * that chaining these together returns the original result for all input but
- * this is not a requirement.
+ * Typically {@link #convertToPresentation(Object, Locale)} and
+ * {@link #convertToModel(Object, Locale)} should be symmetric so that chaining
+ * these together returns the original result for all input but this is not a
+ * requirement.
*
*
* Converters must not have any side effects (never update UI from inside a
@@ -27,18 +27,18 @@ import java.util.Locale;
* If conversion of a value fails, a {@link ConversionException} is thrown.
*
*
- * @param
* A converter should in most cases be symmetric so chaining
- * {@link #convertFromSourceToTarget(Object, Locale)} and
- * {@link #convertFromTargetToSource(Object, Locale)} should return the
- * original value.
+ * {@link #convertToPresentation(Object, Locale)} and
+ * {@link #convertToModel(Object, Locale)} should return the original value.
*
* @param value
* The value to convert, compatible with the target type. Can be
@@ -59,7 +58,7 @@ public interface Converter extends Serializable {
* @throws ConversionException
* If the value could not be converted
*/
- public SOURCE convertFromTargetToSource(TARGET value, Locale locale)
+ public MODEL convertToModel(PRESENTATION value, Locale locale)
throws ConversionException;
/**
@@ -68,9 +67,8 @@ public interface Converter extends Serializable {
* A converter can optionally use locale to do the conversion.
*
* A converter should in most cases be symmetric so chaining
- * {@link #convertFromSourceToTarget(Object, Locale)} and
- * {@link #convertFromTargetToSource(Object, Locale)} should return the
- * original value.
+ * {@link #convertToPresentation(Object, Locale)} and
+ * {@link #convertToModel(Object, Locale)} should return the original value.
*
* @param value
* The value to convert, compatible with the target type. Can be
@@ -81,34 +79,33 @@ public interface Converter extends Serializable {
* @throws ConversionException
* If the value could not be converted
*/
- public TARGET convertFromSourceToTarget(SOURCE value, Locale locale)
+ public PRESENTATION convertToPresentation(MODEL value, Locale locale)
throws ConversionException;
/**
* The source type of the converter.
*
* Values of this type can be passed to
- * {@link #convertFromSourceToTarget(Object, Locale)}.
+ * {@link #convertToPresentation(Object, Locale)}.
*
* @return The source type
*/
- public Class getSourceType();
+ public Class getModelType();
/**
* The target type of the converter.
*
* Values of this type can be passed to
- * {@link #convertFromTargetToSource(Object, Locale)}.
+ * {@link #convertToModel(Object, Locale)}.
*
* @return The target type
*/
- public Class getTargetType();
+ public Class getPresentationType();
/**
* An exception that signals that the value passed to
- * {@link Converter#convertFromSourceToTarget(Object, Locale)} or
- * {@link Converter#convertFromTargetToSource(Object, Locale)} could not be
- * converted.
+ * {@link Converter#convertToPresentation(Object, Locale)} or
+ * {@link Converter#convertToModel(Object, Locale)} could not be converted.
*
* @author Vaadin Ltd
* @version
diff --git a/src/com/vaadin/data/util/converter/DateToStringConverter.java b/src/com/vaadin/data/util/converter/DateToStringConverter.java
index 56405b776a..947a426db6 100644
--- a/src/com/vaadin/data/util/converter/DateToStringConverter.java
+++ b/src/com/vaadin/data/util/converter/DateToStringConverter.java
@@ -28,8 +28,8 @@ public class DateToStringConverter implements Converter {
/**
* Returns the format used by
- * {@link #convertFromSourceToTarget(Date, Locale)} and
- * {@link #convertFromTargetToSource(String, Locale)}.
+ * {@link #convertToPresentation(Date, Locale)} and
+ * {@link #convertToModel(String, Locale)}.
*
* @param locale
* The locale to use
@@ -53,7 +53,7 @@ public class DateToStringConverter implements Converter {
* com.vaadin.data.util.converter.Converter#convertFromTargetToSource(java
* .lang.Object, java.util.Locale)
*/
- public Date convertFromTargetToSource(String value, Locale locale)
+ public Date convertToModel(String value, Locale locale)
throws com.vaadin.data.util.converter.Converter.ConversionException {
if (value == null) {
return null;
@@ -66,7 +66,7 @@ public class DateToStringConverter implements Converter {
Date parsedValue = getFormat(locale).parse(value, parsePosition);
if (parsePosition.getIndex() != value.length()) {
throw new ConversionException("Could not convert '" + value
- + "' to " + getTargetType().getName());
+ + "' to " + getPresentationType().getName());
}
return parsedValue;
@@ -79,7 +79,7 @@ public class DateToStringConverter implements Converter {
* com.vaadin.data.util.converter.Converter#convertFromSourceToTarget(java
* .lang.Object, java.util.Locale)
*/
- public String convertFromSourceToTarget(Date value, Locale locale)
+ public String convertToPresentation(Date value, Locale locale)
throws com.vaadin.data.util.converter.Converter.ConversionException {
if (value == null) {
return null;
@@ -93,7 +93,7 @@ public class DateToStringConverter implements Converter {
*
* @see com.vaadin.data.util.converter.Converter#getSourceType()
*/
- public Class getSourceType() {
+ public Class getModelType() {
return Date.class;
}
@@ -102,7 +102,7 @@ public class DateToStringConverter implements Converter {
*
* @see com.vaadin.data.util.converter.Converter#getTargetType()
*/
- public Class getTargetType() {
+ public Class getPresentationType() {
return String.class;
}
diff --git a/src/com/vaadin/data/util/converter/DoubleToStringConverter.java b/src/com/vaadin/data/util/converter/DoubleToStringConverter.java
index e548936e2f..a6bebaddd3 100644
--- a/src/com/vaadin/data/util/converter/DoubleToStringConverter.java
+++ b/src/com/vaadin/data/util/converter/DoubleToStringConverter.java
@@ -28,8 +28,8 @@ public class DoubleToStringConverter implements Converter {
/**
* Returns the format used by
- * {@link #convertFromSourceToTarget(Double, Locale)} and
- * {@link #convertFromTargetToSource(String, Locale)}.
+ * {@link #convertToPresentation(Double, Locale)} and
+ * {@link #convertToModel(String, Locale)}.
*
* @param locale
* The locale to use
@@ -50,7 +50,7 @@ public class DoubleToStringConverter implements Converter {
* com.vaadin.data.util.converter.Converter#convertFromTargetToSource(java
* .lang.Object, java.util.Locale)
*/
- public Double convertFromTargetToSource(String value, Locale locale)
+ public Double convertToModel(String value, Locale locale)
throws ConversionException {
if (value == null) {
return null;
@@ -63,7 +63,7 @@ public class DoubleToStringConverter implements Converter {
Number parsedValue = getFormat(locale).parse(value, parsePosition);
if (parsePosition.getIndex() != value.length()) {
throw new ConversionException("Could not convert '" + value
- + "' to " + getTargetType().getName());
+ + "' to " + getPresentationType().getName());
}
return parsedValue.doubleValue();
}
@@ -75,7 +75,7 @@ public class DoubleToStringConverter implements Converter {
* com.vaadin.data.util.converter.Converter#convertFromSourceToTarget(java
* .lang.Object, java.util.Locale)
*/
- public String convertFromSourceToTarget(Double value, Locale locale)
+ public String convertToPresentation(Double value, Locale locale)
throws ConversionException {
if (value == null) {
return null;
@@ -89,7 +89,7 @@ public class DoubleToStringConverter implements Converter {
*
* @see com.vaadin.data.util.converter.Converter#getSourceType()
*/
- public Class getSourceType() {
+ public Class getModelType() {
return Double.class;
}
@@ -98,7 +98,7 @@ public class DoubleToStringConverter implements Converter {
*
* @see com.vaadin.data.util.converter.Converter#getTargetType()
*/
- public Class getTargetType() {
+ public Class getPresentationType() {
return String.class;
}
}
diff --git a/src/com/vaadin/data/util/converter/IntegerToStringConverter.java b/src/com/vaadin/data/util/converter/IntegerToStringConverter.java
index afd63b88c4..5c0d6761c0 100644
--- a/src/com/vaadin/data/util/converter/IntegerToStringConverter.java
+++ b/src/com/vaadin/data/util/converter/IntegerToStringConverter.java
@@ -25,8 +25,8 @@ public class IntegerToStringConverter implements Converter {
/**
* Returns the format used by
- * {@link #convertFromSourceToTarget(Integer, Locale)} and
- * {@link #convertFromTargetToSource(String, Locale)}.
+ * {@link #convertToPresentation(Integer, Locale)} and
+ * {@link #convertToModel(String, Locale)}.
*
* @param locale
* The locale to use
@@ -39,7 +39,7 @@ public class IntegerToStringConverter implements Converter {
return NumberFormat.getIntegerInstance(locale);
}
- public Integer convertFromTargetToSource(String value, Locale locale)
+ public Integer convertToModel(String value, Locale locale)
throws ConversionException {
if (value == null) {
return null;
@@ -54,7 +54,7 @@ public class IntegerToStringConverter implements Converter {
Number parsedValue = getFormat(locale).parse(value, parsePosition);
if (parsePosition.getIndex() != value.length()) {
throw new ConversionException("Could not convert '" + value
- + "' to " + getSourceType().getName());
+ + "' to " + getModelType().getName());
}
if (parsedValue == null) {
@@ -64,7 +64,7 @@ public class IntegerToStringConverter implements Converter {
return parsedValue.intValue();
}
- public String convertFromSourceToTarget(Integer value, Locale locale)
+ public String convertToPresentation(Integer value, Locale locale)
throws ConversionException {
if (value == null) {
return null;
@@ -73,11 +73,11 @@ public class IntegerToStringConverter implements Converter {
return getFormat(locale).format(value);
}
- public Class getSourceType() {
+ public Class getModelType() {
return Integer.class;
}
- public Class getTargetType() {
+ public Class getPresentationType() {
return String.class;
}
diff --git a/src/com/vaadin/data/util/converter/LongToDateConverter.java b/src/com/vaadin/data/util/converter/LongToDateConverter.java
index c7d2a33c76..c22e8af16e 100644
--- a/src/com/vaadin/data/util/converter/LongToDateConverter.java
+++ b/src/com/vaadin/data/util/converter/LongToDateConverter.java
@@ -24,7 +24,7 @@ public class LongToDateConverter implements Converter {
* com.vaadin.data.util.converter.Converter#convertFromTargetToSource(java
* .lang.Object, java.util.Locale)
*/
- public Long convertFromTargetToSource(Date value, Locale locale) {
+ public Long convertToModel(Date value, Locale locale) {
if (value == null) {
return null;
}
@@ -39,7 +39,7 @@ public class LongToDateConverter implements Converter {
* com.vaadin.data.util.converter.Converter#convertFromSourceToTarget(java
* .lang.Object, java.util.Locale)
*/
- public Date convertFromSourceToTarget(Long value, Locale locale) {
+ public Date convertToPresentation(Long value, Locale locale) {
if (value == null) {
return null;
}
@@ -52,7 +52,7 @@ public class LongToDateConverter implements Converter {
*
* @see com.vaadin.data.util.converter.Converter#getSourceType()
*/
- public Class getSourceType() {
+ public Class getModelType() {
return Long.class;
}
@@ -61,7 +61,7 @@ public class LongToDateConverter implements Converter {
*
* @see com.vaadin.data.util.converter.Converter#getTargetType()
*/
- public Class getTargetType() {
+ public Class getPresentationType() {
return Date.class;
}
diff --git a/src/com/vaadin/data/util/converter/NumberToStringConverter.java b/src/com/vaadin/data/util/converter/NumberToStringConverter.java
index 227751dbfd..cd4c1363b7 100644
--- a/src/com/vaadin/data/util/converter/NumberToStringConverter.java
+++ b/src/com/vaadin/data/util/converter/NumberToStringConverter.java
@@ -24,8 +24,8 @@ public class NumberToStringConverter implements Converter {
/**
* Returns the format used by
- * {@link #convertFromSourceToTarget(Number, Locale)} and
- * {@link #convertFromTargetToSource(String, Locale)}.
+ * {@link #convertToPresentation(Number, Locale)} and
+ * {@link #convertToModel(String, Locale)}.
*
* @param locale
* The locale to use
@@ -46,7 +46,7 @@ public class NumberToStringConverter implements Converter {
* com.vaadin.data.util.converter.Converter#convertFromTargetToSource(java
* .lang.Object, java.util.Locale)
*/
- public Number convertFromTargetToSource(String value, Locale locale)
+ public Number convertToModel(String value, Locale locale)
throws ConversionException {
if (value == null) {
return null;
@@ -61,7 +61,7 @@ public class NumberToStringConverter implements Converter {
Number parsedValue = getFormat(locale).parse(value, parsePosition);
if (parsePosition.getIndex() != value.length()) {
throw new ConversionException("Could not convert '" + value
- + "' to " + getTargetType().getName());
+ + "' to " + getPresentationType().getName());
}
if (parsedValue == null) {
@@ -78,7 +78,7 @@ public class NumberToStringConverter implements Converter {
* com.vaadin.data.util.converter.Converter#convertFromSourceToTarget(java
* .lang.Object, java.util.Locale)
*/
- public String convertFromSourceToTarget(Number value, Locale locale)
+ public String convertToPresentation(Number value, Locale locale)
throws ConversionException {
if (value == null) {
return null;
@@ -92,7 +92,7 @@ public class NumberToStringConverter implements Converter {
*
* @see com.vaadin.data.util.converter.Converter#getSourceType()
*/
- public Class getSourceType() {
+ public Class getModelType() {
return Number.class;
}
@@ -101,7 +101,7 @@ public class NumberToStringConverter implements Converter {
*
* @see com.vaadin.data.util.converter.Converter#getTargetType()
*/
- public Class getTargetType() {
+ public Class getPresentationType() {
return String.class;
}
diff --git a/src/com/vaadin/data/util/converter/ReverseConverter.java b/src/com/vaadin/data/util/converter/ReverseConverter.java
index d3e2540b57..c86ba72395 100644
--- a/src/com/vaadin/data/util/converter/ReverseConverter.java
+++ b/src/com/vaadin/data/util/converter/ReverseConverter.java
@@ -10,9 +10,9 @@ import java.util.Locale;
* A converter that wraps another {@link Converter} and reverses source and
* target types.
*
- * @param
+ * @param
* The source type
- * @param
+ * @param
* The target type
*
* @author Vaadin Ltd
@@ -20,10 +20,10 @@ import java.util.Locale;
* @VERSION@
* @since 7.0
*/
-public class ReverseConverter implements
- Converter {
+public class ReverseConverter implements
+ Converter {
- private Converter realConverter;
+ private Converter realConverter;
/**
* Creates a converter from source to target based on a converter that
@@ -32,7 +32,7 @@ public class ReverseConverter implements
* @param converter
* The converter to use in a reverse fashion
*/
- public ReverseConverter(Converter converter) {
+ public ReverseConverter(Converter converter) {
this.realConverter = converter;
}
@@ -43,9 +43,9 @@ public class ReverseConverter implements
* com.vaadin.data.util.converter.Converter#convertFromTargetToSource(java
* .lang.Object, java.util.Locale)
*/
- public SOURCE convertFromTargetToSource(TARGET value, Locale locale)
+ public MODEL convertToModel(PRESENTATION value, Locale locale)
throws com.vaadin.data.util.converter.Converter.ConversionException {
- return realConverter.convertFromSourceToTarget(value, locale);
+ return realConverter.convertToPresentation(value, locale);
}
/*
@@ -55,9 +55,9 @@ public class ReverseConverter implements
* com.vaadin.data.util.converter.Converter#convertFromSourceToTarget(java
* .lang.Object, java.util.Locale)
*/
- public TARGET convertFromSourceToTarget(SOURCE value, Locale locale)
+ public PRESENTATION convertToPresentation(MODEL value, Locale locale)
throws com.vaadin.data.util.converter.Converter.ConversionException {
- return realConverter.convertFromTargetToSource(value, locale);
+ return realConverter.convertToModel(value, locale);
}
/*
@@ -65,8 +65,8 @@ public class ReverseConverter implements
*
* @see com.vaadin.data.util.converter.Converter#getSourceType()
*/
- public Class getSourceType() {
- return realConverter.getTargetType();
+ public Class getModelType() {
+ return realConverter.getPresentationType();
}
/*
@@ -74,8 +74,8 @@ public class ReverseConverter implements
*
* @see com.vaadin.data.util.converter.Converter#getTargetType()
*/
- public Class getTargetType() {
- return realConverter.getSourceType();
+ public Class getPresentationType() {
+ return realConverter.getModelType();
}
}
diff --git a/src/com/vaadin/ui/AbstractField.java b/src/com/vaadin/ui/AbstractField.java
index d6ce545096..9e4bdde064 100644
--- a/src/com/vaadin/ui/AbstractField.java
+++ b/src/com/vaadin/ui/AbstractField.java
@@ -726,7 +726,7 @@ public abstract class AbstractField extends AbstractComponent implements
// Check if the current converter is compatible.
if (newDataSource != null
- && (getConverter() == null || !getConverter().getSourceType()
+ && (getConverter() == null || !getConverter().getModelType()
.isAssignableFrom(newDataSource.getType()))) {
// Set a new converter if there is a new data source and the
// there is no old converter or the old is incompatible.
@@ -813,7 +813,7 @@ public abstract class AbstractField extends AbstractComponent implements
private T convertFromDataSource(Object newValue)
throws Converter.ConversionException {
if (converter != null) {
- return converter.convertFromSourceToTarget(newValue, getLocale());
+ return converter.convertToPresentation(newValue, getLocale());
}
if (newValue == null) {
return null;
@@ -850,11 +850,11 @@ public abstract class AbstractField extends AbstractComponent implements
* an exception.
*/
try {
- return converter.convertFromTargetToSource(fieldValue,
+ return converter.convertToModel(fieldValue,
getLocale());
} catch (com.vaadin.data.util.converter.Converter.ConversionException e) {
throw new Converter.ConversionException(
- getValueConversionError(converter.getSourceType()), e);
+ getValueConversionError(converter.getModelType()), e);
}
}
@@ -1030,11 +1030,11 @@ public abstract class AbstractField extends AbstractComponent implements
// to validate the converted value
if (getConverter() != null) {
try {
- valueToValidate = getConverter().convertFromTargetToSource(
+ valueToValidate = getConverter().convertToModel(
fieldValue, getLocale());
} catch (Exception e) {
throw new InvalidValueException(
- getValueConversionError(getConverter().getSourceType()));
+ getValueConversionError(getConverter().getModelType()));
}
}
diff --git a/src/com/vaadin/ui/Table.java b/src/com/vaadin/ui/Table.java
index fabb632494..5ab0fb9029 100644
--- a/src/com/vaadin/ui/Table.java
+++ b/src/com/vaadin/ui/Table.java
@@ -3476,7 +3476,7 @@ public class Table extends AbstractSelect implements Action.Container,
}
Object value = property.getValue();
if (converter != null) {
- return converter.convertFromSourceToTarget(value, getLocale());
+ return converter.convertToPresentation(value, getLocale());
}
return (null != value) ? value.toString() : "";
}
@@ -5131,7 +5131,18 @@ public class Table extends AbstractSelect implements Action.Container,
return rowGenerator;
}
- // FIXME: Javadoc
+ /**
+ * Sets a converter for a property id.
+ *
+ * The converter is used to format the the data for the given property id
+ * before displaying it in the table.
+ *
+ *
+ * @param propertyId
+ * The propertyId to format using the converter
+ * @param converter
+ * The converter to use for the property id
+ */
public void setConverter(Object propertyId, Converter, String> converter) {
if (!getContainerPropertyIds().contains(propertyId)) {
throw new IllegalArgumentException("PropertyId " + propertyId
@@ -5151,12 +5162,26 @@ public class Table extends AbstractSelect implements Action.Container,
refreshRowCache();
}
- // FIXME: Javadoc
+ /**
+ * Checks if there is a converter set explicitly for the given property id.
+ *
+ * @param propertyId
+ * The propertyId to check
+ * @return true if a converter has been set for the property id, false
+ * otherwise
+ */
protected boolean hasConverter(Object propertyId) {
return propertyValueConverters.containsKey(propertyId);
}
- // FIXME: Javadoc
+ /**
+ * Returns the converter used to format the given propertyId.
+ *
+ * @param propertyId
+ * The propertyId to check
+ * @return The converter used to format the propertyId or null if no
+ * converter has been set
+ */
public Converter