Here is my first contribution to qooxdoo! Attached is a patch that allows the root node of a tree (the QxTree element) to be hidden without hiding its children. This allows creating a tree which displays as if it had a number of top-level nodes (even though there is an invisible root node). This might be used, for example, to display all of the computers on a network as top-level items in a tree.
The patch also adds an option to the Tree_1.html example, showing the ability to hide and unhide the root node. Since the patch file can't include binary files, I've also attached the two new icons which allow for tree-lines on the first level=1 node, which do not have ascenders pointing to a higher-level node. Cheers, Derrell ps. The changes to QxTree could as easily be applied to QxTreeFolder which would make them a bit more generic, and in fact I had them there for a while. I was thinking that it could be used, for example, to show or not show the Workgroup level of a network tree. Unfortunately, without adding a bunch more code, the child nodes remain at their current indentation level, meaning that they appear to be children of a different parent when a parent is hidden -- definitely not the intended effect. I may, at some future time, work on making this single-node hiding feature more generic and move it to QxTreeFolder. For now, it's useful for the root node.
Index: source/demo/example/Tree_1.html =================================================================== --- source/demo/example/Tree_1.html (revision 3075) +++ source/demo/example/Tree_1.html (working copy) @@ -192,6 +192,20 @@ tTreeLines.addEventListener("changeChecked", function(e) { t.setUseTreeLines(e.getData()); }); + + + var tHideNode = new QxCheckBox("Hide the root node?"); + + with(tHideNode) { + setTop(100); + setLeft(0); + setChecked(false); + }; + + commandFrame.add(tHideNode); + + tHideNode.addEventListener("changeChecked", function(e) { t.setHideNode(e.getData()); }); + }; </script> </body> Index: source/script/widgets/QxTreeFolder.js =================================================================== --- source/script/widgets/QxTreeFolder.js (revision 3075) +++ source/script/widgets/QxTreeFolder.js (working copy) @@ -444,11 +444,39 @@ { if (this.hasContent() || this.getAlwaysShowPlusMinusSymbol()) { + /* If tree lines were not requested, don't display them */ if (!vUseTreeLines) { return this.getOpen() ? "minus" : "plus"; } - else if (this.isLastChild()) + + /* If this is the first level under the root... */ + if (this.getLevel() == 1) { + /* + * ... and the root is not being displayed and this is the first + * child... + */ + var vParentFolder = this.getParentFolder(); + if (vParentFolder && + !vParentFolder._horizontalLayout.getVisibility() && + this.isFirstChild()) + { + /* + * ... then if this is also the last (i.e. only) child, use no tree + * lines; otherwise, use descender lines but no ascender. + */ + if (this.isLastChild()) + { + return this.getOpen() ? "minus" : "plus"; + } + else + { + return this.getOpen() ? "start_minus" : "start_plus"; + } + } + } + + if (this.isLastChild()) { return this.getOpen() ? "end_minus" : "end_plus"; } Index: source/script/widgets/QxTree.js =================================================================== --- source/script/widgets/QxTree.js (revision 3075) +++ source/script/widgets/QxTree.js (working copy) @@ -73,6 +73,11 @@ QxTree.addProperty({ name : "useDoubleClick", type : QxConst.TYPEOF_BOOLEAN, defaultValue : false, getAlias : "useDoubleClick" }); QxTree.addProperty({ name : "useTreeLines", type : QxConst.TYPEOF_BOOLEAN, defaultValue : true, getAlias : "useTreeLines" }); +/* + * Add a "hideNode" property. This differs from the visibility property in + * that this property hides *only* the current node, not the node's children. + */ +QxTree.addProperty({ name : "hideNode", type : QxConst.TYPEOF_BOOLEAN, defaultValue : false, getAlias : "hideNode" }); @@ -175,7 +180,23 @@ return true; }; +proto._modifyHideNode = function(propValue, propOldValue, propData) +{ + if (! propValue) { + this._horizontalLayout.setHeight(this._horizontalLayout.originalHeight); + this._horizontalLayout.show(); + } else { + this._horizontalLayout.originalHeight = this._horizontalLayout.getHeight(); + this._horizontalLayout.setHeight(0); + this._horizontalLayout.hide(); + } + if (this._initialLayoutDone) { + this._updateIndent(); + } + + return true; +} Index: source/themes/widgets/windows/tree/start_plus.gif =================================================================== Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream Property changes on: source/themes/widgets/windows/tree/start_plus.gif ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Index: source/themes/widgets/windows/tree/start_minus.gif =================================================================== Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream Property changes on: source/themes/widgets/windows/tree/start_minus.gif ___________________________________________________________________ Name: svn:mime-type + application/octet-stream
start_minus.gif
Description: GIF image
start_plus.gif
Description: GIF image