You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@pivot.apache.org by buddhika chamith <ch...@gmail.com> on 2010/05/30 16:42:53 UTC

Populating Tree View with Runtime Data

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

Re: Populating Tree View with Runtime Data

Posted by buddhika chamith <ch...@gmail.com>.
Thanks Greg. I will try it that way.

Re: Populating Tree View with Runtime Data

Posted by Greg Brown <gk...@mac.com>.
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:

http://svn.apache.org/repos/asf/pivot/trunk/tools/src/org/apache/pivot/tools/xml/

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