Processing...
Description & Source Code
  • Description
  • XML & Java Source
    tree_model.zul
    DirectoryTreeNode.java
    DirectoryTreeNodeCollection.java
    BinaryPackageController.java
    PackageDataUtil.java
    PackageData.java

This demo shows how data is populated in a tree using MVC and EL. (DefaultTreeModel)
The tree supports the display of rows of data, similar to a listbox or grid but with the concept of data hierarchy.

tree_model.zul
<groupbox id="grp" closable="false" mold='3d' apply="demo.tree.tree_model.BinaryPackageController">
	<caption label="ZK Binary Package" />
	<tree id="tree" hflex="1" model="${grp$composer.treeModel}">
		<treecols>
			<treecol hflex="1" label="Path" />
			<treecol hflex="1" label="Description" />
			<treecol width="100px" label="Size" />
		</treecols>
		<template name="model">
	        <treeitem>
	            <treerow>
	                <treecell label="${each.data.path}"/>
	                <treecell label="${each.data.description}"/>
	            </treerow>
	        </treeitem>
    </template>
	</tree>
</groupbox>
DirectoryTreeNode.java
package demo.tree.tree_model;

import org.zkoss.zul.DefaultTreeNode;

public class DirectoryTreeNode<T> extends DefaultTreeNode<T> {
	private static final long serialVersionUID = -8085873079938209759L;
	
	// Node Control the default open
	private boolean open = false;

	public DirectoryTreeNode(T data, DirectoryTreeNodeCollection<T> children, boolean open) {
		super(data, children);
		this.setOpen(open);
	}

	public DirectoryTreeNode(T data, DirectoryTreeNodeCollection<T> children) {
		super(data, children);
	}

	public DirectoryTreeNode(T data) {
		super(data);
	}

	public boolean isOpen() {
		return open;
	}

	public void setOpen(boolean open) {
		this.open = open;
	}
}
DirectoryTreeNodeCollection.java
package demo.tree.tree_model;

import java.util.LinkedList;

import org.zkoss.zul.DefaultTreeNode;

public class DirectoryTreeNodeCollection<T> extends LinkedList<DefaultTreeNode<T>> {

	private static final long serialVersionUID = -716538636175940429L;
	
}
BinaryPackageController.java
package demo.tree.tree_model;

import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.select.SelectorComposer;
import org.zkoss.zul.DefaultTreeModel;
import org.zkoss.zul.TreeModel;
import org.zkoss.zul.TreeNode;

import demo.data.PackageDataUtil;
import demo.data.pojo.PackageData;

public class BinaryPackageController extends SelectorComposer<Component> {

	private static final long serialVersionUID = 43014628867656917L;
	
	public TreeModel<TreeNode<PackageData>> getTreeModel() {
		return new DefaultTreeModel<PackageData>(PackageDataUtil.getRoot());
	}
}
PackageDataUtil.java
package demo.data;

import demo.data.pojo.PackageData;
import demo.tree.tree_model.DirectoryTreeNode;
import demo.tree.tree_model.DirectoryTreeNodeCollection;

