How to observe changes in glazedlists in griffon?

99 Views Asked by At

I have a griffon 1.5 application with a glazedlist from which i'm trying to observe changes and bind its size() to a field in the view ..

in my model I have

@Bindable timeslotPicks = 0

@Bindable
@PropertyListener (tableChanged) EventList<ProductionLineEntry> table =
        new BasicEventList<ProductionLineEntry>()  ....

.. and

def tableChanged = {evt->
    println "table Changed ... "
    setTimeslotPicks(table.size())
}

Alas my tableChanged event isn't firing .. How can I bind a view field to the current size of my glazedlist ? Thanks in advance ..

2

There are 2 best solutions below

0
user3914455 On BEST ANSWER

I rejigged my model ..

EventList<ProductionLineEntry> table =
        new BasicEventList<ProductionLineEntry>()
...

and removed my tablechanged check ..

In my mvcInit controller method I added ..

 // Add a listener to my list ..
    model.table.addListEventListener(
       {e-> model.timeslotPicks = model.table.size()} as ListEventListener
    )

It now works beautifully ..

Thanks

1
Andres Almiray On

The problem is that you're observing changes made to the table field, and not the contents of the table field as you expect. In other words, the code you've written (the tableChanged closure) reacts when bean.table is updated, for example, when a new EventList is assigned to that field.

You must write a ListChangeListener in order to adapt list changes to list size.