09.04.2018 Views

tornadofx-guide

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

5. Data Controls<br />

val persons = listOf(<br />

Person("Mary Hanes", "IT Administration", "mary.hanes@contoso.com", listOf(<br />

Person("Jacob Mays", "IT Help Desk", "jacob.mays@contoso.com"),<br />

Person("John Ramsy", "IT Help Desk", "john.ramsy@contoso.com"))),<br />

Person("Erin James", "Human Resources", "erin.james@contoso.com", listOf(<br />

Person("Erlick Foyes", "Customer Service", "erlick.foyes@contoso.com"),<br />

Person("Steve Folley", "Customer Service", "steve.folley@contoso.com"),<br />

Person("Larry Cable", "Customer Service", "larry.cable@contoso.com")))<br />

).observable()<br />

You can create a TreeTableView by merging the components needed for a TableView and<br />

TreeView together. You will need to call the populate() function as well as set the root<br />

TreeItem .<br />

val treeTableView = TreeTableView().apply {<br />

column("Name", Person::nameProperty)<br />

column("Department", Person::departmentProperty)<br />

column("Email", Person::emailProperty)<br />

/// Create the root item that holds all top level employees<br />

root = TreeItem(Person("Employees by leader", "", "", persons))<br />

// Always return employees under the current person<br />

populate { it.value.employees }<br />

// Expand the two first levels<br />

root.isExpanded = true<br />

root.children.forEach { it.isExpanded = true }<br />

}<br />

// Resize to display all elements on the first two levels<br />

resizeColumnsToFitContent()<br />

It is also possible to work with more of an ad hoc backing store like a Map . That would look<br />

something like this:<br />

66

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!