1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.xnap.gui.table;
21
22 import java.util.ArrayList;
23 import java.util.Collections;
24 import java.util.Comparator;
25
26 /***
27 * This class is a default implementation of a {@link TreeTableNode} with
28 * children. All data structures holding the childern are instantiated
29 * lazyly though to allow for less memory consumption when not needed.
30 */
31 public class LazyTreeTableNode implements TreeTableNode
32 {
33
34
35
36
37
38 private DefaultColumnTreeTableModel model;
39 private Object data;
40
41 /***
42 * List of {@link TreeTableNode} objects
43 */
44 private ArrayList children;
45
46
47
48 public LazyTreeTableNode(DefaultColumnTreeTableModel model,
49 Object data)
50 {
51 this.model = model;
52 this.data = data;
53 }
54
55
56
57 public void add(TreeTableNode node)
58 {
59 if (children == null) {
60 children = new ArrayList();
61 }
62
63 children.add(node);
64 model.childInserted(this, children.size() - 1, node);
65
66
67 model.nodeChanged(this);
68 }
69
70 /***
71 * Returns the child node at <code>index</code>.
72 */
73 public Object getChildAt(int index)
74 {
75 return children.get(index);
76 }
77
78 /***
79 * Returns the number of children of the node.
80 */
81 public int getChildCount()
82 {
83 return (children != null) ? children.size() : 0;
84 }
85
86 public Object getData()
87 {
88 return data;
89 }
90
91 public void removeChildAt(int index)
92 {
93 children.remove(index);
94 model.childRemoved(this, index, children.get(index));
95 }
96
97 public void setData(Object data)
98 {
99 this.data = data;
100 }
101
102 public void sort(Comparator c)
103 {
104 if (children != null) {
105 Collections.sort(children, c);
106 }
107 }
108
109 /***
110 * Returns null.
111 */
112 public String toString()
113 {
114 return null;
115 }
116
117 }