Views
5 months ago

tornadofx-guide

11. Editing Models and

11. Editing Models and Validation for more information about partial commit, and the corresponding partial validation features. TableViewEditModel If you are pressed for screen real estate and do not have space for a master/detail setup with a TableView , an effective option is to edit the TableView directly. By enabling a few streamlined features in TornadoFX, you can not only enable easy cell editing but also enable dirty state tracking, committing, and rollback. By calling enableCellEditing() and enableDirtyTracking() , as well as accessing the tableViewEditModel property of a TableView , you can easily enable this functionality. When you edit a cell, a blue flag will indicate its dirty state. Calling rollback() will revert dirty cells to their original values, whereas commit() will set the current values as the new baseline (and remove all dirty state history). 174

11. Editing Models and Validation import tornadofx.* class MyApp: App(MyView::class) class MyView : View("My View") { val controller: CustomerController by inject() var tableViewEditModel: TableViewEditModel by singleAssign() override val root = borderpane { top = buttonbar { button("COMMIT").setOnAction { tableViewEditModel.commit() } button("ROLLBACK").setOnAction { tableViewEditModel.rollback() } } center = tableview { items = controller.customers isEditable = true column("ID",Customer::idProperty) column("FIRST NAME", Customer::firstNameProperty).makeEditable() column("LAST NAME", Customer::lastNameProperty).makeEditable() enableCellEditing() //enables easier cell navigation/editing enableDirtyTracking() //flags cells that are dirty } } } tableViewEditModel = editModel class CustomerController : Controller() { val customers = listOf( Customer(1, "Marley", "John"), Customer(2, "Schmidt", "Ally"), Customer(3, "Johnson", "Eric") ).observable() } class Customer(id: Int, lastName: String, firstName: String) { val lastNameProperty = SimpleStringProperty(this, "lastName", lastName) var lastName by lastNameProperty val firstNameProperty = SimpleStringPorperty(this, "firstName", firstName) var firstName by firstNameProperty val idProperty = SimpleIntegerProperty(this, "id", id) var id by idProperty } 175

GUIDE
Guide
Guide
GUIDE
GUIDE
Guide
Guide
GUIDE
Guide
GUIDE
GUIDE
GUIDE