Module MaterialFX

Class BindingHelper<T>

java.lang.Object
io.github.palexdev.materialfx.bindings.base.AbstractBindingHelper<T>
io.github.palexdev.materialfx.bindings.BindingHelper<T>
Type Parameters:
T - the properties' value type

public class BindingHelper<T> extends AbstractBindingHelper<T>
Binding helper for unidirectional bindings.

Bindings are syntactical sugar, because basically it's a listener attached to an observable value which acts as a 'source', when it changes the target is updated.

The issue though is that this 'syntactical sugar' mechanism is managed by JavaFX, some functionalities are private, unchangeable. For example, JavaFX properties are not settable when they are bound because an internal flag doesn't allow it. To replicate this behavior the only way is to override the property's 'isBound' method to use the BindingManager, an example:

 
         BindingManager bindingManager = BindingManager.instance();
         IntegerProperty property = new SimpleIntegerProperty() {
             @Override
             public boolean isBound() {
                 return bindingManager.isBound(this) && !bindingManager.isIgnoreBinding(this);
             }
         };
         IntegerProperty source = new SimpleIntegerProperty();

         bindingManager.bind(property).to(source).create();
         source.set(8);
 
 

The 'ignoreBinding' flag is necessary because when the updateTarget is triggered we must tell the property to allow the modification because it is caused by the binding helper.