Success! Looks like we've fixed this one. According to our records the fix was applied for EXTGWT-2554 in a recent build.
  1. #1
    Sencha User
    Join Date
    Jul 2011
    Posts
    126
    Vote Rating
    12
    Andreas Samjeske will become famous soon enough

      0  

    Default AssertionError on ListStore.addAll() when sorted and filtered

    AssertionError on ListStore.addAll() when sorted and filtered


    GXT Version 3.0.0b

    I got this error:
    Code:
    ...Caused by: java.lang.AssertionError
        at com.sencha.gxt.core.client.dom.XElement$.as(XElement.java:112)
        at com.sencha.gxt.widget.core.client.grid.GridView.fly(GridView.java:1591)
        at com.sencha.gxt.widget.core.client.grid.GridView.processRows(GridView.java:2464)
        at com.sencha.gxt.widget.core.client.grid.GridView.insertRows(GridView.java:2091)
        at com.sencha.gxt.widget.core.client.grid.GridView.onAdd(GridView.java:2173)
        at com.sencha.gxt.widget.core.client.grid.GridView$10.onAdd(GridView.java:1978)
        at com.sencha.gxt.data.shared.event.StoreAddEvent.dispatch(StoreAddEvent.java:125)
        at com.sencha.gxt.data.shared.event.StoreAddEvent.dispatch(StoreAddEvent.java:1)
        at com.google.gwt.event.shared.GwtEvent.dispatch(GwtEvent.java:1)
        at com.google.web.bindery.event.shared.EventBus.dispatchEvent(EventBus.java:40)
        at com.google.web.bindery.event.shared.SimpleEventBus.doFire(SimpleEventBus.java:193)
        at com.google.web.bindery.event.shared.SimpleEventBus.fireEvent(SimpleEventBus.java:88)
        at com.google.gwt.event.shared.HandlerManager.fireEvent(HandlerManager.java:127)
        at com.sencha.gxt.data.shared.Store.fireEvent(Store.java:609)
        at com.sencha.gxt.data.shared.ListStore.fireSortedAddEvents(ListStore.java:379)
        at com.sencha.gxt.data.shared.ListStore.addAll(ListStore.java:145)
        at com.sencha.gxt.data.shared.ListStore.addAll(ListStore.java:113)
    ...
    Steps to reproduce:
    - Create a ListStore
    - apply SortInfo
    - add a Filter and activate it
    - add items to ListStore via addAll(items)

    If some of these items don't make it to visibility due to the active filter, error above arises.
    (If all or none of the added items get shown, every thing is fine.)

    Why is this?

    addAll calls fireSortedAddEvents(items), with items being all added itmes, instead of all visible items.
    Code:
      public boolean addAll(int index, Collection<? extends M> items) {
    
        // re-apply filters, checking only newly appended items
        if (isFiltered()) {
          // TODO filter events?
          List<M> inserted = new ArrayList<M>();
          for (M item : items) {
            if (!isFilteredOut(item)) {
              inserted.add(item);
            }
          }
          int actualIndex = index == 0 ? 0 : allItems.indexOf(visibleItems.get(index - 1)) + 1;
          visibleItems.addAll(index, inserted);
          allItems.addAll(actualIndex, items);
    
          if (isSorted()) {
            // no slower than 2.x, and easier to implement
            applySort(true);
          }
          if (inserted.size() != 0) {
    
            if (isSorted()) {
              fireSortedAddEvents(items);    <<<<<=====================
            } else {
              fireEvent(new StoreAddEvent<M>(visibleItems.size(), inserted));
            }
          }
        } else {
          allItems.addAll(index, items);
          if (isSorted()) {
            // no slower than 2.x, and easier to implement
            applySort(true);
    
            fireSortedAddEvents(items);
    
          } else {
            fireEvent(new StoreAddEvent<M>(index, new ArrayList<M>(items)));
          }
        }
        return true;
      }
    indexOf(m) only looks for visible items. So it delivers -1 for non-visible ones. This leads to the error.
    Code:
      protected void fireSortedAddEvents(Collection<? extends M> items) {
        TreeSet<StoreAddEvent<M>> events = new TreeSet<StoreAddEvent<M>>(new Comparator<StoreAddEvent<M>>() {
          @Override
          public int compare(StoreAddEvent<M> o1, StoreAddEvent<M> o2) {
            return o1.getIndex() - o2.getIndex();
          }
        });
        for (M m : items) {
          int idx = indexOf(m);      <<<<<<<==================
          events.add(new StoreAddEvent<M>(idx, m));
        }
        for (StoreAddEvent<M> event : events) {
          fireEvent(event);
        }
      }

    My workaround at the moment:
    disable Filters before addAll()-Call, then activate Filters
    Code:
            listStore.setEnableFilters(false);
            listStore.addAll(items);
            listStore.setEnableFilters(true);

  2. #2
    Sencha - GXT Dev Team
    Join Date
    Feb 2009
    Location
    Minnesota
    Posts
    2,733
    Vote Rating
    90
    Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light

      0  

    Default


    Thanks for the report (and sorry for catching you in the spam filter). Your in-depth analysis is very much apreciated, as is your workaround.

    When this is fixed, we'll add a test that only events fire on visible items while filtered. We'll update this thread when a fix is available.

  3. #3
    Sencha - GXT Dev Team
    Join Date
    Feb 2009
    Location
    Minnesota
    Posts
    2,733
    Vote Rating
    90
    Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light

      0  

    Default


    This has been fixed in SVN, along with additional unit tests added to ensure that future changes don't affect this. This will be available in the next release.

Thread Participants: 1

Tags for this Thread