From: Artur Signell Date: Tue, 19 Jun 2012 13:22:13 +0000 (+0300) Subject: Get converter from the application of the component if available (#8992) X-Git-Tag: 7.0.0.alpha3~84 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=d69a0bf1682a42eeff3342e34754d0179b119a6b;p=vaadin-framework.git Get converter from the application of the component if available (#8992) --- 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 Converter getConverter( - Class uiType, Class modelType) { - Converter 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 + * The presentation type + * @param + * 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 Converter getConverter( + Class presentationType, + Class modelType, Application application) { + Converter 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 extends AbstractComponent implements */ public void setConverter(Class datamodelType) { Converter c = (Converter) 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, newDataSource.getType())) { // Try to find a converter Converter 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) app - .getConverterFactory().createConverter(String.class, - property.getType()); - } + ConverterUtil.getConverter(String.class, property.getType(), + getApplication()); } Object value = property.getValue(); if (converter != null) {