PDA

View Full Version : [2.0b1/2.0.2] missing Tree Stuff for 'lazy' definitions



hendricd
24 Oct 2007, 5:34 AM
There appears to not be a way to define a custom RootTreeNodeUI implementation for an AsynchTreeNode set as a Trees' root node:



//Provide a mechanism to define a custom RootTreeNodeUI implementation.
Ext.override(Ext.tree.TreePanel, {
/**
* Sets the root node for this tree during initialization.
* @param {Node} node
* @return {Node}
*/
setRootNode : function(node){
this.root = node;
node.ownerTree = this;
node.isRoot = true;
this.registerNode(node);
if(!this.rootVisible){
node.ui = node.attributes.uiProvider?
new node.attributes.uiProvider(node):
new Ext.tree.RootTreeNodeUI(node);
}
return node;
}
});

//permitting:

var tree =
new Ext.tree.TreePanel({
animate:false,
enableDD:false,
containerScroll: true,
autoScroll: true,
rootVisible:false,
loader: new Ext.tree.TreeLoader({dataUrl:'node.php', preloadChildren:true })
,root: Ext.tree.AsyncTreeNode({draggable:false,expanded:false,id:'rootNode',
uiProvider:Our.custom.RootTreeNodeUI})
,id : 'testTree'
}};

And, a modification for exposing the AsynchTreeNodes' loader defined anywhere in the Tree's definition.



Ext.override(Ext.tree.AsyncTreeNode, {
expand : function(deep, anim, callback){
if(this.loading){ // if an async load is already running, waiting til it's done
var timer;
var f = function(){
if(!this.loading){ // done loading
clearInterval(timer);
this.expand(deep, anim, callback);
}
}.createDelegate(this);
timer = setInterval(f, 200);
return;
}
if(!this.loaded){
if(this.fireEvent("beforeload", this) === false){
return;
}
this.loading = true;
this.ui.beforeLoad(this);

//var loader = this.loader || this.attributes.loader || this.getOwnerTree().getLoader();
var loader = this.getLoader();
if(loader){
loader.load(this, this.loadComplete.createDelegate(this, [deep, anim, callback]));
return;
}
}
Ext.tree.AsyncTreeNode.superclass.expand.call(this, deep, anim, callback);
},

getLoader : function(){
return this.loader || this.attributes.loader || this.getOwnerTree().getLoader();
}
});

mystix
24 Oct 2007, 6:34 AM
hmmm.. bug? or enhancement? :-/

hendricd
24 Oct 2007, 7:02 AM
For the first one:


/**
* @class Ext.tree.RootTreeNodeUI
* This class provides the default UI implementation for <b>root</b> Ext TreeNodes.
* The RootTreeNode UI implementation allows customizing the appearance of the root tree node.<br>
* <p>
* If you are customizing the Tree's user interface, you
* may need to extend this class, but you should never need to instantiate this class.<br>
*/

.. implies that you should use this mechanism to define a custom UI for root treenodes. But, TreePanels-setRootNode disallows that possibility for root nodes - bug.

The second one is a convenience method for lazy layout rendering, which 2.0 seems to push more towards these days -- (bug/enhancement? your call.)

mystix
24 Oct 2007, 7:18 AM
alritey. thanks for the explanation. :)

let's wait for the official decision.

hendricd
26 Feb 2008, 12:19 PM
bump --