Class Bind

java.lang.Object
org.eclipse.core.databinding.bind.Bind

public final class Bind extends Object
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 calls DataBindingContext.bindValue(org.eclipse.core.databinding.observable.value.IObservableValue<T>, org.eclipse.core.databinding.observable.value.IObservableValue<M>).
Since:
1.11
Restriction: