Views
2 months ago

tornadofx-guide

Workspaces The resulting

Workspaces The resulting Workspace consists of a button bar with four default buttons and an empty content area below it. The content area can house any UIComponent . You add a component to the content area by calling workspace.dock() on it. If you show the Workspace without a docked View , it will by default only take up the space needed for the buttons. The window in Figure 16.1 was resized after it was opened. Let's pretend we have a CustomerList component that we would like to dock in the Workspace as the application starts. We do this by overriding the onBeforeShow callback: class MyApp : App(Workspace::class) { override fun onBeforeShow(view: UIComponent) { workspace.dock() } } Figure 16.2 226

Workspaces To keep things focused, we will leave out the CustomerList implementation code which simply displays a TableView with some Customers. What is interesting however, is that the Refresh button in the Workspace was enabled when the CustomerList was docked, while the Save button remained disabled. Leveraging the Workspace buttons Whenever a UIComponent is docked in the Workspace , the Refresh, Save, and Delete buttons will be enabled by default. This happens because the Workspace looks at the refreshable , savable and deletable properties in the docked component. Every UIComponent returns a boolean property with the default value of true , which the Workspace then connects to the enabled state of these buttons. In the CustomerList example, the TornadoFX maintainers made sure the Save button was always disabled by overriding this property: override val savable = SimpleBooleanProperty(false) We can achieve the same result by calling disableSave() in the init block, and the same goes for disableRefresh() and disableDelete() . We did not touch the other buttons, so they remain true as per the default. Whenever the Refresh button is called, it will fire the onRefresh function in the View . You can override this to provide your refresh action: 227

Guide
GUIDE
GUIDE
GUIDE
GUIDE TO
GUIDE
GUIDE
GUIDE
Guide
Guide
Guide
GUIDE
Guide
GUIDE
GUIDE
Guide
guide