|
View:
New views
5 Messages
—
Rating Filter:
Alert me
|
|
|
Tracking changes in EventListsHi 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@... |
|
|
re: Tracking changes in EventListsI may be wrong, but my understanding is that this is probably the biggest outstanding issue with GL... I've run up against it a number of times trying to sync different data structures to EventList... Knowing what item was actually removed is just absolutely critical for a large number of use-cases.
The workaround that I've seen posted (you may want to search the list archives) has been to keep a local cache of the list that can be queried for the removed element. That certainly doesn't meet the 'efficient' requirement.
I know that a bit of work has been done to make delete events hold the removed element reference, but my understanding is that there are some challenges with getting this shoe-horned into the existing API.
Personally, I'd love to know what the issues are, and maybe take a crack at solving them - lack of reference to the removed element causes us all sorts of problems.
Does anyone with a bit more history with GL know what the issues are?
- K
----------------------- Original Message -----------------------
From: Witold Szczerba pljosh.mail@...
To: users@...
Cc:
Date: Tue, 7 Jul 2009 11:07:45 +0200
Subject: Tracking changes in EventLists
Hi there,
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...
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@... |
|
|
Re: Tracking changes in EventListsHey guys,
Right before Jesse's hiatus, we worked on the solution to this problem. In fact, it is implemented for MOST transformations (and simply disabled atm). The issue is that we have a couple REALLY difficult transformations to support this on (GroupingList is one I remember), which we butted up against. We tried and failed a couple times, and thought about reattempting a ground up reimplementation of GroupingList... and that's about where it was left. The workaround is as Kevin described: keep your own local cache, which you update as the source changes. A couple other considerations for you in this space: 1) TransactionList can buffer things for you, if that somehow helps. 2) UndoRedoManager can also track changes and undo/redo them, if that's somehow useful to you. James On Tue, Jul 7, 2009 at 2:31 PM, Kevin Day <kevin@...> wrote:
|
|
|
Re: Tracking changes in EventLists2009/7/27 James Lemieux <jplemieux@...>:
> [...] A couple other considerations for you in > this space: > > 1) TransactionList can buffer things for you, if that somehow helps. > > 2) UndoRedoManager can also track changes and undo/redo them, if that's > somehow useful to you. All I actually need is to query for changes, like in my example: tracker.getDeletedFrom(someList) tracker.getAddedTo(someList); This is because the application is just a front-end to system deployed on application server. When user, for example, gets list of cars, then add two cars and removes three of them and presses "save" I am sending to server information: get rid of cars id=[23,45,98] and then add two new cars [car1=...., car2=....] which is eventually translated into 'delete from Cars where id=....' 'insert into cars (....) values (...)' So I really do not need to buffer changes; when I want to get rid of them, I can just download data from server again and reset the tracker. Other thing is: I need it only for simple lists, not for the transformations. I think that it all would get so trivial if such a "tracker" could be installed only on the lists which are actually a source of data, not some kind of transformations... but that could break the EventList interface transparency. On the other hand, if BasicEventList would have extra methods for trackers... :) Regards, Witold Szczerba --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@... For additional commands, e-mail: users-help@... |
|
|
Re: Tracking changes in EventListsThis could be easily accomplished if your data objects modeled whether they are:
isModified(), isCreated() or isDeleted(). Creating 3 FilterLists immediately derived from your BasicEventList would then answer your questions for you. Alternatively, you simply want to write your own ListEventListener (with a cache of the source EventList so you can look up deleted items after the fact). That's a pretty small amount of code... less than 20 lines for sure. You'd install that ListEventListener on your BasicEventList and then query it later for the changes, as you outlined in your code. Are you having troubles writing this ListEventListener (which you call tracker)? Are you uncomfortable with caching the values of the source list for the benefit of retrieving DELETED items? James On Sun, Jul 26, 2009 at 11:53 PM, Witold Szczerba <pljosh.mail@...> wrote: 2009/7/27 James Lemieux <jplemieux@...>: |
| Free embeddable forum powered by Nabble | Forum Help |