Tornadofx tableview sync two tables
<p>Basic newbie question:</p>

<p>I want to sync/bind two tables.<br>
For keeping the example simple, I have used two separate table views. This needs to be done using fragments and scope, which I thought would complicate the question as I am stuck at a basic problem.<br>
Behaviour: On clicking the sync button of table 1 , I want <strong>table 1 selected data to override the corresponding table 2 data</strong>. and vice-versa</p>

<p>Person Model:</p>

<pre><code>class Person(firstName: String = "", lastName: String = "") {
    val firstNameProperty = SimpleStringProperty(firstName)
    var firstName by firstNameProperty
    val lastNameProperty = SimpleStringProperty(lastName)
    var lastName by lastNameProperty
}

class PersonModel : ItemViewModel&lt;Person&gt;() {
    val firstName = bind { item?.firstNameProperty }
    val lastName = bind { item?.lastNameProperty }
}
</code></pre>

<p>Person Controller (dummy data):</p>

<pre><code>class PersonController : Controller(){
    val persons = FXCollections.observableArrayList&lt;Person&gt;()
    val newPersons = FXCollections.observableArrayList&lt;Person&gt;()
    init {
        persons += Person("Dead", "Stark")
        persons += Person("Tyrion", "Lannister")
        persons += Person("Arya", "Stark")
        persons += Person("Daenerys", "Targaryen")

        newPersons += Person("Ned", "Stark")
        newPersons += Person("Tyrion", "Janitor")
        newPersons += Person("Arya", "Stark")
        newPersons += Person("Taenerys", "Dargaryen")
    }
}
</code></pre>

<p>Person List View:</p>

<pre><code>class PersonList : View() {
    val ctrl: PersonController by inject()
    val model : PersonModel by inject()
    var personTable : TableView&lt;Person&gt; by singleAssign()
    override val root = VBox()
    init {
        with(root) {
            tableview(ctrl.persons) {
                personTable = this
                column("First Name", Person::firstNameProperty)
                column("Last Name", Person::lastNameProperty)
                columnResizePolicy = SmartResize.POLICY
            }
            hbox {
                button("Sync") {
                    setOnAction {
                        personTable.bindSelected(model)
                        //model.itemProperty.bind(personTable.selectionModel.selectedItemProperty())
                    }
                }
            }
        }
    }
</code></pre>

<p>Another Person List View:</p>

<pre><code>class AnotherPersonList : View() {
    val model : PersonModel by inject()
    val ctrl: PersonController by inject()
    override val root = VBox()
    var newPersonTable : TableView&lt;Person&gt; by singleAssign()
    init {
        with(root) {
            tableview(ctrl.newPersons) {
                newPersonTable = this
                column("First Name", Person::firstNameProperty)
                column("Last Name", Person::lastNameProperty)
                columnResizePolicy = SmartResize.POLICY
            }
            hbox {
                button("Sync") {
                    setOnAction {
                        newPersonTable.bindSelected(model)
                    }
                }
            }
        }
    }
}
</code></pre>

<p><a href="https://i.stack.imgur.com/lrbkO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lrbkO.png" alt="Sync Two Tables"></a></p>