tieskedh
06/25/2018, 5:50 PMtextProperty().mapObservable<Int>{it?.split(" ")?.size ?: 0}
or in this case
textProperty().mapObservable{ it?.split(" ")?.size ?: 0 }
bkenn
06/25/2018, 5:55 PMbkenn
06/25/2018, 5:57 PMbinding
instead of mapObservable
carlw
06/25/2018, 6:03 PMbkenn
06/25/2018, 6:08 PMbinding
falls more inline with the other extension functions that create bindings from Observables.bkenn
06/25/2018, 6:09 PMstringBinding
, integerBinding
, doubleBinding
and then binding
.tieskedh
06/25/2018, 6:18 PMtieskedh
06/25/2018, 6:36 PMinline fun <reified T, reified R, reified S : Binding<R>> ObservableValue<T>.fun1(vararg dependencies: Observable, noinline op: (T?) -> R)
= fun2(*dependencies, op = op)
inline fun <reified T, reified R> ObservableValue<T>.fun2(vararg dependencies: Observable, crossinline op: (T?) -> R) = when (R::class) {
String::class -> stringBinding(*dependencies) { it: T? -> op(it) as String? }
Double::class -> doubleBinding(*dependencies) { it: T? -> op(it) as Double }
Float::class -> floatBinding(*dependencies) { it: T? -> op(it) as Float }
Long::class -> longBinding(*dependencies) { it: T? -> op(it) as Long }
Int::class -> integerBinding(*dependencies) { it: T? -> op(it) as Int }
Boolean::class -> booleanBinding(*dependencies) { it: T? -> op(it) as Boolean }
else -> objectBinding(*dependencies) { it: T? -> op(it) }
} as Binding<R>
ron
06/25/2018, 6:36 PMiLobanov
06/25/2018, 7:39 PMcarlw
06/25/2018, 7:48 PMiLobanov
06/25/2018, 7:55 PMiLobanov
06/25/2018, 7:56 PMiLobanov
06/26/2018, 1:01 PMamanda.hinchman-dominguez
06/26/2018, 1:44 PMhover
function, I'd be willing to try and see if there's something for focus
or select
, but I haven't tested it out yetcarlw
06/26/2018, 2:18 PMcarlw
06/26/2018, 2:18 PMiLobanov
06/26/2018, 2:35 PMiLobanov
06/26/2018, 2:37 PMorangy
class MyView() : View() {
private val rootProperty = modelProperty.objectBinding {
TreeItem(it as MyItem?)
}
override val root = vbox {
addClass(Styles.wrapper)
treeview<MyItem> {
rootProperty().bind(rootProperty)
cellFormat { text = it.toString() }
populate {
val value = it.value
when (value) {
is ContainerItem -> value.children
else -> emptyList()
}
}
}
}
}
First time it binds just fine, but when otherProperty
changes (through couple of other bindings), root node changes, but children are not populated. It just displays root node without expansion button and no children visible.carlw
06/26/2018, 2:41 PMcarlw
06/26/2018, 2:41 PMorangy
carlw
06/26/2018, 2:44 PMorangy
carlw
06/26/2018, 2:48 PMorangy
val scriptProperty = SimpleStringProperty()
val evalProperty = scriptProperty.objectBinding { evalScript(it!!)}
modelProperty = evalProperty.objectBinding { makeModel(it) }
Text area is bound to scriptProperty
(btw, how do I bind it unidirectonally from text to scriptProperty?)
textProperty().bindBidirectional(scriptProperty)
and then I bind modelProperty
to a tree as abovecarlw
06/26/2018, 2:49 PMorangy
orangy