Remove Item not part of Event

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Remove Item not part of Event

James Cook-12
I have a ListDataListener attached to an EventListModel. When the underlying
list has an item removed, the following listener callback is invoked:

void intervalRemoved(ListDataEvent e);

The ListDataEvent object tells me which index was removed, but the list no
longer holds this element. Is there any way to identify the _object
instance_ that was removed from a list in the ListDataListener callback?




---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Remove Item not part of Event

James Lemieux
Cap'n Cook,
 
     Unfortunately, at this time, GlazedLists only broadcasts *indices* of inserts, updates, and deletes. It doesn't provide access to the elements. You must manufacture this behaviour yourself by maintaining your own private cache of the list data where you need it. GlazedLists can help with keeping this cache in synch, but you must still get your hands dirty to get around this problem.
 
     So, the idea is that GlazedLists helps with a method called GlazedLists.syncEventListToList(EventList source, List target). It links a regular java.util.List with an EventList and keeps it in synch as the EventList changes. Here is a sketch of a class called MemoryList that does what I'm talking about here. It's untested, but should do the job. Feel free to modify it or use it as you need:
 

import java.util.List;
import java.util.ArrayList;

import ca.odell.glazedlists.TransformedList;
import ca.odell.glazedlists.EventList;
import ca.odell.glazedlists.GlazedLists;
import ca.odell.glazedlists.event.ListEvent;

public class MemoryEventList extends TransformedList {

 private List memory = new ArrayList();

 public MemoryEventList(EventList source) {
  super(source);
  // register ourselves FIRST so we are updated before the memory list
  source.addListEventListener(this);
  GlazedLists.syncEventListToList(source, this.memory);
 }

 /**
  * Returns the last "remembered" snapshot of the source list.
  * This can be used to access removed list elements while
  * processing ListEvents from this class.
  */
 public List getMemory() {
  return memory;
 }

 public void listChanged(ListEvent listChanges) {
  updates.forwardEvent(listChanges);
 }

 protected boolean isWritable() {
  return true;
 }
}

Good luck,
 
Jesse James.

 
On 8/10/05, James Cook <[hidden email]> wrote:
I have a ListDataListener attached to an EventListModel. When the underlying
list has an item removed, the following listener callback is invoked:

void intervalRemoved(ListDataEvent e);

The ListDataEvent object tells me which index was removed, but the list no
longer holds this element. Is there any way to identify the _object
instance_ that was removed from a list in the ListDataListener callback?




---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]