Skip to main content
Jump to: navigation, search

JFace Data Binding/The New Binding API

< JFace Data Binding
Revision as of 09:18, 24 August 2013 by Nigelipse.miegel.org (Talk | contribs) (New page: The existing API for the JFace Data Binding is showing its age. A new API is now available. The same classes for observables, properties, etc are the same. It is only the way the observ...)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

The existing API for the JFace Data Binding is showing its age. A new API is now available. The same classes for observables, properties, etc are the same. It is only the way the observables are bound together that is different.

The DataBindingContext class is no longer used. Instead use the new Bind class.

Basic Usage

To bind a model observable (IObservableValue<T> modelObservable) to a target observable (ObservableValue<T> targetObservable), use code as follows:

Bind.twoWay(modelObservable).to(targetObservable)

This will set up two way binding between the model and the target, with the initial value from the model being initially set into the target. If you want one way binding from the model to the target then use the following:

Bind.oneWay(modelObservable).to(targetObservable)

If you want to validate values going from the target to the model then you can insert a validator (IValidator<T> myValidator) as follows:

Bind.twoWay(modelObservable).validate(myValidator).to(targetObservable)

Notice how methods are chained together. You start the chain by calling either the static method Bind.oneWay or the static method Bind.twoWay, passing the model observable. These two methods return respectively, an IOneWayBinding or an ITwoWayBinding implementation. Both of these interfaces contain various methods for validations, conversions, and other operations. These methods in general return an IOneWayBinding or an ITwoWayBinding implementation, so you can chain operations together. Finally you call the to method passing the target observable.


@See

Back to the top