PDA

View Full Version : bug in tree ?


chuckgom1
02-14-2009, 10:34 AM
Hi,

I've made a data-bound tree with right-click to add/delete/update nodes.

1 class "mytree.lzx" extending basetree.lzx ( looks like tree.lzx + right click handling )
+ the canvas "test_mytree.lzx"

The issue that I can't fix is :
when I add a Node "Project3" (isLeaf=false) to the root Node, then add a leaf "appli31" to "Project3", It appears like a Node (isLeaf="false").
If I add a second leaf "appli32" to "Project3", both appli31 and appli32 appears like leaves !!!??? Is this a bug ?

The 2 files joined should be put in ..../my-apps/mytree/mytree.lzx and ..../my-apps/mytree/test_mytree.lzx to work fine (reference to laszlo images for tree in the class)

(I'm using OL-4.1.1)

rcyeager
02-14-2009, 03:15 PM
If you add a debug output into your custom mytree node view where you create the context menu in the oninit handler, you will see it doesn't trigger when the first new leaf node is created. This may indicate the tree is using a replicated view instead. When the second leaf node is created, then the init method is called twice, which is when the leafs are getting converted with the proper icons. Data-mapped views can be tricky. You will need to dig through the base tree implementation to figure out how the tree class really works.

IMO, the opttree component in the incubator directory is much better. Suggest using that instead. It offers much better performance and is easier to customize the tree nodes.

Robert Yeager
http://www.qrowd.com
http://www.cooqy.com

chuckgom1
02-15-2009, 01:55 AM
"ID" attributes are only used on a data purpose, if I change the name of this attribute for "IDE", the result is exactly the same !

And you're right, if I write:
<mytree ...>
<mytree datapath="*" ....>
<handler name="oninit">
Debug.write("init");
</handler>
</mytree>
</mytree>

the init method is not called when creating the 1st leaf in "Project3" .
I tried to force the init() method but I didn't succeed.
(parent.parent.what.init(); in the button handler near line 60 of test_tree.lzx)
Any idea to make it work?

rcyeager
02-15-2009, 08:38 AM
You are correct about using "ID", so long as it is inside data nodes.

Adding this code to your custom "mytree" class fixes the problem for me:


<method name="_setIsLeaf" args="leaf">
if (typeof(leaf) == "string") {
leaf = (leaf == "true" );
}
this.isleaf = leaf;
if (this.onisleaf) this.onisleaf.sendEvent(isleaf)
</method>
<handler name="onisleaf">
if (this.isleaf) {
item.treeitem.expander.expander.setResourceNumber( 3);
item.treeitem.icon.icon.setResourceNumber(3);
} else if (this.open) {
item.treeitem.expander.expander.setResourceNumber( 2);
item.treeitem.icon.icon.setResourceNumber(2);
} else if (this["item"] != null){
item.treeitem.expander.expander.setResourceNumber( 1);
item.treeitem.icon.icon.setResourceNumber(1);
}
</handler>


It seems that the arrival of data and the presentation of the node is not always consistent in the tree. This hack forces the node to configure itself again.

I never use the tree class, b/c the opttree performs and works much better.

Robert Yeager
http://www.qrowd.com
http://www.cooqy.com

chuckgom1
02-15-2009, 11:35 PM
Thanks a lot, it works !
I don't know exactly why but it works ^^
I didn't know this technique, I don't know when the _setisleaf method is called,by who and so on, if it's explained somewhere in the tutorials let me know !