My tornadoFx client consumes an api with json resu...
# tornadofx
p
My tornadoFx client consumes an api with json results, literally every model has a SimpleListProperty<datatype>() in it. Here is an example:
Copy code
data class rule(val name: String, val def: String)
class ruleBook{
    val rulesProperty = SimpleListProperty<rule>()
    var rules by rulesProperty
}
class RuleBookVM: ItemViewModel<ruleBook>() {
    val rules = bind(ruleBook::rulesProperty)
}

class TestView : View("Test View") {
    val myRuleBook: RuleBookVM by inject()
    init {
        myRuleBook.rules.value.add(rule("hoge", "fuga"))
    }
    val name = textfield()
    val definition = textfield()
    override val root = vbox{
        label("Test")
        add(name)
        add(definition)
        button("Add a rule").action{
            myRuleBook.rules.value.add(rule(name.text, definition.text))
        }
        tableview(myRuleBook.rules) {
            column("name", rule::name)
            column("def", rule::def)
        }
    }
}
g
William, if you're responding to my stuff, we may be using terms slightly differently. I distinguish Model from Domain. (The rationale: the Domain classes are POJO and it is as an important need to keep them POJO.) My Model classes use ViewModel or ItemViewModel as a base, and they stand in for Domain classes in the UI. The problem I am having is creating the bind in a Model against a domain POJO that contains a List<X> or MutableList<X>.
p
Hmm, is there any reason why you can't use a SimpleListProperty or ObservableList ? (you say you don't want to... but, you need the observable part for the viewmodel to bind and update)
Sorry, I went back and read your comments more closely from the other thread. Basically you're saying you have data class Rule(some definitions) data class RuleBook(some definitions) class RuleBook: ItemViewModel and you want to bind between the item view model and a regular pojo? can't you just add an interim class that translates between a non-fx aware class and the ItemView?
You can always addAll from the mutableList, so you could have 4 classes, 2 for data classes, 1 as backing for the ItemViewModel (that implements an observableList) and 1 ItemViewModel. Then you can use the non-fx aware domain and load it into the ItemViewModel i.e.
Copy code
data class rule(name: String)
data class ruleBook(rules: mutableList<rule>)
class FXruleBook{
  val   rulesProperty = SimpleListProperty<rule>()
 var rules by rulesProperty
}
class RulebookVm: ItemViewModel<ruleBook>() {
 val rules = bind(ruleBook::rulesProperty)
}
then I assume you use a controller to get the data?
Copy code
fun loadData() : UIRuleBook {
   val myNaiveRuleBook =  //load some data into a ruleBook
   val myRuleBook = FXRuleBook()
  myRuleBook.value.addAll(myNaiveRuleBook.rules)
return myRuleBook
}
and then in the view:
Copy code
val MyRuleBook: RuleBookVM by inject()
  async {
     controller.loadData()
 } ui {
    MyRuleBook.item = it
}
My tornadoFx app is a thin client based off of a rest api, so I just have a jsonModel and a viewModel
g
I have one of those, too, and it's a lot easier when I don't have to worry about violating POJO.
p
Yeah, I hear what you're saying. I don't have any need to separate my logic like that since my client is just a thin client based off of an api -- anyway, as far as I know, you need to bridge between your POJO and the UI with an observable list or it won't be "magic". in the ItemViewModel, you can always write a function to get the POJO from the IVM.