Hi,

I have an Async Tree Grid with setCaching(true). After user types into StoreFilterField his search string, is the cache of the tree cleared and the requested items are not found anymore. (Filter tries to load them from the server again.) I need to keep the cache because before filter is fired I make sure (in some other way) that all nodes that fulfill the filter criteria are loaded from the Server into the store. Some matching nodes are on the fourth or even higher level and I need them to be found.

I have created a complete working case as simple as possible to reproduce this unexpected/broken behavior.
Follow these steps in the example below:
- Expand nodes up to level 3
- Filter for "2"

Please let me know if there is any workaround to fix it...

mm.

Client
Code:
public class MyTestCase implements EntryPoint {

      public interface FileModelProperties extends PropertyAccess<FileModel> {
            @Path("id")
            ModelKeyProvider<FileModel> key();

            ValueProvider<FileModel, String> name();
            
            ValueProvider<FileModel, String> path();
            
          }
          
          @Override
          public void onModuleLoad() {
            final GreetingServiceAsync service = GWT.create(GreetingService.class);

            RpcProxy<FileModel, List<FileModel>> proxy = new RpcProxy<FileModel, List<FileModel>>() {
              
              @Override
              public void load(FileModel loadConfig, AsyncCallback<List<FileModel>> callback) {
                service.getFolderChildrenDummy(loadConfig, callback);
              }
            };
            
            final TreeLoader<FileModel> loader = new TreeLoader<FileModel>(proxy) {
              @Override
              public boolean hasChildren(FileModel parent) {
                return parent instanceof FolderModel;
              }
            };
           
            
            FileModelProperties props = GWT.create(FileModelProperties.class);
            
            TreeStore<FileModel> store = new TreeStore<FileModel>(props.key());
            loader.addLoadHandler(new ChildTreeStoreBinding<FileModel>(store));
            
            ColumnConfig<FileModel, String> cc1 = new ColumnConfig<FileModel, String>(props.name(), 300, "Name");
            ColumnConfig<FileModel, String> cc2 = new ColumnConfig<FileModel, String>(props.path(), 300, "Path");
            
            List<ColumnConfig<FileModel, ?>> l = new ArrayList<ColumnConfig<FileModel, ?>>();
            l.add(cc1);
            l.add(cc2);

            ColumnModel<FileModel> cm = new ColumnModel<FileModel>(l);
            
            Window con = new Window();
            con.setHeadingText("Async tree filter bug");
            con.setPixelSize(600, 300);
            con.addStyleName("margin-10");
            
            VerticalLayoutContainer vp = new VerticalLayoutContainer(); 
            TreeGrid<FileModel> tree = new TreeGrid<FileModel>(store, cm, cc1);
            tree.setTreeLoader(loader);
            tree.setBorders(true);
            tree.setTreeLoader(loader);
            tree.setCaching(true);
            tree.getView().setTrackMouseOver(true);
            tree.getView().setAutoExpandColumn(cc2);

            tree.getStyle().setLeafIcon(ExampleImages.INSTANCE.java());
            
            StoreFilterField<FileModel> filter = new StoreFilterField<FileModel>() {
                @Override
                protected boolean doSelect(Store<FileModel> store, FileModel parent, FileModel item,
                        String filter) {
                    return item.getName().toLowerCase().contains(filter.toLowerCase());
                }
            };
            filter.bind(store);
            vp.add(filter);
            vp.add(tree, new VerticalLayoutData(1, 1));
            con.add(vp);
            con.show();
            
          }
}
GreetingService
Code:
@RemoteServiceRelativePath("greet")
public interface GreetingService extends RemoteService {
    List<FileModel> getFolderChildrenDummy(FileModel folder);
}
GreetingServiceAsync
Code:
public interface GreetingServiceAsync {
    void getFolderChildrenDummy(FileModel loadConfig, AsyncCallback<List<FileModel>> callback);
}
Server
Code:
@SuppressWarnings("serial")
public class GreetingServiceImpl extends RemoteServiceServlet implements GreetingService {

    /**
     * Simulating a simple directory structure
     */
    @Override
    public List<FileModel> getFolderChildrenDummy(FileModel folder) {

        List<FileModel> result = new ArrayList<FileModel>();
        int level = 0;
        if (folder == null) {
            folder = new FolderModel("Root", "C:\\");
        } else {
            level = Integer.parseInt(folder.getId().substring(0, folder.getId().indexOf("."))) + 1;
        }

        if (level < 4) {
            FolderModel folderA = new FolderModel(null, null);
            folderA.setName("Subfolder A on level " + level);
            folderA.setPath(folder.getPath() + folderA.getName() + "\\");
            folderA.setId(level + "." + 3);
            result.add(folderA);
        }

        FileModel fileA = new FileModel();
        fileA.setName("File A on level " + level);
        fileA.setPath(folder.getPath() + fileA.getName() + "\\");
        fileA.setId(level + "." + 1);
        result.add(fileA);

        FileModel fileB = new FileModel();
        fileB.setName("File B on level " + level);
        fileB.setPath(folder.getPath() + fileB.getName() + "\\");
        fileB.setId(level + "." + 2);
        result.add(fileB);
        System.out.println("Server Returns " + result.size() + " items for level " + level);
        return result;
    }

}