This repository was archived by the owner on Sep 28, 2024. It is now read-only.

Description
Using this guide: https://docs.tornadofx.io/0_subsection/11_editing_models_and_validation
I created a custom View that displays a "FolderModel" class, which holds a nameProperty and a pathProperty.
In the example
private fun editPerson(person: Person?) {
if (person != null) {
prevSelection?.apply {
nameProperty.unbindBidirectional(nameField.textProperty())
titleProperty.unbindBidirectional(titleField.textProperty())
}
nameField.bind(person.nameProperty)
titleField.bind(person.titleProperty)
prevSelection = person
}
}
binds both String properties to the appropriate fields and unbinds the previous selection as needed.
When trying to recreate this, I run into the problem of unbinding the previous model from the textfield bound to it:
if(currentFolder != null) {
currentFolder?.apply {
nameProperty.unbindBidirectional(nameField.textProperty())
pathProperty.unbindBidirectional(pathField.textProperty()) // <-- this won't compile because pathProperty is an ObjectProperty<Path>!
}
}
nameField.bind(folder.nameProperty)
pathField.bind(folder.pathProperty, converter = object: StringConverter<Path>() {
override fun toString(path: Path?): String = path?.toString() ?: ""
override fun fromString(string: String?): Path? = string?.let { try { Path.of(string) } catch (e: Exception) { null } }
})
currentFolder = folder
What's the proper way to unbind an ObjectProperty from a TextField after it's bound using a StringConverter?