Jump to: navigation, search

JFace Data Binding/The New Binding API/Bind Proposals

This page contains proposals for new stuff for the binding API. If you have requirements you would like to see, please edit this page or create a bug.

Bind instances

The above examples have all used static methods in the Bind class. However sometimes we need to group bindings together. For example, the dispose method in the old DataBindingContext class disposes all bindings in the context. To support the same concept, Bind allows the creation of a Bind instance to give context.

For example:

Bind bindingContext = Bind.createContext(); bindingContext.twoWay(modelObservable1).to(targetObservable1); bindingContext.twoWay(modelObservable2).to(targetObservable2); bindingContext.twoWay(modelObservable3).to(targetObservable3);

...

bindingContext.dispose();

Transaction Bind instance

Sometimes you don't want changes to go from the target to the model immediately. For example if the target controls are in a dialog box then you may want the values to be set in the model only if and when the user presses the 'OK' button. Another example would be an editor part where you don't want parts outside the editor to see the changes until the editor has been saved. To do this you create a 'transaction' binding context:

Bind bindingContext = Bind.createTransactionalContext(); bindingContext.twoWay(modelObservable1).to(targetObservable1); bindingContext.twoWay(modelObservable2).to(targetObservable2); bindingContext.twoWay(modelObservable3).to(targetObservable3);

Changes to the model will now be set in the target but changes to the target are not immediately set in the model. When changes need to be set in the model (for example when the user presses the 'OK' button in a dialog or the user saves an editor) then the following code should be called:

bindingContext.commit();

If commit is never called (for example the user pressed the 'Cancel' button) then the model is never updated.

The transactional binding context also has an isDirty method. This method returns an IObservableValue<Boolean> that can be bound to the enablement of the 'OK' button in a dialog or the dirty state of an editor.