Views
6 months ago

tornadofx-guide

Workspaces class

Workspaces class CustomerEditor : Fragment("Customer Editor") { val customer: CustomerModel by inject() override val savable = customer.dirty override val headingProperty = customer.fullName override val root = form { fieldset("Customer Details") { field("First Name") { textfield(customer.firstName) } field("Last Name") { textfield(customer.lastName) } } } override fun onSave() { } customer.commit() } override fun onRefresh() { } customer.rollback() The customer model is injected, and will contain the selected customer from the list. The savable property is bound to the dirty property of the model and the headingProperty is bound to a StringBinding called fullName , which concatinates the first and last names and updates whenever they are changed. The form fields bind to the name properties and lastly the onSave and onRefresh functions are implemented to react to the corresponding Workspace buttons. Figure 16.6 236

Workspaces We can see that the title and heading are indeed displaying separate information. Since we haven't made any edits yet, the Save button is disabled, while the Refresh button is available, and would roll back any changes made since the last commit. The back button is enabled as well, and clicking it would navigate back to the Customer list. This is a very powerful feature which enables browser like navigation in your application with very little effort on your part. The Workspace keeps a navigation stack of configurable depth. By default it will contain 10 previously docked views. You can configure the maxViewStackDepth to change the number of views held in the navigation stack. Alternative to overriding onSave and onRefresh Some times you want to access an object in one of the workbench button actions but you want to avoid creating a variable for that object. Instead you can use the whenSaved and whenRefreshed callbacks, which can be configured from anywhere. Important: They are alternatives to onSave and onRefresh so you should only do one or the other. Let's say we want to refresh a TableView when the Refresh button is clicked. We can configure this inside the builder for the TableView: 237

GUIDE
GUIDE
Guide
Guide
GUIDE
GUIDE
GUIDE
GUIDE
guide
GUIDE
Guide
GUIDE
Guide