Views
5 months ago

tornadofx-guide

Workspaces You will

Workspaces You will notice that the Save button is enabled in this View. This is because the savable property is bound to the dirty state property of the view model: val model: CustomerModel by inject() override val savable = model.dirty When a customer is loaded, the Save button will stay disabled until an edit has been made. To save, we override the onSave function: override fun onSave() { runAsync { customerController.save(customer.item) } ui { saved -> customer.update(saved) } } This particular customerController.save call will return the Customer from the server once it is saved. If the server made any changes to our customer object, they would have been reflected in the saved customer we got back. For that reason, we call customer.update(saved) which is function you get for free if you implement JsonModel . This makes sure that changes from the server is pushed back into the model. This is completely optional, and you might just want to do customerController.save(customer.item) . 232

Workspaces Title and heading When a view is docked, the title of the Workspace will match the title of that view. There is also a heading text in the workspace that by default shows the same text as the title. The heading can be overriden by assigning to the heading variable or binding to the headingProperty property. If you want to completely remove the heading, augment the workspace with workspace.headingContainer.removeFromParent() or just hide it. You can also put whatever nodes you want inside the heading container. You saw this trick in the CRM screenshot, where a Gravator icon was placed to the left of the customer name. Dynamic elements in the ToolBar Some views might need more buttons or functionality added to the ToolBar, but once you navigate away from the view it wouldn't make sense to keep them around. The Workspace will actually track whatever elements you add to it while a view is docked and remove those changes when the view is undocked. The perfect place to add these extra buttons would be the onDock call of the view. Every UIComponent has a property called workspace which will point to the current Workspace for the current Scope. Let's add an "Add Customer" button to the Workspace whenever the CustomerList is docked: override fun onDock() { with (workspace) { button("Add Customer").action { addCustomer() } } } The Workspace will now look like in Figure 16.4 233

guide
Guide
GUIDE
Guide
GUIDE
guide
Guide
A guide
Guide
GUIDE