diff options
author | Artur Signell <artur@vaadin.com> | 2012-06-19 16:22:13 +0300 |
---|---|---|
committer | Artur Signell <artur@vaadin.com> | 2012-06-21 17:11:27 +0300 |
commit | d69a0bf1682a42eeff3342e34754d0179b119a6b (patch) | |
tree | 2c0dee1c75b1bfeac2ca57d3ecb44794f68029fd /src | |
parent | d627ad58d2d11a09947a8eac4cd12b72c3d02669 (diff) | |
download | vaadin-framework-d69a0bf1682a42eeff3342e34754d0179b119a6b.tar.gz vaadin-framework-d69a0bf1682a42eeff3342e34754d0179b119a6b.zip |
Get converter from the application of the component if available (#8992)
Diffstat (limited to 'src')
-rw-r--r-- | src/com/vaadin/data/util/converter/ConverterUtil.java | 37 | ||||
-rw-r--r-- | src/com/vaadin/ui/AbstractField.java | 2 | ||||
-rw-r--r-- | src/com/vaadin/ui/Label.java | 2 | ||||
-rw-r--r-- | src/com/vaadin/ui/Table.java | 10 |
4 files changed, 35 insertions, 16 deletions
diff --git a/src/com/vaadin/data/util/converter/ConverterUtil.java b/src/com/vaadin/data/util/converter/ConverterUtil.java index 5fe3101db2..239baf6b6d 100644 --- a/src/com/vaadin/data/util/converter/ConverterUtil.java +++ b/src/com/vaadin/data/util/converter/ConverterUtil.java @@ -10,14 +10,37 @@ import com.vaadin.Application; public class ConverterUtil implements Serializable { - public static <UITYPE, MODELTYPE> Converter<UITYPE, MODELTYPE> getConverter( - Class<UITYPE> uiType, Class<MODELTYPE> modelType) { - Converter<UITYPE, MODELTYPE> converter = null; + /** + * Finds a converter that can convert from the given presentation type to + * the given model type and back. Uses the given application to find a + * {@link ConverterFactory} or, if application is null, uses the + * {@link Application#getCurrentApplication()}. + * + * @param <PRESENTATIONTYPE> + * The presentation type + * @param <MODELTYPE> + * The model type + * @param presentationType + * The presentation type + * @param modelType + * The model type + * @param application + * The application to use to find a ConverterFactory or null to + * use the current application + * @return A Converter capable of converting between the given types or null + * if no converter was found + */ + public static <PRESENTATIONTYPE, MODELTYPE> Converter<PRESENTATIONTYPE, MODELTYPE> getConverter( + Class<PRESENTATIONTYPE> presentationType, + Class<MODELTYPE> modelType, Application application) { + Converter<PRESENTATIONTYPE, MODELTYPE> converter = null; + if (application == null) { + application = Application.getCurrentApplication(); + } - Application app = Application.getCurrentApplication(); - if (app != null) { - ConverterFactory factory = app.getConverterFactory(); - converter = factory.createConverter(uiType, modelType); + if (application != null) { + ConverterFactory factory = application.getConverterFactory(); + converter = factory.createConverter(presentationType, modelType); } return converter; diff --git a/src/com/vaadin/ui/AbstractField.java b/src/com/vaadin/ui/AbstractField.java index b74dba6d65..21ca01f592 100644 --- a/src/com/vaadin/ui/AbstractField.java +++ b/src/com/vaadin/ui/AbstractField.java @@ -761,7 +761,7 @@ public abstract class AbstractField<T> extends AbstractComponent implements */ public void setConverter(Class<?> datamodelType) { Converter<T, ?> c = (Converter<T, ?>) ConverterUtil.getConverter( - getType(), datamodelType); + getType(), datamodelType, getApplication()); setConverter(c); } diff --git a/src/com/vaadin/ui/Label.java b/src/com/vaadin/ui/Label.java index 12e1f9590e..e1c64605d7 100644 --- a/src/com/vaadin/ui/Label.java +++ b/src/com/vaadin/ui/Label.java @@ -228,7 +228,7 @@ public class Label extends AbstractComponent implements Property<String>, newDataSource.getType())) { // Try to find a converter Converter<String, ?> c = ConverterUtil.getConverter(String.class, - newDataSource.getType()); + newDataSource.getType(), getApplication()); setConverter(c); } dataSource = newDataSource; diff --git a/src/com/vaadin/ui/Table.java b/src/com/vaadin/ui/Table.java index 5d4f919704..b74de7e180 100644 --- a/src/com/vaadin/ui/Table.java +++ b/src/com/vaadin/ui/Table.java @@ -21,13 +21,13 @@ import java.util.StringTokenizer; import java.util.logging.Level; import java.util.logging.Logger; -import com.vaadin.Application; import com.vaadin.data.Container; import com.vaadin.data.Item; import com.vaadin.data.Property; import com.vaadin.data.util.ContainerOrderedWrapper; import com.vaadin.data.util.IndexedContainer; import com.vaadin.data.util.converter.Converter; +import com.vaadin.data.util.converter.ConverterUtil; import com.vaadin.event.Action; import com.vaadin.event.Action.Handler; import com.vaadin.event.DataBoundTransferable; @@ -3664,12 +3664,8 @@ public class Table extends AbstractSelect implements Action.Container, if (hasConverter(colId)) { converter = getConverter(colId); } else { - Application app = Application.getCurrentApplication(); - if (app != null) { - converter = (Converter<String, Object>) app - .getConverterFactory().createConverter(String.class, - property.getType()); - } + ConverterUtil.getConverter(String.class, property.getType(), + getApplication()); } Object value = property.getValue(); if (converter != null) { |