BiBindingHelper.
For bidirectional bindings a given target property will always have one and only helper at any time.
The sources list is managed by that manager, when a new bind is made on the same target, a new BiBindingHelper
is created, which is the combination of the old one and the new one, BiBindingHelper.newFor(BiBindingHelper, BiBindingHelper, boolean) is used.
When a binding is not necessary anymore it's opportune to dispose it either with dispose() or
unbind(ObservableValue, ObservableValue) or clear(ObservableValue).
This mechanism is so flexible that it also allows to bind read-only properties on the sole condition that
you must have a way to set that property and it must be specified with BiBindingBuilder.
For these properties be careful during the unbind as in JavaFX the getReadOnlyProperty() method returns a completely different instance. For this reason the manager also offers unbind methods to unbind read-only wrappers.
To make the bindings building more readable it usesBiBindingBuilder.-
Method Summary
Modifier and TypeMethodDescription<T> BiBindingManagerapply(BiBindingBuilder<T> bindingBuilder, BiBindingHelper<T> bindingHelper, boolean override) Creates a bidirectional binding with the given arguments.<T> BiBindingBuilder<T>bindBidirectional(Property<T> target) Creates and returns a newBiBindingBuilderwith the given target.<T> BiBindingBuilder<T>bindBidirectional(ObservableValue<? extends T> target) Creates and returns a newBiBindingBuilderwith the given target.<T> BiBindingManagerclear(ObservableValue<? extends T> target) CallsBiBindingHelper.clear()for the given target (if existing in tha map).dispose()Disposes all the bindings and clears the map.<T> BiBindingManagerdisposeFor(ObservableValue<? extends T> target) CallsBiBindingHelper.dispose()for the given target (if existing in tha map).static BiBindingManagerinstance()Retrieves the instance of the BiBindingManager<T> booleanisBound(ObservableValue<? extends T> target) Checks if the bindings map contains the given target.booleanisEmpty()Checks ifsize()is 0;intsize()<T> BiBindingManagerunbind(ObservableValue<? extends T> target, ObservableValue<? extends T> source) Removes the given source from the given target's binding.unbindReadOnly(ReadOnlyBooleanWrapper target, ObservableValue<? extends Boolean> source) Retrieves the read-only property withReadOnlyBooleanWrapper.getReadOnlyProperty()and callsunbind(ObservableValue, ObservableValue)on it.unbindReadOnly(ReadOnlyDoubleWrapper target, ObservableValue<? extends Double> source) Retrieves the read-only property withReadOnlyDoubleWrapper.getReadOnlyProperty()and callsunbind(ObservableValue, ObservableValue)on it.unbindReadOnly(ReadOnlyFloatWrapper target, ObservableValue<? extends Float> source) Retrieves the read-only property withReadOnlyFloatWrapper.getReadOnlyProperty()and callsunbind(ObservableValue, ObservableValue)on it.unbindReadOnly(ReadOnlyIntegerWrapper target, ObservableValue<? extends Integer> source) Retrieves the read-only property withReadOnlyIntegerWrapper.getReadOnlyProperty()and callsunbind(ObservableValue, ObservableValue)on it.unbindReadOnly(ReadOnlyLongWrapper target, ObservableValue<? extends Long> source) Retrieves the read-only property withReadOnlyLongWrapper.getReadOnlyProperty()and callsunbind(ObservableValue, ObservableValue)on it.<T> BiBindingManagerunbindReadOnly(ReadOnlyObjectWrapper<T> target, ObservableValue<? extends T> source) Retrieves the read-only property withReadOnlyObjectWrapper.getReadOnlyProperty()and callsunbind(ObservableValue, ObservableValue)on it.unbindReadOnly(ReadOnlyStringWrapper target, ObservableValue<? extends String> source) Retrieves the read-only property withReadOnlyStringWrapper.getReadOnlyProperty()and callsunbind(ObservableValue, ObservableValue)on it.
-
Method Details
-
instance
Retrieves the instance of the BiBindingManager -
bindBidirectional
Creates and returns a newBiBindingBuilderwith the given target. -
bindBidirectional
Creates and returns a newBiBindingBuilderwith the given target. Since it is aPropertya default targetUpdater is also set by usingWritableValue.setValue(Object). -
apply
public <T> BiBindingManager apply(BiBindingBuilder<T> bindingBuilder, BiBindingHelper<T> bindingHelper, boolean override) Creates a bidirectional binding with the given arguments. TheBindingBuilderspecifies the target, the targetUpdater and the source.Calls
ThebindingCheck(ObservableValue)on the target before proceeding.BiBindingHelperto use must be computed properly as there are several cases:- The target is already bound to something: in this case a new helper is created by combining the existing one and the given one using
BiBindingHelper.newFor(BiBindingHelper, BiBindingHelper, boolean)- The given helper is null or equal to the existing one: in this case the existing one is used and all the sources of the given one are added to the existing one
The target is not already bound: if the given helper is null a new one is created otherwise the given one is used.
If the givenBiBindingBuilder's eager evaluation flag is true (by default it is)BiBindingHelper.invalidate()is called on the chosen helper. At the end the entry, target-helper, in put into the map. If usingBiBindingBuilder.create()it's not necessary to call this method too!! -
unbind
public <T> BiBindingManager unbind(ObservableValue<? extends T> target, ObservableValue<? extends T> source) Removes the given source from the given target's binding. If by removing the source, the helper becomes empty, the target is removed from the bindings map. -
clear
CallsBiBindingHelper.clear()for the given target (if existing in tha map). -
disposeFor
CallsBiBindingHelper.dispose()for the given target (if existing in tha map). -
dispose
Disposes all the bindings and clears the map. -
unbindReadOnly
public BiBindingManager unbindReadOnly(ReadOnlyBooleanWrapper target, ObservableValue<? extends Boolean> source) Retrieves the read-only property withReadOnlyBooleanWrapper.getReadOnlyProperty()and callsunbind(ObservableValue, ObservableValue)on it. -
unbindReadOnly
public BiBindingManager unbindReadOnly(ReadOnlyStringWrapper target, ObservableValue<? extends String> source) Retrieves the read-only property withReadOnlyStringWrapper.getReadOnlyProperty()and callsunbind(ObservableValue, ObservableValue)on it. -
unbindReadOnly
public BiBindingManager unbindReadOnly(ReadOnlyIntegerWrapper target, ObservableValue<? extends Integer> source) Retrieves the read-only property withReadOnlyIntegerWrapper.getReadOnlyProperty()and callsunbind(ObservableValue, ObservableValue)on it. -
unbindReadOnly
public BiBindingManager unbindReadOnly(ReadOnlyLongWrapper target, ObservableValue<? extends Long> source) Retrieves the read-only property withReadOnlyLongWrapper.getReadOnlyProperty()and callsunbind(ObservableValue, ObservableValue)on it. -
unbindReadOnly
public BiBindingManager unbindReadOnly(ReadOnlyFloatWrapper target, ObservableValue<? extends Float> source) Retrieves the read-only property withReadOnlyFloatWrapper.getReadOnlyProperty()and callsunbind(ObservableValue, ObservableValue)on it. -
unbindReadOnly
public BiBindingManager unbindReadOnly(ReadOnlyDoubleWrapper target, ObservableValue<? extends Double> source) Retrieves the read-only property withReadOnlyDoubleWrapper.getReadOnlyProperty()and callsunbind(ObservableValue, ObservableValue)on it. -
unbindReadOnly
public <T> BiBindingManager unbindReadOnly(ReadOnlyObjectWrapper<T> target, ObservableValue<? extends T> source) Retrieves the read-only property withReadOnlyObjectWrapper.getReadOnlyProperty()and callsunbind(ObservableValue, ObservableValue)on it. -
isBound
Checks if the bindings map contains the given target. -
size
public int size()- Returns:
- the number of bindings actually present in the map
-
isEmpty
public boolean isEmpty()Checks ifsize()is 0;
-