On Sun, Dec 13, 2009 at 18:47, lp1051 <[email protected]> wrote: > I have two main cases and problems, that I would need help with: > > First, I cannot even find out how many branchces my virtual tree has. I > tried getChild(), getChildren(), children, or childNodes - none works. Then > I thought maybe tree.getDataModel().getData() could work, but it gives me > one more child then I have (counting branches+leafs). I guess it's > something > very easy, but... >
There are a few ways to do it. Firstly, using the raw data model works fine. The only piece of information that you're missing is that there is a "virtual root" node, node id 0, that's there automatically. That's why you're finding one more node than the number of branches + leaves that you added. See the demobrowser snippet below that shows it. Secondly, if you include the qx.ui.treevirtual.MFamily, then you have access to the familyGetFirstChild(), familyGetNextSibling(), etc. methods which is a nice way to organize some forms of code. If you use these methods, then you'll also likely want to include the qx.ui.treevirtual.MNode mixin. The methods return a node id, and you can retrieve the node object using the nodeGet() method in the MNode mixin. In either case, the structure of a node is documented with the class qx.ui.treevirtual.SimpleTreeDataModel. You'll particularly care about the "type" field of the node, which will be qx.ui.treevirtual.SimpleTreeDataModel.Type.LEAF (1) or qx.ui.treevirtual.SimpleTreeDataModel.Type.BRANCH (2). > > And then I would need something like addBefore() method, so I could place > branch or leaf into specific part of the tree. I cannot use move() and with > addBefore() I get error - addBefore() is not a function. Am I missing some > pages of manual, or API documentation? > No, you're not missing anything here. There is no built-in method for doing that, but it's not difficult to implement. The easiest way is likely to do a normal dataModel.addBranch() or dataModel.addLeaf() call, to which you specify the parent node id (among other things), and which returns to you the node id of the newly-added branch or leaf. You could then retrieve the parent node using the nodeGet() method described above, and move the just-pushed child item -- the new node you just added -- to whatever position in the children array you'd like, using qx.lang.removeAt() and qx.lang.insertAt(), qx.lang.insertBefore(), or qx.lang.insertAfter() to modify the children array in place. After you've made all of your adjustments, call dataModel.setData() with no parameters to cause the modified data model to take effect. Here's a demobrowser application that shows the extra node id 0 which is the virtual root that you can ignore. This this all helps. Derrell http://demo.qooxdoo.org/devel/playground/#%7B%22code%22%3A%20%22%252F%252F%2520We%2520want%2520to%2520use%2520some%2520of%2520the%2520high-level%2520node%2520operation%2520convenience%250A%252F%252F%2520methods%2520rather%2520than%2520manually%2520digging%2520into%2520the%2520TreeVirtual%2520helper%250A%252F%252F%2520classes.%2520%2520Include%2520the%2520mixin%2520that%2520provides%2520them.%250Aqx.Class.include%28qx.ui.treevirtual.TreeVirtual%252C%250A%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520qx.ui.treevirtual.MNode%29%253B%250A%250A%252F%252F%2520tree%250Avar%2520tree%2520%253D%2520new%2520qx.ui.treevirtual.TreeVirtual%28%2522Tree%2522%29%253B%250Atree.setWidth%28200%29%253B%250Atree.setColumnWidth%280%252C%2520200%29%253B%250Atree.setAlwaysShowOpenCloseSymbol%28true%29%253B%250Athis.getRoot%28%29.add%28tree%252C%250A%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%257B%250A%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520left%2520%253A%252010%252C%250A%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520top%2520%253A%252030%252C%250A%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520bottom%2520%253A%252030%250A%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%257D%29%253B%250A%250A%252F%252F%2520create%2520a%2520label%2520to%2520which%2520we%27ll%2520output%2520the%2520data%2520model%250Avar%2520output%2520%253D%2520new%2520qx.ui.basic.Label%28%29%253B%250Aoutput.setRich%28true%29%253B%250Aoutput.setWidth%28300%29%253B%250Athis.getRoot%28%29.add%28output%252C%250A%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%257B%250A%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520left%2520%253A%2520250%252C%250A%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520top%2520%253A%252030%252C%250A%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520bottom%2520%253A%252030%250A%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%257D%29%253B%250A%250A%252F%252F%2520tree%2520data%2520model%250Avar%2520dataModel%2520%253D%2520tree.getDataModel%28%29%253B%250Avar%2520te1%2520%253D%2520dataModel.addBranch%28null%252C%2520%2522Desktop%2522%252C%2520true%29%253B%250Avar%2520te%2520%253D%2520dataModel.addBranch%28te1%252C%2520%2522Workspace%2522%252C%2520true%29%253B%250AdataModel.addLeaf%28te%252C%2520%2522Windows%2520%28C%253A%29%2522%29%253B%250AdataModel.setData%28%29%253B%250A%250A%252F%252F%2520retrieve%2520and%2520display%2520the%2520data%2520model%250Avar%2520x%2520%253D%2520qx.dev.Debug.debugObjectToString%28dataModel.getData%28%29%252C%2520%2522data%2522%252C%252010%252C%2520true%29%253B%250Aoutput.setValue%28x%29%253B%250A%250A%22%7D
------------------------------------------------------------------------------ Return on Information: Google Enterprise Search pays you back Get the facts. http://p.sf.net/sfu/google-dev2dev
_______________________________________________ qooxdoo-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
