Errai 3.0.1-SNAPSHOT

org.jboss.errai.databinding.client.api
Class Convert

java.lang.Object
  extended by org.jboss.errai.databinding.client.api.Convert

public class Convert
extends Object

Type conversion utility used by the generated Bindable proxies.

Author:
Christian Sadilek

Constructor Summary
Convert()
           
 
Method Summary
static void deregisterDefaultConverters()
          Deletes all registrations of default converters.
static
<M,W> void
registerDefaultConverter(Class<M> modelValueType, Class<W> widgetValueType, Converter<M,W> converter)
          Registers a Converter as a default for the provided model and widget types.
static Object to(Class<?> toType, Object o)
          Converts the provided object to the provided type.
static
<M,W> M
toModelValue(Class<M> modelValueType, Class<W> widgetValueType, W widgetValue, Converter<M,W> converter)
          Converts the provided object to a model value.
static
<M,W> M
toModelValue(Class<M> modelValueType, com.google.gwt.user.client.ui.Widget widget, W widgetValue, Converter<M,W> converter)
          Converts the provided object to a model value.
static
<M,W> W
toWidgetValue(Class<W> widgetValueType, Class<M> modelValueType, M modelValue, Converter<M,W> converter)
          Converts the provided object to a widget value.
static
<M,W> W
toWidgetValue(com.google.gwt.user.client.ui.Widget widget, Class<M> modelValueType, M modelValue, Converter<M,W> converter)
          Converts the provided object to a widget value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Convert

public Convert()
Method Detail

to

public static Object to(Class<?> toType,
                        Object o)
Converts the provided object to the provided type.

This method is used in case no Converter has been specified for the binding (see DataBinder.bind(Widget, String, Converter)) and no default converter has been registered for the corresponding types (see registerDefaultConverter(Class, Class, Converter)).

Parameters:
toType - The type to convert to, must not be null.
o - The object to convert. Null allowed. If toType is String.class, null values will be represented as empty Strings.
Returns:
the converted object

toWidgetValue

public static <M,W> W toWidgetValue(com.google.gwt.user.client.ui.Widget widget,
                                    Class<M> modelValueType,
                                    M modelValue,
                                    Converter<M,W> converter)
Converts the provided object to a widget value.

Type Parameters:
M - The type of the model value (field type of the model)
W - The type of the widget value (e.g. String for a TextBox (=HasValue<String>) or Boolean for a Checkbox (=HasValue<Boolean>)))
Parameters:
widget - The widget holding the value, used to determine the value type. Must not be null.
modelValueType - The model type, used to lookup global default converters. Must not be null.
modelValue - The value to convert.
converter - The converter to use, null if default conversion should be used.
Returns:
the converted object

toWidgetValue

public static <M,W> W toWidgetValue(Class<W> widgetValueType,
                                    Class<M> modelValueType,
                                    M modelValue,
                                    Converter<M,W> converter)
Converts the provided object to a widget value.

Type Parameters:
M - The type of the model value (field type of the model)
W - The type of the widget value (e.g. String for a TextBox (=HasValue<String>) or Boolean for a Checkbox (=HasValue<Boolean>)))
Parameters:
widgetValueType - The type to convert to. Must not be null.
modelValueType - The model type, used to lookup global default converters. Must not be null.
modelValue - The value to convert.
converter - The converter to use, null if default conversion should be used.
Returns:
the converted object

toModelValue

public static <M,W> M toModelValue(Class<M> modelValueType,
                                   com.google.gwt.user.client.ui.Widget widget,
                                   W widgetValue,
                                   Converter<M,W> converter)
Converts the provided object to a model value.

Type Parameters:
M - The type of the model value (field type of the model)
W - The type of the widget value (e.g. String for a TextBox (=HasValue<String>) or Boolean for a Checkbox (=HasValue<Boolean>)))
Parameters:
modelValueType - The type to convert to. Must not be null.
widget - The widget holding the value, used to determine the value type. Must not be null.
widgetValue - The value to convert.
converter - The converter to use, null if default conversion should be used.
Returns:
the converted object

toModelValue

public static <M,W> M toModelValue(Class<M> modelValueType,
                                   Class<W> widgetValueType,
                                   W widgetValue,
                                   Converter<M,W> converter)
Converts the provided object to a model value.

Type Parameters:
M - The type of the model value (field type of the model)
W - The type of the widget value (e.g. String for a TextBox (=HasValue<String>) or Boolean for a Checkbox (=HasValue<Boolean>)))
Parameters:
modelValueType - The type to convert to. Must not be null.
widgetValueType - The widget type, use to lookup global default converters. Must not be null.
widgetValue - The value to convert.
converter - The converter to use, null if default conversion should be used.
Returns:
the converted object

registerDefaultConverter

public static <M,W> void registerDefaultConverter(Class<M> modelValueType,
                                                  Class<W> widgetValueType,
                                                  Converter<M,W> converter)
Registers a Converter as a default for the provided model and widget types. The default converter will be used in case no custom converter is provided when binding a model to a widget.

Type Parameters:
M - The type of the model value (field type of the model)
W - The type of the widget value (e.g. String for a TextBox (=HasValue<String>) or Boolean for a Checkbox (=HasValue<Boolean>)))
Parameters:
modelValueType - The model type the provided converter converts to, must not be null.
widgetValueType - The widget type the provided converter converts to, must not be null.
converter - The converter to register as a default for the provided model and widget types.

deregisterDefaultConverters

public static void deregisterDefaultConverters()
Deletes all registrations of default converters.


Errai 3.0.1-SNAPSHOT

Copyright © 2013-2014 JBoss, a division of Red Hat. All Rights Reserved.