public class PackageDataUtil {
	private static DirectoryTreeNode<PackageData> root;
	static {
		root = new DirectoryTreeNode<PackageData>(null,
				new DirectoryTreeNodeCollection<PackageData>() {
					private static final long serialVersionUID = 9019022379404376015L;

					{
						add(new DirectoryTreeNode<PackageData>(new PackageData(
								"/doc", "Release Notes and License")));
						add(new DirectoryTreeNode<PackageData>(new PackageData(
								"/dist", null),
								new DirectoryTreeNodeCollection<PackageData>() {
									private static final long serialVersionUID = 3541713473898615987L;

									{
										add(new DirectoryTreeNode<PackageData>(
												new PackageData("/lib", null),
												new DirectoryTreeNodeCollection<PackageData>() {
													private static final long serialVersionUID = 7225750712385675090L;

													{
														add(new DirectoryTreeNode<PackageData>(
																new PackageData(
																		"/zkforge",
																		null),
																new DirectoryTreeNodeCollection<PackageData>() {
																	private static final long serialVersionUID = 1204356757289701541L;

																	{
																		add(new DirectoryTreeNode<PackageData>(
																				new PackageData(
																						"ckez.jar",
																						"CKeditor",
																						"1709KB")));
																		add(new DirectoryTreeNode<PackageData>(
																				new PackageData(
																						"timelinez.jar",
																						"Timeline",
																						"283KB")));
																		add(new DirectoryTreeNode<PackageData>(
																				new PackageData(
																						"timeplotz.jar",
																						"Timeplot",
																						"112KB")));
																		add(new DirectoryTreeNode<PackageData>(
																				new PackageData(
																						"gmapsz.jar",
																						"Google Maps",
																						"95KB")));
																		add(new DirectoryTreeNode<PackageData>(
																				new PackageData(
																						"zuljsp.jar",
																						"JSP",
																						"129KB")));
																	}
																}

																, true));

														add(new DirectoryTreeNode<PackageData>(
																new PackageData(
																		"/ext",
																		null),
																new DirectoryTreeNodeCollection<PackageData>() {
																	private static final long serialVersionUID = 4142744663101866804L;

																	{
																		add(new DirectoryTreeNode<PackageData>(
																				new PackageData(
																						"commons-fileupload.jar",
																						"Upload Features")));
																		add(new DirectoryTreeNode<PackageData>(
																				new PackageData(
																						"commons-io.jar",
																						"Upload Features")));
																		add(new DirectoryTreeNode<PackageData>(
																				new PackageData(
																						"jcommon.jar",
																						"Chart Component")));
																		add(new DirectoryTreeNode<PackageData>(
																				new PackageData(
																						"jfreechar.jar",
																						"Chart Component")));
																		add(new DirectoryTreeNode<PackageData>(
																				new PackageData(
																						"jasperreports.jar",
																						"Jasperreport related Component")));
																		add(new DirectoryTreeNode<PackageData>(
																				new PackageData(
																						"itext.jarjxl.jar",
																						"Jasperreport related Component")));
																		add(new DirectoryTreeNode<PackageData>(
																				new PackageData(
																						"poi.jar",
																						"Jasperreport related Component")));
																		add(new DirectoryTreeNode<PackageData>(
																				new PackageData(
																						"commons-collections.jar",
																						"Jasperreport related Component")));
																		add(new DirectoryTreeNode<PackageData>(
																				new PackageData(
																						"commons-logging.jar",
																						"Jasperreport related Component")));
																		add(new DirectoryTreeNode<PackageData>(
																				new PackageData(
																						"commons-digester.jar",
																						"Jasperreport related Component")));
																		add(new DirectoryTreeNode<PackageData>(
																				new PackageData(
																						"bsh.jar",
																						"Scripting in Java interpreter for zscript (BeanShell)")));
																		add(new DirectoryTreeNode<PackageData>(
																				new PackageData(
																						"js.jar",
																						"Scripting in JavaScript (Rhino)")));
																		add(new DirectoryTreeNode<PackageData>(
																				new PackageData(
																						"groovy.jar",
																						"Scripting in Groovy")));
																		add(new DirectoryTreeNode<PackageData>(
																				new PackageData(
																						"jruby.jar",
																						"Scripting in Ruby (JRuby)")));
																		add(new DirectoryTreeNode<PackageData>(
																				new PackageData(
																						"jython.jar",
																						"Scripting in Python (Jython)")));
																		add(new DirectoryTreeNode<PackageData>(
																				new PackageData(
																						"Filters.jar",
																						"Captcha Component.")));
																		add(new DirectoryTreeNode<PackageData>(
																				new PackageData(
																						"mvel.jar",
																						"Evaluate the expressions (MVEL)")));
																		add(new DirectoryTreeNode<PackageData>(
																				new PackageData(
																						"ognl.jar",
																						"Evaluate the expressions (OGNL)")));
																	}
																}));

														add(new DirectoryTreeNode<PackageData>(
																new PackageData(
																		"zcommon.jar",
																		"ZK Core Jar File",
																		"413KB")));
														add(new DirectoryTreeNode<PackageData>(
																new PackageData(
																		"zcommon-el.jar",
																		"ZK Core Jar File",
																		"100KB")));
														add(new DirectoryTreeNode<PackageData>(
																new PackageData(
																		"zel.jar",
																		"ZK Core Jar File",
																		"151KB")));
														add(new DirectoryTreeNode<PackageData>(
																new PackageData(
																		"zhtml.jar",
																		"ZK Core Jar File",
																		"57KB")));
														add(new DirectoryTreeNode<PackageData>(
																new PackageData(
																		"zml",
																		"ZK Core Jar File",
																		"57KB")));
														add(new DirectoryTreeNode<PackageData>(
																new PackageData(
																		"zk.jar",
																		"ZK Core Jar File",
																		"1056KB")));
														add(new DirectoryTreeNode<PackageData>(
																new PackageData(
																		"zkbind.jar",
																		"ZK Core Jar File",
																		"270KB")));
														add(new DirectoryTreeNode<PackageData>(
																new PackageData(
																		"zkplus.jar",
																		"ZK Core Jar File",
																		"122KB")));
														add(new DirectoryTreeNode<PackageData>(
																new PackageData(
																		"zul.jar",
																		"ZK Core Jar File",
																		"1311KB")));
														add(new DirectoryTreeNode<PackageData>(
																new PackageData(
																		"zweb.jar",
																		"ZK Core Jar File",
																		"196KB")));

													}
												}

										));

										add(new DirectoryTreeNode<PackageData>(
												new PackageData("/src",
														"Jar Format Source Code")));
										add(new DirectoryTreeNode<PackageData>(
												new PackageData("/xsd",
														"XSD files for Development")));
										add(new DirectoryTreeNode<PackageData>(
												new PackageData("/WEB-INF",
														"Configuration Files")));
									}
								}

						));

					}
				}, true); // dist opened
	}

	public static DirectoryTreeNode<PackageData> getRoot() {
		return root;
	}
}
PackageData.java
package demo.data.pojo;

public class PackageData {
	private final String path;
	private final String description;
	private final String size;

	public PackageData(String path, String description) {
		this.path = path;
		this.description = description;
		this.size = null;
	}

	public PackageData(String path, String description, String size) {
		this.path = path;
		this.description = description;
		this.size = size;
	}

	public String getPath() {
		return path;
	}

	public String getDescription() {
		return description;
	}

	public String getSize() {
		return size;
	}
}