Class DataBindingContext
- java.lang.Object
-
- org.eclipse.core.databinding.DataBindingContext
-
public class DataBindingContext extends Object
A DataBindingContext is the point of contact for the creation and management ofbindings
, and aggregates validation statuses of its bindings, or more generally, its validation status providers.A DataBindingContext provides the following abilities:
- Ability to create bindings between
observable values
. - Ability to create bindings between
observable lists
. - Access to the bindings created by the instance.
- Access to the list of validation status providers (this includes all bindings).
Multiple contexts can be used at any point in time. One strategy for the management of contexts is the aggregation of validation statuses. For example an
IWizardPage
could use a single context and the statuses could be aggregated to set the page status and fulfillment. Each page in theIWizard
would have its own context instance.Default converters
If the model and target types do not match and no converter is set on the update strategy object then an attempt is made to find a default converter between them.
IObservableValue.getValueType()
orIObservableCollection.getElementType()
is used for this.There are default converters available between the following types:
- Strings to/from numeric types, including
BigInteger
andBigDecimal
. - String to/from boolean, using constant names provided the internal messages file.
- String to/from
Date
, using the pattern in the internal messages file. IStatus
to string, using the status message.Object
to string, usingObject.toString()
.
More default converters might be added in a future version. This might cause the types that now use the object-to-string converter to instead use a more specific converter.
The internal messages file is located at
org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/messages.properties
.- Since:
- 1.0
- Ability to create bindings between
-
-
Constructor Summary
Constructors Constructor Description DataBindingContext()
Creates a data binding context, using the current default realm for the validation observables.DataBindingContext(Realm validationRealm)
Creates a data binding context using the given realm for the validation observables.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addBinding(Binding binding)
Adds the given binding to this data binding context.void
addValidationStatusProvider(ValidationStatusProvider validationStatusProvider)
Adds the given validation status provider to this data binding context.<T,M>
BindingbindList(IObservableList<T> targetObservableList, IObservableList<M> modelObservableList)
Creates aBinding
to synchronize the values of twoobservable lists
.<T,M>
BindingbindList(IObservableList<T> targetObservableList, IObservableList<M> modelObservableList, UpdateListStrategy<? super T,? extends M> targetToModel, UpdateListStrategy<? super M,? extends T> modelToTarget)
Creates aBinding
to synchronize the values of twoobservable lists
.<T,M>
BindingbindSet(IObservableSet<T> targetObservableSet, IObservableSet<M> modelObservableSet)
Creates aBinding
to synchronize the values of twoobservable sets
.<T,M>
BindingbindSet(IObservableSet<T> targetObservableSet, IObservableSet<M> modelObservableSet, UpdateSetStrategy<? super T,? extends M> targetToModel, UpdateSetStrategy<? super M,? extends T> modelToTarget)
Creates aBinding
to synchronize the values of twoobservable sets
.<T,M>
BindingbindValue(IObservableValue<T> targetObservableValue, IObservableValue<M> modelObservableValue)
Creates aBinding
to synchronize the values of twoobservable values
.<T,M>
BindingbindValue(IObservableValue<T> targetObservableValue, IObservableValue<M> modelObservableValue, UpdateValueStrategy<? super T,? extends M> targetToModel, UpdateValueStrategy<? super M,? extends T> modelToTarget)
Creates aBinding
to synchronize the values of twoobservable values
.protected <M,T>
UpdateListStrategy<M,T>createModelToTargetUpdateListStrategy(IObservableList<M> modelObservableList, IObservableList<T> targetObservableList)
Returns an update value strategy to be used for copying value list from the model list to the target list.protected <M,T>
UpdateSetStrategy<M,T>createModelToTargetUpdateSetStrategy(IObservableSet<M> modelObservableSet, IObservableSet<T> targetObservableSet)
Returns an update value strategy to be used for copying value set from the model set to the target set.protected <M,T>
UpdateValueStrategy<M,T>createModelToTargetUpdateValueStrategy(IObservableValue<M> fromValue, IObservableValue<T> toValue)
Returns an update value strategy to be used for copying values from the from value to the to value.protected <T,M>
UpdateListStrategy<T,M>createTargetToModelUpdateListStrategy(IObservableList<T> targetObservableList, IObservableList<M> modelObservableList)
Returns an update value strategy to be used for copying value list from the target list to the model list.protected <T,M>
UpdateSetStrategy<T,M>createTargetToModelUpdateSetStrategy(IObservableSet<T> targetObservableSet, IObservableSet<M> modelObservableSet)
Returns an update value strategy to be used for copying value set from the target set to the model set.protected <T,M>
UpdateValueStrategy<T,M>createTargetToModelUpdateValueStrategy(IObservableValue<T> fromValue, IObservableValue<M> toValue)
Returns an update value strategy to be used for copying values from the from value to the to value.void
dispose()
Disposes of this data binding context and all bindings and validation status providers that were added to this context.IObservableList<Binding>
getBindings()
Returns an unmodifiableIObservableList
of all bindings in order by time of addition.Realm
getValidationRealm()
Returns the validation realm.IObservableMap<Binding,IStatus>
getValidationStatusMap()
Deprecated.as of 1.1, please usegetValidationStatusProviders()
IObservableList<ValidationStatusProvider>
getValidationStatusProviders()
Returns an unmodifiableIObservableList
of all validation status providers in order by time of addition.boolean
removeBinding(Binding binding)
Removes the given binding.boolean
removeValidationStatusProvider(ValidationStatusProvider validationStatusProvider)
Removes the validation status provider.void
updateModels()
Updates all model observable objects to reflect the current state of the target observable objects.void
updateTargets()
Updates all target observable objects to reflect the current state of the model observable objects.
-
-
-
Constructor Detail
-
DataBindingContext
public DataBindingContext()
Creates a data binding context, using the current default realm for the validation observables.- See Also:
Realm
-
-
Method Detail
-
bindValue
public final <T,M> Binding bindValue(IObservableValue<T> targetObservableValue, IObservableValue<M> modelObservableValue)
Creates aBinding
to synchronize the values of twoobservable values
. This method is an alias forbindValue(targetObservableValue, modelObservableValue, null, null)
.- Parameters:
targetObservableValue
- target value, commonly a UI widgetmodelObservableValue
- model value- Returns:
- created binding
- Since:
- 1.2
-
bindValue
public final <T,M> Binding bindValue(IObservableValue<T> targetObservableValue, IObservableValue<M> modelObservableValue, UpdateValueStrategy<? super T,? extends M> targetToModel, UpdateValueStrategy<? super M,? extends T> modelToTarget)
Creates aBinding
to synchronize the values of twoobservable values
. During synchronization validation and conversion can be employed to customize the process. For specifics on the customization of the process seeUpdateValueStrategy
.- Parameters:
targetObservableValue
- target value, commonly a UI widgetmodelObservableValue
- model valuetargetToModel
- strategy to employ when the target is the source of the change and the model is the destinationmodelToTarget
- strategy to employ when the model is the source of the change and the target is the destination- Returns:
- created binding
- See Also:
UpdateValueStrategy
-
createModelToTargetUpdateValueStrategy
protected <M,T> UpdateValueStrategy<M,T> createModelToTargetUpdateValueStrategy(IObservableValue<M> fromValue, IObservableValue<T> toValue)
Returns an update value strategy to be used for copying values from the from value to the to value. Clients may override.- Parameters:
fromValue
- from model valuetoValue
- to target value- Returns:
- a update value strategy
-
createTargetToModelUpdateValueStrategy
protected <T,M> UpdateValueStrategy<T,M> createTargetToModelUpdateValueStrategy(IObservableValue<T> fromValue, IObservableValue<M> toValue)
Returns an update value strategy to be used for copying values from the from value to the to value. Clients may override.- Parameters:
fromValue
- from target valuetoValue
- to model value- Returns:
- a update value strategy
-
bindList
public final <T,M> Binding bindList(IObservableList<T> targetObservableList, IObservableList<M> modelObservableList)
Creates aBinding
to synchronize the values of twoobservable lists
. This method is an alias forbindList(targetObservableList, modelObservableList, null, null)
.- Parameters:
targetObservableList
- target list, commonly a list representing a list in the UImodelObservableList
- model list- Returns:
- created binding
- Since:
- 1.2
- See Also:
UpdateListStrategy
-
bindList
public final <T,M> Binding bindList(IObservableList<T> targetObservableList, IObservableList<M> modelObservableList, UpdateListStrategy<? super T,? extends M> targetToModel, UpdateListStrategy<? super M,? extends T> modelToTarget)
Creates aBinding
to synchronize the values of twoobservable lists
. During synchronization validation and conversion can be employed to customize the process. For specifics on the customization of the process seeUpdateListStrategy
.- Parameters:
targetObservableList
- target list, commonly a list representing a list in the UImodelObservableList
- model listtargetToModel
- strategy to employ when the target is the source of the change and the model is the destinationmodelToTarget
- strategy to employ when the model is the source of the change and the target is the destination- Returns:
- created binding
- See Also:
UpdateListStrategy
-
createModelToTargetUpdateListStrategy
protected <M,T> UpdateListStrategy<M,T> createModelToTargetUpdateListStrategy(IObservableList<M> modelObservableList, IObservableList<T> targetObservableList)
Returns an update value strategy to be used for copying value list from the model list to the target list. Clients may override.- Parameters:
modelObservableList
- from model listtargetObservableList
- to target list- Returns:
- an update list strategy
-
createTargetToModelUpdateListStrategy
protected <T,M> UpdateListStrategy<T,M> createTargetToModelUpdateListStrategy(IObservableList<T> targetObservableList, IObservableList<M> modelObservableList)
Returns an update value strategy to be used for copying value list from the target list to the model list. Clients may override.- Parameters:
targetObservableList
- from target listmodelObservableList
- to model list- Returns:
- an update list strategy
-
bindSet
public final <T,M> Binding bindSet(IObservableSet<T> targetObservableSet, IObservableSet<M> modelObservableSet)
Creates aBinding
to synchronize the values of twoobservable sets
. This method is an alias forbindSet(targetObservableValue, modelObservableValue, null, null)
.- Parameters:
targetObservableSet
- target set, commonly a set representing a set in the UImodelObservableSet
- model set- Returns:
- created binding
- Since:
- 1.2
-
bindSet
public final <T,M> Binding bindSet(IObservableSet<T> targetObservableSet, IObservableSet<M> modelObservableSet, UpdateSetStrategy<? super T,? extends M> targetToModel, UpdateSetStrategy<? super M,? extends T> modelToTarget)
Creates aBinding
to synchronize the values of twoobservable sets
. During synchronization validation and conversion can be employed to customize the process. For specifics on the customization of the process seeUpdateSetStrategy
.- Parameters:
targetObservableSet
- target set, commonly a set representing a set in the UImodelObservableSet
- model settargetToModel
- strategy to employ when the target is the source of the change and the model is the destinationmodelToTarget
- strategy to employ when the model is the source of the change and the target is the destination- Returns:
- created binding
- Since:
- 1.1
-
createTargetToModelUpdateSetStrategy
protected <T,M> UpdateSetStrategy<T,M> createTargetToModelUpdateSetStrategy(IObservableSet<T> targetObservableSet, IObservableSet<M> modelObservableSet)
Returns an update value strategy to be used for copying value set from the target set to the model set. Clients may override.- Parameters:
targetObservableSet
- from target setmodelObservableSet
- to model set- Returns:
- a default set update strategy
- Since:
- 1.1
-
createModelToTargetUpdateSetStrategy
protected <M,T> UpdateSetStrategy<M,T> createModelToTargetUpdateSetStrategy(IObservableSet<M> modelObservableSet, IObservableSet<T> targetObservableSet)
Returns an update value strategy to be used for copying value set from the model set to the target set. Clients may override.- Parameters:
modelObservableSet
- from model settargetObservableSet
- to target set- Returns:
- a default set update strategy
- Since:
- 1.1
-
dispose
public final void dispose()
Disposes of this data binding context and all bindings and validation status providers that were added to this context. This method must be called in thevalidation realm
.
-
getBindings
public final IObservableList<Binding> getBindings()
Returns an unmodifiableIObservableList
of all bindings in order by time of addition.- Returns:
- an unmodifiable
IObservableList
of all bindings
-
getValidationStatusProviders
public final IObservableList<ValidationStatusProvider> getValidationStatusProviders()
Returns an unmodifiableIObservableList
of all validation status providers in order by time of addition.- Returns:
- an unmodifiable
IObservableList
of all validation status providers - Since:
- 1.1
-
getValidationStatusMap
@Deprecated public final IObservableMap<Binding,IStatus> getValidationStatusMap()
Deprecated.as of 1.1, please usegetValidationStatusProviders()
Returns anIObservableMap
mapping from bindings to current validation statuses. The keys of the map are the bindings returned bygetBindings()
, and the values are the current IStatus objects for each binding.- Returns:
- the observable map from bindings to status objects.
-
addBinding
public void addBinding(Binding binding)
Adds the given binding to this data binding context. This will also add the given binding to the list of validation status providers.- Parameters:
binding
- The binding to add.- See Also:
addValidationStatusProvider(ValidationStatusProvider)
,getValidationStatusProviders()
-
addValidationStatusProvider
public void addValidationStatusProvider(ValidationStatusProvider validationStatusProvider)
Adds the given validation status provider to this data binding context.- Parameters:
validationStatusProvider
- The validation status provider to add.- Since:
- 1.1
-
updateModels
public final void updateModels()
Updates all model observable objects to reflect the current state of the target observable objects.
-
updateTargets
public final void updateTargets()
Updates all target observable objects to reflect the current state of the model observable objects.
-
removeBinding
public boolean removeBinding(Binding binding)
Removes the given binding.- Parameters:
binding
- The binding to remove.- Returns:
true
if was associated with the context,false
if not
-
removeValidationStatusProvider
public boolean removeValidationStatusProvider(ValidationStatusProvider validationStatusProvider)
Removes the validation status provider.- Parameters:
validationStatusProvider
- The validation status provider to remove.- Returns:
true
if was associated with the context,false
if not- Since:
- 1.1
-
-