Let's say you have a POJO like
Employee, and you want to make changes to the fields in the POJO observable. What's the best way to do this? The listeners should be able to register for change events, without necessarily subscribing to every property.
I could create an
ObservableEmployeeHelper that takes an employee and wraps each of the fields in Simple*Property objects, and then fires notifications whenever any of those properties change. But it would be nice for the listeners to be able to pick and choose what they want to listen to -- something like this:
addListener(EmployeeEvent.ALL, new ChangeListener<ObservableEmployeeHelper>(){...});
or
addListener(EmployeeEvent.SALARY_CHANGE, new ChangeListener<ObservableEmployeeHelper>(){...});
The other problem is that the ListCell and TableCell's really don't know how to deal with a change to the POJO instead of to the a single observable attribute. For example, if Employee has a
status field (ON_HOLIDAY, ON_SICK_LEAVE, ON_SITE, WORKING_FROM HOME) and you want to display an icon next to the user's name indicating this status. It's difficult to do in way that automatically updates the icon in a list whenever you change the status. My hack for this to attach a listener to the Employee observable status property and watch for changes. But this can lead quickly to memory leaks if not done well.
And currently if you put the Observable POJOs into an ObservableList, you won't get notified if a particular POJO changes, only if the entire list changes.
Is there an easier way to watch for changes to any field in a POJO?
It would be nice if there was an @Observable annotation that you could just add to the fields of your POJO and some kind of mixin that you could add to the class that would propagate changes, register listeners, etc.
Edited by: mfortner on Aug 6, 2012 5:00 PM