<zk>
<zscript><![CDATA[
public class MyModel extends AbstractTreeModel {
public MyModel() {
super("Root");
}
public boolean isLeaf(Object node) {
return getLevel((String) node) >= 3; //at most 4 levels
}
public Object getChild(Object parent, int index) {
return parent + "." + index;
}
public int getChildCount(Object parent) {
return isLeaf(parent) ? 0 : 2; //each node has 5 children
}
public int getIndexOfChild(Object parent, Object child) {
String data = (String) child;
int i = data.lastIndexOf('.');
return Integer.parseInt(data.substring(i + 1));
}
private int getLevel(String data) {
for (int i = -1, level = 0;; ++level)
if ((i = data.indexOf('.', i + 1)) < 0)
return level;
}
}
MyModel myTree = new MyModel();
]]></zscript>
<vlayout>
<tree id="tree" model="${myTree}"
onSelect='selectedLabel.setValue(self.getSelectedItem()+", "+self.getSelectedItem().getLabel())'>
<template name="model">
<treeitem open="false">
<treerow>
<treecell label="${each}" />
</treerow>
</treeitem>
</template>
</tree>
<label id="selectedLabel" />
</vlayout>
</zk>