package net.sourceforge.tuned; import java.util.List; import ca.odell.glazedlists.EventList; import ca.odell.glazedlists.event.ListEvent; import ca.odell.glazedlists.event.ListEventListener; public class ListChangeSynchronizer implements ListEventListener { private final List target; public ListChangeSynchronizer(EventList source, List target) { this.target = target; source.addListEventListener(this); } public void listChanged(ListEvent listChanges) { EventList source = listChanges.getSourceList(); // update target list while (listChanges.next()) { int index = listChanges.getIndex(); int type = listChanges.getType(); switch (type) { case ListEvent.INSERT: target.add(index, source.get(index)); break; case ListEvent.UPDATE: target.set(index, source.get(index)); break; case ListEvent.DELETE: target.remove(index); break; } } } public static ListChangeSynchronizer syncEventListToList(EventList source, List target) { return new ListChangeSynchronizer(source, target); } }