]> source.dussan.org Git - vaadin-framework.git/commitdiff
#8102 Removed "value" from value converter used in AbstractField and
authorArtur Signell <artur@vaadin.com>
Wed, 21 Dec 2011 16:50:31 +0000 (18:50 +0200)
committerArtur Signell <artur@vaadin.com>
Wed, 21 Dec 2011 16:50:31 +0000 (18:50 +0200)
renamed updateValueConverterFromFactory to setConverter based on API
review meeting.

src/com/vaadin/Application.java
src/com/vaadin/ui/AbstractField.java
tests/server-side/com/vaadin/tests/server/component/abstractfield/AbstractFieldValueConversions.java
tests/testbench/com/vaadin/tests/components/abstractfield/DoubleInTextField.java
tests/testbench/com/vaadin/tests/components/abstractfield/IntegerFieldWithoutDataSource.java
tests/testbench/com/vaadin/tests/fieldbinder/BasicPersonForm.java

index cc54ca97cf24486fb2b146c91f3b7055229787a8..2ccc7e63b558620f409b416b260369dbb139f3c8 100644 (file)
@@ -53,6 +53,7 @@ import com.vaadin.terminal.gwt.server.WebApplicationContext;
 import com.vaadin.ui.AbstractComponent;
 import com.vaadin.ui.AbstractField;
 import com.vaadin.ui.Root;
+import com.vaadin.ui.Table;
 import com.vaadin.ui.Window;
 
 /**
@@ -1226,7 +1227,9 @@ public class Application implements Terminal.ErrorListener, Serializable {
      * </p>
      * <p>
      * The {@link Converter} for an individual field can be overridden using
-     * {@link AbstractField#setValueConverter(Converter)}.
+     * {@link AbstractField#setConverter(Converter)} and for invidual property
+     * ids in a {@link Table} using
+     * {@link Table#setConverter(Object, Converter)}.
      * </p>
      * <p>
      * The converter factory must never be set to null.
index e98a06f91cc730ed94aec964b9e89f079329e802..5a8b9037e0138fb88c6c7fa3b4dfa40f2e685855 100644 (file)
@@ -72,7 +72,7 @@ public abstract class AbstractField<T> extends AbstractComponent implements
      * A converter used to convert from the data model type to the field type
      * and vice versa.
      */
-    private Converter<Object, T> valueConverter = null;
+    private Converter<Object, T> converter = null;
     /**
      * Connected data-source.
      */
@@ -138,7 +138,7 @@ public abstract class AbstractField<T> extends AbstractComponent implements
     /**
      * The error message that is shown when the field value cannot be converted.
      */
-    private String valueConversionError = "Could not convert value to {0}";
+    private String conversionError = "Could not convert value to {0}";
 
     /**
      * Is automatic validation enabled.
@@ -538,7 +538,7 @@ public abstract class AbstractField<T> extends AbstractComponent implements
      * 
      * <p>
      * Since Vaadin 7.0, no implicit conversions between other data types and
-     * String are performed, but a value converter is used if set.
+     * String are performed, but a converter is used if set.
      * </p>
      * 
      * @return the current value of the field.
@@ -590,7 +590,7 @@ public abstract class AbstractField<T> extends AbstractComponent implements
             // Repaint is needed even when the client thinks that it knows the
             // new state if validity of the component may change
             if (repaintIsNotNeeded
-                    && (isRequired() || getValidators() != null || getValueConverter() != null)) {
+                    && (isRequired() || getValidators() != null || getConverter() != null)) {
                 repaintIsNotNeeded = false;
             }
 
@@ -724,12 +724,11 @@ public abstract class AbstractField<T> extends AbstractComponent implements
 
         // Check if the current converter is compatible.
         if (newDataSource != null
-                && (getValueConverter() == null || !getValueConverter()
-                        .getSourceType().isAssignableFrom(
-                                newDataSource.getType()))) {
-            // Set a new value converter if there is a new data source and the
+                && (getConverter() == null || !getConverter().getSourceType()
+                        .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.
-            updateValueConverterFromFactory(newDataSource.getType());
+            setConverter(newDataSource.getType());
         }
         // Gets the value from source
         try {
@@ -777,15 +776,15 @@ public abstract class AbstractField<T> extends AbstractComponent implements
     }
 
     /**
-     * Retrieves a value converter for the field from the converter factory
-     * defined for the application. Clears the value converter if no application
-     * reference is available or if the factory returns null.
+     * Retrieves a converter for the field from the converter factory defined
+     * for the application. Clears the converter if no application reference is
+     * available or if the factory returns null.
      * 
      * @param datamodelType
      *            The type of the data model that we want to be able to convert
      *            from
      */
