View Full Version : DnD removes cache for expandable nodes?

9 Nov 2011, 9:42 AM

I'm working on DnD tree. To populate store i'm using loader which makes calls to the RPC service. The service retrieves data from the database using Groovy service.
Before, when I was moving the expandable node (i mean the node which has children), if it was already loaded (store contains BeanModel of this node) it stayed loaded. So when I was expanding it after drop the data was taken from the store cache. It was fine for me.
But now, when i drop the expandable node even if it's already loaded, after drop if i click on expand, the store calls the loader and so retrieves the data from DB, so i'm getting differences between BeanModel data of this node and the rest store data. For example imagine that node A has 2 children, B and C. I move child C to a new parent (let's call it node N). And then i move node A to a new parent also. When i expand it, i can see, that child C acting like it's still belongs to node A, but herewith it's situated in a different place in tree panel.
As i can see it happened after upgrading to the version 2.2.5 from 2.2.4, can anyone approve this problem? Or maybe share some workaround?

25 Nov 2011, 1:46 AM
Ok, i got through all DnD chain. After drop all the data are in cache (the all variable of treestore class, which is a map of all objects loaded in store), but the node parameter loaded is false, so on expand treepanel makes a call to loader and gets results from DB.
Still cannot figure at what point node gets this loaded=false status, but probably this is a problem of GWT, not GXT.

25 Nov 2011, 7:38 AM
Ok, so after a while i got that there is a methos register(M m) in a TreePanel class, which at line 1470 puts newly loaded nodes to javaMap "cache". It uses id "x-auto-21_x-auto-#" as a key and "new TreeNode(id, m)" as a value.

nodes.put(id, new TreeNode(id, m));
Sometimes when the new node is created, the loaded variable is false, so it goes to this cache with such status.

private boolean childrenRendered;
private boolean expand, checked, expandDeep;
private boolean expanded;
private boolean leaf = true;
private boolean loaded;
private boolean loading;

TreeNode(String id, M m) {
this.id = id;
this.m = m;
Then, on DnD when the model is inserting, the node is being taken from this javaMap cache, so it gets this loaded=false status even if it was already expanded and loaded. That's why when i try to expand it, TreeStore makes call to loader...

Ok. Finally.
After drop the store unregister the model and removes it from a cache variable

TreeNode n = null;
if (useKeyProvider) {
n = nodes.remove(generateModelId(m));
} else {
n = nodes.remove(cache.remove(m));

then, when the node is added to new parent the register method is being called and at some point it checks if the node is in cache, then it's id will be used

String id = cache.get(m);
if (id == null) {
id = generateModelId(m);
cache.put(m, id);
nodes.put(id, new TreeNode(id, m));

but as it not in cache for that time, the new instance of TreeNode for dropped model will be created and therefor "loaded" value will be wet to false.

The thing is, that all the children of dropped model are also being added to cache and registered, but because of this "loaded=false" on expand the data is taken from the DB.

It seems for me like a bug or some lack of logic.