Populating Tree View with Runtime Data

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Populating Tree View with Runtime Data

buddhika chamith
Hi All,

I was following Tree View example. It only shows how to fill up the tree with static data in wtkx. I want the tree to be populated programmatically at runtime. The example says this can be achieved as follows.  'A real application could load dynamic data and use a custom renderer to present the raw data straight to the user.' Can somebody please point me to some code sample where this has been done using a custom renderer? Sorry if the question is too elementary. I am a complete newbie.

Regards,
Buddhika
Reply | Threaded
Open this post in threaded view
|

Re: Populating Tree View with Runtime Data

Greg Brown
Administrator
WTKX is just a shortcut to instantiating Java objects in code. So, instead of this:

<TreeView>
    <treeData>
        <content:TreeBranch>
            <content:TreeBranch text="Activity" icon="org/apache/pivot/tutorials/folder.png">
                <content:TreeBranch text="Games" icon="org/apache/pivot/tutorials/folder.png">
                    ...
                </content:TreeBranch>
            </content:TreeBranch>
        </content:TreeBranch>    
    </treeData>
</TreeView>

You can do this:

TreeView treeView = new TreeView();
TreeBranch root = new TreeBranch();
TreeBranch activityBranch = new TreeBranch();
root.add(activityBranch);

TreeBranch gamesBranch = new TreeBranch();
activityBranch.add(gamesBranch);

treeView.setTreeData(root);

How Java maps to WTKX is discussed in more detail in the WTKX Primer section of the tutorial.

Note that a tree node can actually be any type of Object, and a tree branch is simply any class that implements org.apache.pivot.collections.List. The TreeNode and TreeBranch classes are simply default implementations that the default TreeNodeRenderer knows how to handle. For example, the following demo uses an instance of org.apache.pivot.xml.Element as a branch:


Hope this helps.

Greg


On May 30, 2010, at 10:42 AM, buddhika chamith wrote:

Hi All,

I was following Tree View example. It only shows how to fill up the tree with static data in wtkx. I want the tree to be populated programmatically at runtime. The example says this can be achieved as follows.  'A real application could load dynamic data and use a custom renderer to present the raw data straight to the user.' Can somebody please point me to some code sample where this has been done using a custom renderer? Sorry if the question is too elementary. I am a complete newbie.

Regards,
Buddhika

Reply | Threaded
Open this post in threaded view
|

Re: Populating Tree View with Runtime Data

buddhika chamith
Thanks Greg. I will try it that way.