« Return to Thread: Tracking changes in EventLists

Tracking changes in EventLists

by Witold Szczerba :: Rate this Message:

Reply to Author | View in Thread

Hi there,
I am working with BeansBinding framework in my recent project, there
is a list implementation: ObservableList. I want to use EventLists in
few places, but what stops me right now is the problem with
ListEventListener. What I need is the object which can track changes
on list. I have created a simple tracker for ObservableList. One
tracker can be used for many ObservableLists. It works like this:

ObservableListTracker tracker = new ObservableListTracker();
ObservableList list = ObservableCollections.observableList(new ArrayList());
list.add("1");
list.add("2");
list.add("3");
list.addObservableListListener(tracker);

assertTrue(tracker.isEmpty());

list.add("a");
assertTrue(tracker.getAddedTo(list).contains("a"));
assertFalse(tracker.isEmpty());

list.remove("a");
assertTrue(tracker.getDeletedFrom(list).isEmpty());
assertTrue(tracker.getAddedTo(list).isEmpty());
assertTrue(tracker.isEmpty());

list.remove("3");
assertTrue(tracker.getDeletedFrom(list).contains("3"));
assertFalse(tracker.isEmpty());

list.clearAll();
assertTrue(tracker.getDeletedFrom(list).contains("3"));
assertTrue(tracker.getDeletedFrom(list).contains("2"));
assertTrue(tracker.getDeletedFrom(list).contains("1"));
assertFalse(tracker.isEmpty());

tracker.reset();
assertTrue(tracker.getDeletedFrom(list).isEmpty());
assertTrue(tracker.getAddedTo(list).isEmpty());
assertTrue(tracker.isEmpty());


I was trying to create such a tracker for EventList, but it is not
that easy, because when elements are removed from EventList, the
ListEvent is unable to tell me what element was removed. All it tells
me is: there was _something_ on index X - but that is not enough.

My question is: maybe some of you have created such an object I could
use to track changes?
Or maybe you have some ideas how to implement this efficiently?

Regards,
Witold Szczerba

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...

 « Return to Thread: Tracking changes in EventLists