PDA

View Full Version : ListStore insertions get removed if filters are enable



larvelljones
27 May 2008, 6:18 AM
I'm not sure this is a bug, but perhaps a misuse of the Store. But if ListStore.insert(..) is called while the base class Store is currently filtering (filtersEnabled==true), the next time filters are applied will remove them (see Store.applyFilters).

I worked around this by adding a method to Store that handles adding items to "all" and changed ListStore to call this method when inserting items.

Store.java:

protected void insertItems(List<M> items, int index) {
if (filtersEnabled) {
all = snapshot;
all.addAll(index, items);
snapshot = all;
} else {
all.addAll(index, items);
}
}ListStore.java:

protected void insert(List<M> items, int index, boolean supressEvent) {
insertModels(items, index);
for (M m : items) {
registerModel(m);
}
if (!supressEvent) {
StoreEvent evt = createStoreEvent();
evt.models = items;
evt.index = index;
fireEvent(Add, evt);
}
}

I forgot about the remove method. But there are other methods in Store that would need to be updated as well. Any that affect the "all" property.