albrechtroehm
08/07/2019, 2:10 PMclass House(name: String = "", rooms: List<Room> = emptyList()) : NamedObject(name)
{
val roomsProperty = SimpleListProperty<Room>(this, "rooms ",rooms.asObservable())
var rooms : ObservableList<Room> by roomsProperty
}
class HouseModel(house: ObjectProperty<House>) : ItemViewModel<House>(itemProperty = house)
{
val name = bind(House::nameProperty)
val rooms = bind(House::roomsProperty)
}
...
class HouseListFragment : ListCellFragment<House>() {
private val controller by inject<QuotationController>()
private val house = HouseModel(itemProperty)
override val root = vbox {
hbox {
vbox {
removeWhen { editingProperty }
label(house.name) {
setId(Styles.contentLabel)
hgrow = Priority.ALWAYS
useMaxSize = true
}
label(house.rooms.value.size.toString())
label(" rooms ") {}
}
}
}
}
Doing something like private val roomNumber = SimpleIntegerProperty(house.rooms.value.size)
always gives me 0 for a house which should have 3 roomsalbrechtroehm
08/07/2019, 2:39 PMprivate val roomNumber = integerBinding(house.rooms.value) {count() }
also returns displays as 0albrechtroehm
08/07/2019, 3:49 PMclass HouseModel : ItemViewModel<House>()
{
val name = bind(House::nameProperty)
val rooms = bind(House::roomsProperty)
}
class HouseListFragment : ListCellFragment<House>()
{
private val controller by inject<QuotationController>()
private val house = HouseModel().bindTo(this)
override val root = vbox {
hbox {
vbox {
removeWhen { editingProperty }
label(house.name) {
setId(Styles.contentLabel)
hgrow = Priority.ALWAYS
useMaxSize = true
}
label(stringBinding(house.rooms) { "${value?.size} rooms in this house" })
}
albrechtroehm
08/07/2019, 3:57 PM