I have a class Market
which contains a collection of MarketUpdate
objects called m_updates
. For the UI I am using type-safe builders to create columns in a tableview like so:
override val root = tableview<Market> {
val sortedMarketList = SortedList<Market>(markets)
sortedMarketList.comparatorProperty().bind(this.comparatorProperty())
items = sortedMarketList
...
column("Strikes", Market::m_strikes)
...
The m_strikes
property is just a SimpleIntegerProperty directly owned by a Market
object. However, I need to be able to build columns like these:
...
column("Created At", Market::m_updates::first::m_time)
...
...
column("Last Update", Market::m_updates::last::m_time)
...
where m_time
is a SimpleLongProperty owned by a MarketUpdate
object. When a Market
object is updated, a new MarketUpdate
object is added to the end of the m_updates
collection. This means that the binding needs to automatically transition from one object to another, and that the tableview needs to be notified and update itself to reflect the data in the new object. I think binding by way of the first()
and last()
functions of the collection as described above captures the idea in a very simple way, but it won't compile.
There are many properties like m_strikes
and m_time
. How can I achieve this gracefully?
If I understand your use case, what you want to do is to create an observable value that represents the time property for the first and last updates in a given
Market
object. To do that, you can create anobjectBinding
based on theupdates
list inside of eachMarket
object, then extract thefirst()
orlast()
element'stimeProperty
. In the following example, the TableView will update as soon as you augment the updates list in anyMarket
object.Bear in mind that the example requires each
Market
to have at least one update. If this isn't your case, make sure to handle null accordingly.I've used a SortedFilteredList to make it easier to deal with sorting. The reason sort works here, is that the columns are actually represented by LocalDateTime values.
I hope this gives you some ideas :)