-    public void updateValueConverterFromFactory(Class<?> datamodelType) {
+    public void setConverter(Class<?> datamodelType) {
         Converter<?, T> converter = null;
 
         Application app = Application.getCurrentApplication();
@@ -794,7 +793,7 @@ public abstract class AbstractField<T> extends AbstractComponent implements
             converter = (Converter<?, T>) factory.createConverter(
                     datamodelType, getType());
         }
-        setValueConverter(converter);
+        setConverter(converter);
     }
 
     /**
@@ -803,8 +802,7 @@ public abstract class AbstractField<T> extends AbstractComponent implements
      * @param newValue
      *            The data source value to convert.
      * @return The converted value that is compatible with the UI type or the
-     *         original value if its type is compatible and no value converter
-     *         is set.
+     *         original value if its type is compatible and no converter is set.
      * @throws Converter.ConversionException
      *             if there is no converter and the type is not compatible with
      *             the data source type.
@@ -812,9 +810,8 @@ public abstract class AbstractField<T> extends AbstractComponent implements
     @SuppressWarnings("unchecked")
     private T convertFromDataSource(Object newValue)
             throws Converter.ConversionException {
-        if (valueConverter != null) {
-            return valueConverter.convertFromSourceToTarget(newValue,
-                    getLocale());
+        if (converter != null) {
+            return converter.convertFromSourceToTarget(newValue, getLocale());
         }
         if (newValue == null) {
             return null;
@@ -828,7 +825,7 @@ public abstract class AbstractField<T> extends AbstractComponent implements
                             + newValue.getClass().getName()
                             + " to "
                             + getType()
-                            + ". No value converter is set and the types are not compatible.");
+                            + ". No converter is set and the types are not compatible.");
         }
     }
 
@@ -845,18 +842,17 @@ public abstract class AbstractField<T> extends AbstractComponent implements
      */
     private Object convertToDataSource(T fieldValue)
             throws Converter.ConversionException {
-        if (valueConverter != null) {
+        if (converter != null) {
             /*
-             * If there is a value converter, always use it. It must convert or
-             * throw an exception.
+             * If there is a converter, always use it. It must convert or throw
+             * an exception.
              */
             try {
-                return valueConverter.convertFromTargetToSource(fieldValue,
+                return converter.convertFromTargetToSource(fieldValue,
                         getLocale());
             } catch (com.vaadin.data.util.converter.Converter.ConversionException e) {
                 throw new Converter.ConversionException(
-                        getValueConversionError(valueConverter.getSourceType()),
-                        e);
+                        getValueConversionError(converter.getSourceType()), e);
             }
         }
 
@@ -893,9 +889,9 @@ public abstract class AbstractField<T> extends AbstractComponent implements
      */
     protected String getValueConversionError(Class<?> dataSourceType) {
         if (dataSourceType == null) {
-            return getValueConversionError();
+            return getConversionError();
         } else {
-            return getValueConversionError().replace("{0}",
+            return getConversionError().replace("{0}",
                     dataSourceType.getSimpleName());
         }
     }
@@ -980,7 +976,7 @@ public abstract class AbstractField<T> extends AbstractComponent implements
      * A field is invalid if it is set as required (using
      * {@link #setRequired(boolean)} and is empty, if one or several of the
      * validators added to the field indicate it is invalid or if the value
-     * cannot be converted provided a value converter has been set.
+     * cannot be converted provided a converter has been set.
      * 
      * The "required" validation is a built-in validation feature. If the field
      * is required and empty this method throws an EmptyValueException with the
@@ -1013,14 +1009,13 @@ public abstract class AbstractField<T> extends AbstractComponent implements
 
         // If there is a converter we start by converting the value as we want
         // to validate the converted value
-        if (getValueConverter() != null) {
+        if (getConverter() != null) {
             try {
-                valueToValidate = getValueConverter()
-                        .convertFromTargetToSource(fieldValue, getLocale());
+                valueToValidate = getConverter().convertFromTargetToSource(
+                        fieldValue, getLocale());
             } catch (Exception e) {
                 throw new InvalidValueException(
-                        getValueConversionError(getValueConverter()
-                                .getSourceType()));
+                        getValueConversionError(getConverter().getSourceType()));
             }
         }
 
@@ -1429,8 +1424,8 @@ public abstract class AbstractField<T> extends AbstractComponent implements
      * 
      * @return The error that is shown if conversion of the field value fails
      */
-    public String getValueConversionError() {
-        return valueConversionError;
+    public String getConversionError() {
+        return conversionError;
     }
 
     /**
@@ -1441,8 +1436,8 @@ public abstract class AbstractField<T> extends AbstractComponent implements
      * @param valueConversionError
      *            Message to be shown when conversion of the value fails
      */
-    public void setValueConversionError(String valueConversionError) {
-        this.valueConversionError = valueConversionError;
+    public void setConversionError(String valueConversionError) {
+        this.conversionError = valueConversionError;
         requestRepaint();
     }
 
@@ -1572,8 +1567,8 @@ public abstract class AbstractField<T> extends AbstractComponent implements
      * 
      * @return The converter or null if none is set.
      */
-    public Converter<Object, T> getValueConverter() {
-        return valueConverter;
+    public Converter<Object, T> getConverter() {
+        return converter;
     }
 
     /**
@@ -1584,12 +1579,11 @@ public abstract class AbstractField<T> extends AbstractComponent implements
      * The source for the converter is the data model and the target is the
      * field.
      * 
-     * @param valueConverter
-     *            The new value converter to use.
+     * @param converter
+     *            The new converter to use.
      */
-    public void setValueConverter(Converter<?, T> valueConverter) {
-        //
-        this.valueConverter = (Converter<Object, T>) valueConverter;
+    public void setConverter(Converter<?, T> converter) {
+        this.converter = (Converter<Object, T>) converter;
         requestRepaint();
     }
 
index 0bc40097d27bb909c27c55a78e0610478b47f2a1..f39b479943a6e6e16a934be201d2e53a6fd9a404 100644 (file)
@@ -34,7 +34,7 @@ public class AbstractFieldValueConversions extends TestCase {
 \r
     public void testStringIdentityConversion() {\r
         TextField tf = new TextField();\r
-        tf.setValueConverter(new Converter<String, String>() {\r
+        tf.setConverter(new Converter<String, String>() {\r
 \r
             public String convertFromTargetToSource(String value, Locale locale) {\r
                 return value;\r
@@ -64,7 +64,7 @@ public class AbstractFieldValueConversions extends TestCase {
 \r
     public void testFailingConversion() {\r
         TextField tf = new TextField();\r
-        tf.setValueConverter(new Converter<Integer, String>() {\r
+        tf.setConverter(new Converter<Integer, String>() {\r
 \r
             public Integer convertFromTargetToSource(String value, Locale locale) {\r
                 throw new ConversionException("Failed");\r
@@ -95,7 +95,7 @@ public class AbstractFieldValueConversions extends TestCase {
     public void testIntegerStringConversion() {\r
         TextField tf = new TextField();\r
 \r
-        tf.setValueConverter(new IntegerToStringConverter());\r
+        tf.setConverter(new IntegerToStringConverter());\r
         tf.setPropertyDataSource(new MethodProperty<Integer>(paulaBean, "age"));\r
         assertEquals(34, tf.getPropertyDataSource().getValue());\r
         assertEquals("34", tf.getValue());\r
@@ -109,7 +109,7 @@ public class AbstractFieldValueConversions extends TestCase {
 \r
     public void testBooleanNullConversion() {\r
         CheckBox cb = new CheckBox();\r
-        cb.setValueConverter(new Converter<Boolean, Boolean>() {\r
+        cb.setConverter(new Converter<Boolean, Boolean>() {\r
 \r
             public Boolean convertFromTargetToSource(Boolean value,\r
                     Locale locale) {\r
@@ -143,7 +143,7 @@ public class AbstractFieldValueConversions extends TestCase {
         cb.setPropertyDataSource(property);\r
         assertEquals(Boolean.FALSE, property.getValue());\r
         assertEquals(Boolean.FALSE, cb.getValue());\r
-        Boolean newDmValue = cb.getValueConverter().convertFromSourceToTarget(\r
+        Boolean newDmValue = cb.getConverter().convertFromSourceToTarget(\r
                 cb.getValue(), new Locale("fi", "FI"));\r
         assertEquals(Boolean.FALSE, newDmValue);\r
 \r
index e74513b9ac3c5b5999d6076f927eb4d194ca9997..b7077dba802d0146205d079bd46dad6d8a618efb 100644 (file)
@@ -24,7 +24,7 @@ public class DoubleInTextField extends AbstractComponentDataBindingTest {
         addComponent(salary6);\r
         salary6.setPropertyDataSource(new MethodProperty<Double>(person,\r
                 "salaryDouble"));\r
-        salary6.setValueConverter(new Vaadin6ImplicitDoubleConverter());\r
+        salary6.setConverter(new Vaadin6ImplicitDoubleConverter());\r
 \r
     }\r
 \r
index e9c555ab17d6bc9d1fc86d2533bfa0bb21c25356..8745df991a6674b4aac203dedc3ab6921a5cf28e 100644 (file)
@@ -26,7 +26,7 @@ public class IntegerFieldWithoutDataSource extends TestBase {
 \r
     private TextField createIntegerTextField() {\r
         final TextField tf = new TextField("Enter an integer");\r
-        tf.updateValueConverterFromFactory(Integer.class);\r
+        tf.setConverter(Integer.class);\r
         tf.setImmediate(true);\r
         tf.addListener(new ValueChangeListener() {\r
 \r
index 0bbf487c829be4e1a718c95ef68d4919d66b67b7..1e7d90ec187f094615a2f6e97b13237bf83be1b3 100644 (file)
@@ -160,7 +160,7 @@ public class BasicPersonForm extends TestBase {
         age.addValidator(new IntegerRangeValidator(\r
                 "Must be between 0 and 150, {0} is not", 0, 150));\r
         sex.setPageLength(0);\r
-        deceased.setValueConverter(new BooleanToStringConverter() {\r
+        deceased.setConverter(new BooleanToStringConverter() {\r
             @Override\r
             protected String getTrueString() {\r
                 return "YAY!";\r