Class DataBindingContext


  • public class DataBindingContext
    extends Object
    A DataBindingContext is the point of contact for the creation and management of bindings, 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 the IWizard would have its own context instance.

    Since:
    1.0
    • Constructor Detail

      • DataBindingContext

        public DataBindingContext()
        Creates a data binding context, using the current default realm for the validation observables.
        See Also:
        Realm
      • DataBindingContext

        public DataBindingContext​(Realm validationRealm)
        Creates a data binding context using the given realm for the validation observables.
        Parameters:
        validationRealm - the realm to be used for the validation observables
        See Also:
        Realm
    • Method Detail

      • bindValue

        public final <T,​M> Binding bindValue​(IObservableValue<T> targetObservableValue,
                                                   IObservableValue<M> modelObservableValue)
        Creates a Binding to synchronize the values of two observable values. This method is an alias for bindValue(targetObservableValue, modelObservableValue, null, null).
        Parameters:
        targetObservableValue - target value, commonly a UI widget
        modelObservableValue - 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 a Binding to synchronize the values of two observable values. During synchronization validation and conversion can be employed to customize the process. For specifics on the customization of the process see UpdateValueStrategy.
        Parameters:
        targetObservableValue - target value, commonly a UI widget
        modelObservableValue - model value
        targetToModel - strategy to employ when the target is the source of the change and the model is the destination
        modelToTarget - 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 -
        toValue -
        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 -
        toValue -
        Returns:
        a update value strategy
      • bindList

        public final <T,​M> Binding bindList​(IObservableList<T> targetObservableList,
                                                  IObservableList<M> modelObservableList)
        Creates a Binding to synchronize the values of two observable lists. This method is an alias for bindList(targetObservableList, modelObservableList, null, null).
        Parameters:
        targetObservableList - target list, commonly a list representing a list in the UI
        modelObservableList - 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 a Binding to synchronize the values of two observable lists. During synchronization validation and conversion can be employed to customize the process. For specifics on the customization of the process see UpdateListStrategy.
        Parameters:
        targetObservableList - target list, commonly a list representing a list in the UI
        modelObservableList - model list
        targetToModel - strategy to employ when the target is the source of the change and the model is the destination
        modelToTarget - 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)
        Parameters:
        modelObservableList -
        targetObservableList -
        Returns:
        an update list strategy
      • createTargetToModelUpdateListStrategy

        protected <T,​M> UpdateListStrategy<T,​M> createTargetToModelUpdateListStrategy​(IObservableList<T> targetObservableList,
                                                                                                  IObservableList<M> modelObservableList)
        Parameters:
        targetObservableList -
        modelObservableList -
        Returns:
        an update list strategy
      • bindSet

        public final <T,​M> Binding bindSet​(IObservableSet<T> targetObservableSet,
                                                 IObservableSet<M> modelObservableSet)
        Creates a Binding to synchronize the values of two observable sets. This method is an alias for bindSet(targetObservableValue, modelObservableValue, null, null).
        Parameters:
        targetObservableSet - target set, commonly a set representing a set in the UI
        modelObservableSet - 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 a Binding to synchronize the values of two observable sets. During synchronization validation and conversion can be employed to customize the process. For specifics on the customization of the process see UpdateSetStrategy.
        Parameters:
        targetObservableSet - target set, commonly a set representing a set in the UI
        modelObservableSet - model set
        targetToModel - strategy to employ when the target is the source of the change and the model is the destination
        modelToTarget - 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)
        Parameters:
        targetObservableSet -
        modelObservableSet -
        Returns:
        a default set update strategy
        Since:
        1.1
      • createModelToTargetUpdateSetStrategy

        protected <M,​T> UpdateSetStrategy<M,​T> createModelToTargetUpdateSetStrategy​(IObservableSet<M> modelObservableSet,
                                                                                                IObservableSet<T> targetObservableSet)
        Parameters:
        modelObservableSet -
        targetObservableSet -
        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 the validation realm.
      • 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 -
        Returns:
        true if was associated with the context, false if not
      • removeValidationStatusProvider

        public boolean removeValidationStatusProvider​(ValidationStatusProvider validationStatusProvider)
        Removes the validation status provider.
        Parameters:
        validationStatusProvider -
        Returns:
        true if was associated with the context, false if not
        Since:
        1.1
      • getValidationRealm

        public final Realm getValidationRealm()
        Returns the validation realm.
        Returns:
        the realm for the validation observables
        See Also:
        Realm