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 import java.util.Iterator;
26
27 /***
28 * This class is a default implementation of a {@link TreeTableNode} with
29 * children.
30 */
31 public class DefaultTreeTableNode 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 = new ArrayList();
45
46
47
48 public DefaultTreeTableNode(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 children.add(node);
60 model.childInserted(this, children.size() - 1, node);
61 }
62
63 public void changed()
64 {
65 model.nodeChanged(this);
66 }
67
68 public void changedChildAt(int index)
69 {
70 model.childChanged(this, index, children.get(index));
71 }
72
73 /***
74 * Returns an Iterator over all child nodes.
75 */
76 public Iterator children()
77 {
78 return children.iterator();
79 }
80
81 /***
82 * Returns the child that stores <code>data</code>.
83 *
84 * @return -1, if data could not be found
85 */
86 public int getIndexOfChildByData(Object data)
87 {
88 for (int i = 0; i < children.size(); i++) {
89 TreeTableNode node = (TreeTableNode)children.get(i);
90 if (node.getData() == data) {
91 return i;
92 }
93 }
94 return -1;
95 }
96
97 /***
98 * Returns the child node at <code>index</code>.
99 */
100 public Object getChildAt(int index)
101 {
102 return children.get(index);
103 }
104
105 /***
106 * Returns the number of children of the node.
107 */
108 public int getChildCount()
109 {
110 return children.size();
111 }
112
113 public Object getData()
114 {
115 return data;
116 }
117
118 public DefaultColumnTreeTableModel getModel()
119 {
120 return model;
121 }
122
123 public void removeChildAt(int index)
124 {
125 Object o = children.get(index);
126 children.remove(index);
127 model.childRemoved(this, index, o);
128 }
129
130 public void sort(Comparator c)
131 {
132 Collections.sort(children, c);
133 }
134
135 /***
136 * Returns the <code>data.toString()</code>.
137 */
138 public String toString()
139 {
140 return null;
141 }
142
143 }