A have a bean (POJO-like) and want to make model for GUI component of it. So I need to notify about each property change in order GUI component can reflect.
How to do this? Should I put notification and listener storage code just inside my bean? But this will make it "dirty". May be write some wrapper? But this will duplicate getters and setters.
Are there any libraries and/or helper objects for this in Commons or somewhere else?
UPDATE
Also suppose I have AbstractList<E>
implementation. How to "propertize" it quickly, i.e. make it to notify listeners about changes? For example, by firing ListDataEvent
. I know I can implement AbstractListModel<E>
instead of AbstractList<E>
but it looks worse. I wish to stay mostly "pojo-like"...
Take a look at
FXCollections
(JDK 7):This will result into an output:
You can either make use of something like
PropertyChangeSuppport
or roll your own, for example...