RE: Programmatically constructing ...

"Christian Boulanger" <[email protected]> Thu, 25 Sep 2003 09:04:24 +0200
Newsgroups gmane.comp.windows.devel.netwindows
Message-ID <004b01c38333$416d2ab0$dd00a8c0@Laptop>
Responding to my own post...

> how do I programmatically construct 
> 
> - the tree widget (how does the array have to look like that 
> I feed into the setData method?)

I figured it out and Alex asked me to post it to the list:

We need an array/object like this:

Object nwComponent
	['node'] array
		[0] array
			['nwComponents'] =Object nwComponent
				['node'] etc. etc.
			['dispText'] = folder
		[1] array
			['dispText'] = element
			['action'] = action
			['opened'] = true

Here is some code which transforms a tree structure like the following:

treedata = { 
	'tree': 	{ 1:[2,3,4], 5:[6,7,8], 9:9,10:10,11:11},
	'branch':{1:{'name':"folder1",}, 
		2:{'name':"element1",'action':foo}, 
		3:{'name':"element2",'action':foo}, 
		4:{'name':"element3",'action':foo}, 
		5:{'name':"folder2"}, 
		......
		9:{'name':"element7",'action':foo},
		10:{'name':"element8",'action':foo},
		11:{'name':"element9",'action':foo}
		}
	}

Into the required structure:

Foo =  function()
{
this.constructTree = function(ds)
    {
        this.treedata = ds.data;	// data from server
        this.nwtree = new nwComponent();	// see bottom
        this.nwtree.node =
this.makeTreeData(this.treedata.tree,this.nwtree.node);
        this.vtree = new NW_WIDGET_FACTORY_tree(); // visual tree
        this.vtree.setData(this.nwtree);
        this.domNodeObj.appendChild(this.vtree.domNode);
    }

this.makeTreeData = function(treedata,treenode)
	for(branchId in treedata){
            var x = treenode.length;
            treenode[x] = new Array;   // nwComponent.node
            treenode[x]['dispText'] =
this.treedata['branch'][branchId].name;
            if(typeof treedata[branchId] == "object"){
                // folder
                treenode[x]['opened'] = "true";
                treenode[x]['nwComponents'] = new nwComponent();
                treenode[x]['nwComponents']['node'] = this.makeTreeData(
                    treedata[branchId],
                    treenode[x]['nwComponents']['node']
                ); 
            } else {
                // element
                treenode[x]['action'] = foo;
            }
        }
        return treenode;
   }
}
function nwComponent()
{
    this.node = new Array;
} 

It is not very elegant, but it works. Maybe you have a better solution.

I am still clueless as to how to programmatically construct tabbed panes. I
tried the following:

tabbed_pane = new NW_WIDGET_tabbed_pane(right_pane,"100%","100%");
var startTab = new NW_WIDGET_tab_ds("Introduction", "start.html");
startTab.getFromURL();
tabbed_pane.createTab(startTab);
var tabNode = document.createElement("div");
var tabd = new NW_WIDGET_tab_ds("name", null, tabNode);
tabbed_pane.addTab(tabd);

But this did not work. Any hints?

Christian 


_______________________________________________
The netWindows developers list: [email protected]
http://netwindows.org/mailman/listinfo/devel_netwindows.org