Class Bind
java.lang.Object
org.eclipse.core.databinding.bind.Bind
This class contains static methods that are the entry points to the fluent
databinding API. Bindings are created using a single expression of chained
method calls.
This fluent API is a facade for the traditional databinding API that is based
on DataBindingContext
and UpdateValueStrategy
. It provides
short-hands, extra type safety and better readability, but no new
functionality. Everything that is possible to do with the traditional API is
also possible using the new API.
Example:
Bind.twoWay() // 1
.from(WidgetProperties.text(SWT.Modify).observe(text)) // 2
.validateAfterConvert(widgetValidator) // 3
.convertTo(IConverter.create(i -> Objects.toString(i, ""))) // 4
.convertFrom(IConverter.create(s -> s.isEmpty() ? 0 : Integer.decode(s)))
.to(modelValue) // 5
.validateBeforeSet(modelValidator) // 6
.bind(bindingContext); // 7
- 1. First the user chooses between a two-way or one-way binding. The binding direction (target-to-model or model-to-target) can also be chosen.
- 2. The from-end observable is given. Here the API chooses between value, list of set bindings.
- 3. The from-end is configured. This involves setting validators and binding policies (that is, convert-only or only-on-request). Only methods that are relevant for two-way or one-way bindings are present for the respective cases.
- 4. Converters are set. Here the to-end observable gets its type. The API ensures that two converters are set for two-way bindings.
- 5. The to-end observable is set.
- 6. The to-end is configured, in the same was as the from-end.
- 7. The bind-method is called, with a DataBindingContext as argument. This
internally creates
UpdateValueStrategy
objects and callsDataBindingContext.bindValue(org.eclipse.core.databinding.observable.value.IObservableValue<T>, org.eclipse.core.databinding.observable.value.IObservableValue<M>)
.
- Since:
- 1.11
- Restriction:
-
Method Summary
Modifier and TypeMethodDescriptionstatic CommonSteps.OneWayConfigAndFromStep<?>
oneWay()
Returns the first step in a pipeline that will create a one-way binding, for value, list or set bindings.static CommonSteps.TwoWayConfigAndFromStep<?>
twoWay()
Returns the first step in a pipeline that will create a two-way binding, for value, list or set bindings.
-
Method Details
-
twoWay
Returns the first step in a pipeline that will create a two-way binding, for value, list or set bindings.- The direction of the binding is target-to-model by default.
- Both directions of the binding will have policy
UpdateValueStrategy.POLICY_UPDATE
by default.
- Returns:
- the first binding step
- See Also:
-
DataBindingContext.bindValue(org.eclipse.core.databinding.observable.value.IObservableValue<T>, org.eclipse.core.databinding.observable.value.IObservableValue<M>)
DataBindingContext.bindList(org.eclipse.core.databinding.observable.list.IObservableList<T>, org.eclipse.core.databinding.observable.list.IObservableList<M>)
DataBindingContext.bindSet(org.eclipse.core.databinding.observable.set.IObservableSet<T>, org.eclipse.core.databinding.observable.set.IObservableSet<M>)
-
oneWay
Returns the first step in a pipeline that will create a one-way binding, for value, list or set bindings.- The direction of the binding is target-to-model by default.
- The from-to direction of the binding has policy
UpdateValueStrategy.POLICY_UPDATE
by default. - The to-from direction of the binding has policy
UpdateValueStrategy.POLICY_NEVER
.
- Returns:
- the first binding step
- See Also:
-
DataBindingContext.bindValue(org.eclipse.core.databinding.observable.value.IObservableValue<T>, org.eclipse.core.databinding.observable.value.IObservableValue<M>)
DataBindingContext.bindList(org.eclipse.core.databinding.observable.list.IObservableList<T>, org.eclipse.core.databinding.observable.list.IObservableList<M>)
DataBindingContext.bindSet(org.eclipse.core.databinding.observable.set.IObservableSet<T>, org.eclipse.core.databinding.observable.set.IObservableSet<M>)
-