01: /* SimpleTreeNode.java
02:
03: {{IS_NOTE
04: Purpose:
05:
06: Description:
07:
08: History:
09: Aug 10 2007, Created by Jeff Liu
10: }}IS_NOTE
11:
12: Copyright (C) 2005 Potix Corporation. All Rights Reserved.
13:
14: {{IS_RIGHT
15: This program is distributed under GPL Version 2.0 in the hope that
16: it will be useful, but WITHOUT ANY WARRANTY.
17: }}IS_RIGHT
18: */
19: package org.zkoss.zul;
20:
21: import java.util.List;
22:
23: /**
24: *
25: * The treenode for {@link SimpleTreeModel}
26: * Note: It assumes the content is immutable
27: *
28: * @author Jeff
29: * @since ZK 3.0.0
30: */
31: public class SimpleTreeNode {
32:
33: private Object _data;
34:
35: private List _children;
36:
37: /**
38: * Constructor
39: * @param data data of the receiver
40: * @param children children of the receiver
41: * <br>
42: * Notice: Only <code>SimpleTreeNode</code> can be contained in The List <code>children</code>
43: */
44: public SimpleTreeNode(Object data, List children) {
45: _data = data;
46: _children = children;
47: }
48:
49: /**
50: * Return data of the receiver
51: * @return data of the receiver
52: */
53: public Object getData() {
54: return _data;
55: }
56:
57: /**
58: * Return children of the receiver
59: * @return children of the receiver
60: */
61: public List getChildren() {
62: return _children;
63: }
64:
65: /**
66: * Return data.toString(). If data is null, return String "Data is null"
67: * @return data.toString(). If data is null, return String "Data is null"
68: */
69: public String toString() {
70: return (_data == null) ? "Data is null" : _data.toString();
71: }
72:
73: /**
74: * Returns true if the receiver is a leaf.
75: * @return true if the receiver is a leaf.
76: */
77: public boolean isLeaf() {
78: return (_children.size() == 0);
79: }
80:
81: /**
82: * Returns the child SimpleTreeNode at index childIndex.
83: * @return the child SimpleTreeNode at index childIndex.
84: */
85: public Object getChildAt(int childIndex) {
86: return _children.get(childIndex);
87: }
88:
89: /**
90: * Returns the number of children SimpleTreeNodes the receiver contains.
91: * @return the number of children SimpleTreeNodes the receiver contains.
92: */
93: public int getChildCount() {
94: return _children.size();
95: }
96: }
|