public class RelayBinding<TParentValue,TValue,TObservedValue extends javafx.beans.value.ObservableValue<TValue>>
extends javafx.beans.binding.ObjectBinding<TValue>
e.G. if we have a class A which hold a property of B, which hold property of C, which holds a property of D and D is the property we want to bind to, we would like build something like this
A a = new A();
ObjectProperty<Long> property = new SimpleObjectProperty<>();
a.getB().getC().dProperty().bindBidirectional(property);
However since B and C might be null we would need to listen to the values to become available at some point in time. This is where the
RelayBinding comes into play and handles this by attaching listeners cascadingly so that we can bind to D with no concern that B or C might be
null, change or become invalid.
e.g. using the above example, the code to safely bind to D would look like this.
A a = new A();
ObjectProperty<Long> property = new SimpleObjectProperty<>();
new NestedBinding(a.bProperty(), B::cProperty).bindBidirectional(C::dProperty, property, false);
| Modifier and Type | Method and Description |
|---|---|
void |
addListener(@NotNull javafx.beans.value.ChangeListener<? super TValue> listener) |
void |
addListener(@NotNull javafx.beans.InvalidationListener listener) |
protected void |
afterSetObservedValue(@NotNull javafx.beans.value.ObservableValue<TValue> observableValue)
Will be called when the
observedValue was set. |
protected void |
beforeDestroyObservedValue(@NotNull javafx.beans.value.ObservableValue<TValue> observableValue)
Will be called when the
observedValue is about to be destroyed. |
void |
changed(@Nullable javafx.beans.value.ObservableValue<? extends TValue> observable,
TValue oldValue,
TValue newValue)
When the observed value is propertyChanged, this binding is invalidated.
|
protected TValue |
computeValue()
Returns the current value of the
observedValue if any. |
protected void |
destroyObservedValue()
Removes this binding as the listener from the
observedValue, invokes a call to changed(ObservableValue, Object, Object) with the oldValue and then
sets the observedValue to null. |
void |
dispose()
Stops listening to the
observedValue and also stops the replacement, fallback value and all attached listeners. |
@NotNull IFluentBinding<TValue> |
fallbackOn(TValue fallbackValue)
Sets a fallback value that will be returned if the underlying
ObservableValue is not yet set. |
@NotNull Optional<javafx.beans.value.ObservableValue<TValue>> |
getObservedValue()
Returns the current value of the
observedValue. |
boolean |
hasFallbackValue()
Determines if the binding has as fallback value.
|
boolean |
hasListeners()
Determines if this binding has any
ChangeListener or InvalidationListener attached to it. |
boolean |
hasReplacement()
Determines if the binding has a replacement.
|
void |
removeListener(@NotNull javafx.beans.value.ChangeListener<? super TValue> listener) |
void |
removeListener(@NotNull javafx.beans.InvalidationListener listener) |
@NotNull IFluentBinding<TValue> |
replaceWith(@Nullable Function<TValue,TValue> valueReplacer)
Applies the given
Function whenever the underlying ObservableValue is changed, allowing for certain values to be replaced or ignored. |
protected void |
setObservedValue(@NotNull javafx.beans.value.ObservableValue<TValue> observedValue)
Sets the
observedValue and adds the this binding as the listener. |
@NotNull IFluentBinding<TValue> |
stopFallbackOn()
Removes the fallback value, so that null will be returned instead of the fallback value.
|
@NotNull IFluentBinding<TValue> |
stopListeners()
Removes all the
ChangeListener and InvalidationListener that have been attached to this binding. |
@NotNull IFluentBinding<TValue> |
stopReplacement()
Stops replacing the value of the underlying
ObservableValue. |
boolean |
wasGarbageCollected()
Returns true if the
observedValue is no longer set. |
bind, get, getDependencies, invalidate, isValid, onInvalidating, toString, unbindasString, asString, asString, getValue, isEqualTo, isEqualTo, isNotEqualTo, isNotEqualTo, isNotNull, isNull, objectExpressionclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitconvertTo, replaceWith, thenObserve, thenObservePropertypublic void dispose()
observedValue and also stops the replacement, fallback value and all attached listeners. Also stops listening to the parent.dispose in interface javafx.beans.binding.Binding<TValue>stopReplacement(),
stopFallbackOn(),
stopListeners()@NotNull public @NotNull Optional<javafx.beans.value.ObservableValue<TValue>> getObservedValue()
observedValue.Optional.empty() if the observedValue is null or an Optional of the current value of the observedValue.protected final void destroyObservedValue()
observedValue, invokes a call to changed(ObservableValue, Object, Object) with the oldValue and then
sets the observedValue to null.protected final void setObservedValue(@NotNull
@NotNull javafx.beans.value.ObservableValue<TValue> observedValue)
observedValue and adds the this binding as the listener.observedValue - the ObservableValue which will be used as the observedValueprotected void beforeDestroyObservedValue(@NotNull
@NotNull javafx.beans.value.ObservableValue<TValue> observableValue)
observedValue is about to be destroyed.observableValue - the current observedValue.protected void afterSetObservedValue(@NotNull
@NotNull javafx.beans.value.ObservableValue<TValue> observableValue)
observedValue was set.observableValue - the current observedValue.@Nullable protected TValue computeValue()
observedValue if any.computeValue in class javafx.beans.binding.ObjectBinding<TValue>observedValue if any.public void changed(@Nullable
@Nullable javafx.beans.value.ObservableValue<? extends TValue> observable,
@Nullable
TValue oldValue,
@Nullable
TValue newValue)
changed in interface javafx.beans.value.ChangeListener<TValue>public boolean wasGarbageCollected()
observedValue is no longer set.wasGarbageCollected in interface javafx.beans.WeakListenerobservedValue is no longer set, otherwise false.@NotNull public @NotNull IFluentBinding<TValue> fallbackOn(@Nullable TValue fallbackValue)
ObservableValue is not yet set.fallbackOn in interface IFluentBinding<TValue>fallbackValue - the value to fallback on.IFluentBinding.IFluentBinding.stopFallbackOn(),
IFluentBinding.hasFallbackValue()@NotNull public @NotNull IFluentBinding<TValue> stopFallbackOn()
stopFallbackOn in interface IFluentBinding<TValue>IFluentBinding.IFluentBinding.fallbackOn(Object),
IFluentBinding.hasFallbackValue()public boolean hasFallbackValue()
hasFallbackValue in interface IFluentBinding<TValue>IFluentBinding.fallbackOn(Object),
IFluentBinding.stopFallbackOn()@NotNull public @NotNull IFluentBinding<TValue> replaceWith(@Nullable @Nullable Function<TValue,TValue> valueReplacer)
Function whenever the underlying ObservableValue is changed, allowing for certain values to be replaced or ignored. In order to stop this behaviour a call
to IFluentBinding.stopReplacement() is required. A call to this method should overwrite previous call, so only the last applied behaviour is used.replaceWith in interface IFluentBinding<TValue>valueReplacer - the Function which decided if the value of the underlying ObservableValue will be replaced with the fallback value.IFluentBinding.IFluentBinding.replaceWith(Predicate, Object),
IFluentBinding.stopReplacement(),
IFluentBinding.stopReplacement(),
IFluentBinding.hasReplacement()@NotNull public @NotNull IFluentBinding<TValue> stopReplacement()
ObservableValue.stopReplacement in interface IFluentBinding<TValue>IFluentBinding.IFluentBinding.replaceWith(Function),
IFluentBinding.replaceWith(Predicate, Object),
IFluentBinding.hasReplacement()public boolean hasReplacement()
hasReplacement in interface IFluentBinding<TValue>IFluentBinding.replaceWith(Predicate, Object),
IFluentBinding.replaceWith(Function),
IFluentBinding.stopReplacement()public void addListener(@NotNull
@NotNull javafx.beans.InvalidationListener listener)
addListener in interface javafx.beans.ObservableaddListener in class javafx.beans.binding.ObjectBinding<TValue>public void removeListener(@NotNull
@NotNull javafx.beans.InvalidationListener listener)
removeListener in interface javafx.beans.ObservableremoveListener in class javafx.beans.binding.ObjectBinding<TValue>public void addListener(@NotNull
@NotNull javafx.beans.value.ChangeListener<? super TValue> listener)
addListener in interface javafx.beans.value.ObservableValue<TValue>addListener in class javafx.beans.binding.ObjectBinding<TValue>public void removeListener(@NotNull
@NotNull javafx.beans.value.ChangeListener<? super TValue> listener)
removeListener in interface javafx.beans.value.ObservableValue<TValue>removeListener in class javafx.beans.binding.ObjectBinding<TValue>@NotNull public @NotNull IFluentBinding<TValue> stopListeners()
ChangeListener and InvalidationListener that have been attached to this binding.stopListeners in interface IFluentBinding<TValue>IFluentBinding.ObservableValue.addListener(ChangeListener),
Observable.addListener(InvalidationListener),
IFluentBinding.hasListeners()public boolean hasListeners()
IFluentBindingChangeListener or InvalidationListener attached to it.hasListeners in interface IFluentBinding<TValue>ChangeListener or InvalidationListener attached to it, otherwise false.IFluentBinding.stopListeners(),
ObservableValue.addListener(ChangeListener),
Observable.addListener(InvalidationListener)Copyright © 2016 Saxonia Systems AG. All rights reserved.