Results 1 to 4 of 4

Thread: TreeStore does not fire add events when store is sorted

    Success! Looks like we've fixed this one. According to our records the fix was applied for EXTGWT-2338 in internal.
  1. #1
    Ext GWT Premium Member
    Join Date
    Oct 2007
    Posts
    44

    Exclamation TreeStore does not fire add events when store is sorted

    Hey,

    there is a bug in TreeStore's insert method which results in not fireing insert events in case the store is sorted. Here is the code of the method:

    PHP Code:
    private void insert(TreeModel parentint index, List<Mchildrenboolean suppressEvent) {
        
    int initialCount parent.getChildren().size();
        
    parent.addChildren(indexwrap(children));

        if (
    initialCount != parent.getChildren().size()) {
          List<
    MaddedChildren = new ArrayList<M>();
          List<
    TreeModelcurrentChildren parent.getChildren();
          
    int i index;
          for (
    M child children) {
            if (
    currentChildren.get(i).getData() == child) {
              
    addedChildren.add(child);
              
    i++;
            }
          }
          if (!
    suppressEvent && addedChildren.size() != 0) {
            
    fireEvent(new StoreAddEvent<M>(indexaddedChildren));
          }
        }
      } 
    In the second line the new children are added to the parent. However, addChildern does the following, if the store is sorted:
    PHP Code:
        public void addChildren(int index, List<TreeModelchildren) {
          if (
    isSorted()) {
            
    // if sorted we should rebuild the local list, index is ignored
            
    this.children.addAll(children);
            
    Collections.sort(this.childrenbuildWrappedFullComparator()); 
    i.e., it ignores the index and adds the children to their respective positions (which is the expected behaviour for a sorted store). If we now go back and look at when StoreAddEvents are actually fired we see that they are only fired if addedChildren is not empty. The problem is that objects are only added to the addedChildren list if they are at the exact position given by index which of course they are now not (with high probability) as the index was ignored.

    The only workaround I could figure out is to remove the sorting before adding elements as I cannot override the private method.

  2. #2
    Sencha User
    Join Date
    Oct 2009
    Location
    Redwood City, California
    Posts
    402

    Default

    Thanks for the detailed report and investigation. Like you mentioned, there doesn't seem to be a good way of working around this issue in your project. It is plausible that you could create your own wrapper class around TreeStore and delegate most methods to an internal GXT TreeStore instance as a very temporary fix. This is not a reasonable solution for maintained production code.

    As a result, I've filed a bug against the team and will have our engineers take a look. I'll update here as soon as we have a fix available.

  3. #3
    Ext GWT Premium Member
    Join Date
    Oct 2007
    Posts
    44

    Default

    Hey WesleyMoy,

    for now I've pretty much gone with the wrapper workaround, but I'd be happy to see this fixed in the next version. Do you have any plans on when it should come out?

  4. #4
    Sencha User
    Join Date
    Feb 2009
    Location
    Minnesota
    Posts
    2,737

    Default

    Apologies for the delay, this was fixed in 3.0.1, and should be working in every version since then.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •