public class UiBinding extends Object
The binding framework can implicitly bind UI elements to properties, this allow seamless
model to UI mapping. Most cases allow simple binding by just using the
#bind(com.codename1.properties.Property, com.codename1.ui.Component)
method
to seamlessly update a property/component based on changes.
It contains the following base concepts:
UiBinding.ObjectConverter
- a converter converts
from one type to another. E.g. if we want a TextArea
to map
to an Integer
property we'd use an
UiBinding.IntegerConverter
to indicate the desired
destination value.
UiBinding.ComponentAdapter
- takes two
UiBinding.ObjectConverter
to convert to/from the
component & property. It provides the API for event binding and value extraction/setting
on the component.
UiBinding.Binding
- the commit mode
Modifier and Type | Class and Description |
---|---|
class |
UiBinding.Binding
Binding allows us to have commit/auto-commit mode.
|
static class |
UiBinding.BooleanConverter
Converts the source value to a Boolean
|
static class |
UiBinding.BoundTableModel
Implements table model binding, this is implemented as a class to allow
additional features such as adding/removing rows
|
static class |
UiBinding.CheckBoxRadioSelectionAdapter<PropertyType>
Adapts a
CheckBox or
RadioButton to binding |
static class |
UiBinding.ComponentAdapter<PropertyType,ComponentType>
Adapters can be extended to allow any component to bind to a property via a converter
|
static class |
UiBinding.DateConverter
Converts the source value to a Date
|
static class |
UiBinding.DoubleConverter
Converts the source value to a Double
|
static class |
UiBinding.FloatConverter
Converts the source value to a Float
|
static class |
UiBinding.IntegerConverter
Converts the source value to an Integer
|
static class |
UiBinding.LongConverter
Converts the source value to a Long
|
static class |
UiBinding.MappingConverter
Maps values to other values for conversion in a similar way to a Map this is pretty
useful for API's like picker where we have a list of Strings and we might want a list
of other objects to match every string
|
static class |
UiBinding.ObjectConverter
Object converter can convert an object from one type to another e.g.
|
static class |
UiBinding.PickerAdapter<PropertyType>
Adapts a
Picker to binding |
static class |
UiBinding.RadioListAdapter<PropertyType>
Adapts a set of
RadioButton to a selection within a list of values |
static class |
UiBinding.StringConverter
Converts the source value to a String
|
static class |
UiBinding.TextAreaAdapter<PropertyType>
|
static class |
UiBinding.TextComponentAdapter<PropertyType>
Adapts a
TextComponent to binding |
Constructor and Description |
---|
UiBinding() |
Modifier and Type | Method and Description |
---|---|
UiBinding.Binding |
bind(PropertyBase prop,
Component cmp)
Binds the given property to the component using default adapters
|
UiBinding.Binding |
bind(PropertyBase prop,
Component cmp,
UiBinding.ComponentAdapter adapt)
Binds the given property to the component using a custom adapter class
|
UiBinding.Binding |
bind(PropertyBusinessObject obj,
Container cnt)
Binds a hierarchy of Components to a business object by searching the tree and collecting
the bindings.
|
UiBinding.Binding |
bindGroup(PropertyBase prop,
Object[] values,
Component... cmps)
Binds the given property to the selected value from the set based on the multiple components.
|
void |
bindInteger(Property<Integer,? extends Object> prop,
TextArea ta)
Deprecated.
this code was experimental we will use the more generic Adapter/bind framework
|
void |
bindString(Property<String,? extends Object> prop,
TextArea ta)
Deprecated.
this code was experimental we will use the more generic Adapter/bind framework
|
UiBinding.BoundTableModel |
createTableModel(CollectionProperty<? extends PropertyBusinessObject,? extends Object> objects,
PropertyBusinessObject prototype)
Creates a table model which is implicitly bound to the properties
|
UiBinding.BoundTableModel |
createTableModel(List<? extends PropertyBusinessObject> objects,
PropertyBusinessObject prototype)
Creates a table model which is implicitly bound to the properties
|
boolean |
isAutoCommit()
Is auto-commit mode on by default see
setAutoCommit(boolean) |
void |
setAutoCommit(boolean b)
Default value for auto-commit mode, in auto-commit mode changes to the component/property
are instantly reflected otherwise
com.codename1.properties.UiBinding.CommitMode#commit()
should be invoked explicitly |
static void |
unbind(PropertyBase prop)
Allows us to unbind the property from binding, this is equivalent to calling
UiBinding.Binding.disconnect() on all
bindings... |
static void |
unbind(PropertyBusinessObject po)
Unbinds all the properties within the business object
|
public void setAutoCommit(boolean b)
com.codename1.properties.UiBinding.CommitMode#commit()
should be invoked explicitlyb
- true to enable auto commit modepublic boolean isAutoCommit()
setAutoCommit(boolean)
public static void unbind(PropertyBase prop)
UiBinding.Binding.disconnect()
on all
bindings...prop
- the propertypublic static void unbind(PropertyBusinessObject po)
po
- the business objectpublic UiBinding.Binding bind(PropertyBusinessObject obj, Container cnt)
obj
- the business object with the properties to bindcnt
- a container that will be recursed for bindingpublic UiBinding.Binding bindGroup(PropertyBase prop, Object[] values, Component... cmps)
prop
- the propertyvalues
- the values that can be usedcmps
- the componentspublic UiBinding.Binding bind(PropertyBase prop, Component cmp)
prop
- the propertycmp
- the componentpublic UiBinding.Binding bind(PropertyBase prop, Component cmp, UiBinding.ComponentAdapter adapt)
prop
- the propertycmp
- the componentadapt
- an implementation of UiBinding.ComponentAdapter
that allows us to define the way the component maps to/from the propertypublic UiBinding.BoundTableModel createTableModel(List<? extends PropertyBusinessObject> objects, PropertyBusinessObject prototype)
objects
- list of business objectsprototype
- the type by which we determine the structure of the tableTable
classpublic UiBinding.BoundTableModel createTableModel(CollectionProperty<? extends PropertyBusinessObject,? extends Object> objects, PropertyBusinessObject prototype)
objects
- list of business objectsprototype
- the type by which we determine the structure of the tableTable
classpublic void bindString(Property<String,? extends Object> prop, TextArea ta)
prop
- the property valueta
- the text areapublic void bindInteger(Property<Integer,? extends Object> prop, TextArea ta)
prop
- the property valueta
- the text area