Views
1 week ago

tornadofx-guide

Workspaces Some use

Workspaces Some use cases might require you to make sure that the user cannot go back to a certain view after he has navigated to the prior view. You can remove your self from the View Stack on unDock like this: override fun onUndock() { } workspace.viewStack.remove(this) Docking multiple views in the editor area The Workspace provides an alternative way to navigate between views. Instead of back and forward buttons, you can choose to dock multiple views inside a TabPane in the editor area. The Workspace has a navigationMode property that lets you change how the views are represented in the editor area. The default is Workspace.NavigationMode.Stack . The following example creates a tabbed Workspace that automatically docks two views inside it when it's created: class TabbedWorkspace: Workspace("Tabbed Workspace", NavigationMode.Tabs) { init { dock() dock() } } Figure 16.7 240

Workspaces A Workspace in Tabs mode automatically hides the navigation buttons as they are no longer needed You can create a starting point for this Workspace from a normal App class: class TabbedWorkspaceApp : App(TabbedWorkspace::class) The views docked inside the Workspace tabs will have their onDock function called whenever they are added and also when they are subsequently chosen as the active Tab. Correspondingly, the onUndock function is called whenever it is no longer the active Tab, as well as when it's removed from the TabPane using the close button on the tab. You can control the closable state of a View docked inside the TabPane via the closeable property in UIComponent . It returns a BooleanExpression with the default value of true but you can override it to bind against another property or simply return another SimpleBooleanValue(false) to make it uncloseable. This example makes sure you cannot close the tab before the CustomerModel inside it is committed or rolled back: class CustomerEditor : View("Customer Editor") { val customer: CustomerModel by inject() override val closeable = customer.dirty.not() } 241

Guide
guide
GUIDE
guide
Guide
Guide
GUIDE
A guide
Guide