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 />

This more closely resembles the traditional setCellValueFactory() for the JavaFX<br />

TableColumn .<br />

Row Expanders<br />

Later we will learn about the TreeTableView which has a notion of "parent" and "child" rows,<br />

but the constraint with this control is the parent and child must have the same columns.<br />

Fortunately, TornadoFX comes with an awesome utility to not only reveal a "child table" for a<br />

given row, but any kind of Node control.<br />

Say we have two domain types: Region and Branch . A Region is a geographical zone,<br />

and it contains one or more Branch items which are specific business operation locations<br />

(warehouses, distribution centers, etc). Here is a declaration of these types and some given<br />

instances.<br />

class Region(val id: Int, val name: String, val country: String, val branches: Observa<br />

bleList)<br />

class Branch(val id: Int, val facilityCode: String, val city: String, val stateProvince<br />

: String)<br />

val regions = listOf(<br />

Region(1,"Pacific Northwest", "USA",listOf(<br />

Branch(1,"D","Seattle","WA"),<br />

Branch(2,"W","Portland","OR")<br />

).observable()),<br />

Region(2,"Alberta", "Canada",listOf(<br />

Branch(3,"W","Calgary","AB")<br />

).observable()),<br />

Region(3,"Midwest", "USA", listOf(<br />

Branch(4,"D","Chicago","IL"),<br />

Branch(5,"D","Frankfort","KY"),<br />

Branch(6, "W","Indianapolis", "IN")<br />

).observable())<br />

).observable()<br />

We can create a TableView where each row has a rowExpander() function defined, and<br />

there we can arbitrarily create any Node control built off that particular row's item. In this<br />

case, we can nest another TableView for a given Region to show all the Branch items<br />

belonging to it. It will have a "+" button column to expand and show this expanded control<br />

(Figure 5.5).<br />

Figure 5.5<br />

59

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

Saved successfully!

Ooh no, something went wrong!