DefaultIndirectObservableValue

open class DefaultIndirectObservableValue<P : Any, V>(val parentProperty: ObservableValue<P?>, val defaultValue: V, val getObservable: (P) -> ObservableValue<V>) : LazyObservableValue<V>

Tracks a value of a property where we don't have the property itself, but only another property, (parentProperty) from which we can access the required property.

Imagine we have a class Person, with : val nameProperty : StringProperty

Now suppose we have :

val personProperty : Property

Note that personProperty.value can be null.

The following will give us an ObservableValue which changes whenever personProperty changes, and also changes whenever that person's name changes.

val personNameProperty : ObservableValue = IndirectObservableValue( personProperty, "" ) {
    person -> person.nameProperty.value
}

When personProperty.value == null, then personNameProperty.value == "<None>", not null.

Alas, personNameProperty is not of type ObservableString. To work around the JVM's limited type system, consider creating a boilerplate class :

class IndirectObservableString

( parentProperty: ObservableValue, defaultValue: String, getObservable: (P) -> ObservableValue ) : IndirectObservableValue(parentProperty, defaultValue, getObservable), ObservableString

Inheritors

Constructors

Link copied to clipboard
constructor(parentProperty: ObservableValue<P?>, defaultValue: V, getObservable: (P) -> ObservableValue<V>)

Properties

Link copied to clipboard

The default value to use when parentProperty.value == null.

Link copied to clipboard

A lambda to get the ObservableValue we are interested in tracking, from the value of parentProperty.

Link copied to clipboard
Link copied to clipboard
open override val value: V

Functions

Link copied to clipboard
open override fun addBindChangeListener(listener: ChangeListener<V, ObservableValue<V>>)

Identical to addChangeListener, but these listeners are guaranteed to fire BEFORE other listeners. These should be used for the sole purpose of updating single ObservableValues which are dependent on this ObservableValue. This helps (but doesn't guarantee) that properties change atomically. i.e. when one property changes, a related property also changes before other (regular) listeners fire. Therefore, the (regular) listeners cannot read inconsistent values.

Link copied to clipboard

open override fun addBindListener(listener: InvalidationListener)

Identical to addListener, but these listeners are guaranteed to fire BEFORE regular listeners. These should be used for the sole purpose of updating other ObservableValues which are dependent on this Observable.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
open override fun addListener(listener: InvalidationListener)
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Converts an ObservableValue, with a non-nullable to value, to an ObservableValue whose value IS nullable.

Link copied to clipboard
Link copied to clipboard
open override fun eval(): V
Link copied to clipboard
open operator fun getValue(thisRef: Any, kProperty: KProperty<*>): V

Lets us declare a val using a for the value of this property, using this as a delegate. e.g.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
open override fun removeChangeListener(listener: ChangeListener<V, ObservableValue<V>>)
Link copied to clipboard
Link copied to clipboard
open override fun removeListener(listener: InvalidationListener)
Link copied to clipboard

Converts an ObservableValue, with a nullable to value, to an ObservableValue whose value is NOT nullable, by supplying a defaultValue.

Link copied to clipboard
Link copied to clipboard