class Person(var id : Long, var name : String) class SimpleVM1_ViewModel : ViewModel() { val persons = mutableListOf( Person(1L, "Carl"), Person( 2L, "Edvin"), Person( 3L, "Thomas") ).observable() fun save(p : Person) { // should only be one val index = persons.indexOfFirst { it.id == p.id } // someone else might have deleted it b/c multiple windows if( index != -1 ) persons.set( index, p ) } } class SimpleVM1_DetailsFragment : Fragment() { val vm : SimpleVM1_ViewModel by inject() val person : Person by param() val id_p = SimpleLongProperty() val name = SimpleStringProperty() override val root = vbox { gridpane { row { label("ID") textfield(id_p) { isEditable = false } } row { label("Name") textfield(name) } padding = Insets(10.0) spacing = 4.0 } separator() buttonbar { button("Save") { setOnAction { vm.save(Person(id_p.value, name.value)) close() } } button("Cancel") { setOnAction { close() } } padding = Insets(10.0) } } override fun onDock() { id_p.value = person.id name.value = person.name title = "Person ${person.id}" } } class SimpleVM1_MasterView : View("Simple VM1 Example") { val vm : SimpleVM1_ViewModel by inject() override val root = vbox { tableview(vm.persons) { column("ID", Person::id) column("Name", Person::name) onUserSelect { find( mapOf(SimpleVM1_DetailsFragment::person to it) ).openWindow() } } } } class SimpleVM1_App : App(SimpleVM1_MasterView::class) fun main(args : Array) { Application.launch(SimpleVM1_App::class.java, *args) }