1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.myfaces.custom.tree2;
21
22 import java.util.List;
23 import java.util.ArrayList;
24
25 public class TreeNodeBase implements TreeNode, Comparable
26 {
27 private static final long serialVersionUID = 278589014441538822L;
28 private List children = new ArrayList();
29 private String type;
30 private String description;
31 private boolean leaf;
32 private String identifier;
33
34 public TreeNodeBase()
35 {}
36
37 public TreeNodeBase(String type, String description, boolean leaf)
38 {
39 this(type, description, null, leaf);
40 }
41
42 public TreeNodeBase(String type, String description, String identifier, boolean leaf)
43 {
44 this.type = type;
45 this.description = description;
46 this.identifier = identifier;
47 this.leaf = leaf;
48 }
49
50 public boolean isLeaf()
51 {
52 return leaf || (getChildCount() == 0);
53 }
54
55 public void setLeaf(boolean leaf)
56 {
57 this.leaf = leaf;
58 }
59
60 public List getChildren()
61 {
62 return children;
63 }
64
65 public String getType()
66 {
67 return type;
68 }
69
70 public void setType(String type)
71 {
72 this.type = type;
73 }
74
75 public void setDescription(String description)
76 {
77 this.description = description;
78 }
79
80 public String getDescription()
81 {
82 return description;
83 }
84
85 public void setIdentifier(String identifier)
86 {
87 this.identifier = identifier;
88 }
89
90 public String getIdentifier()
91 {
92 return identifier;
93 }
94
95 public int getChildCount()
96 {
97 return getChildren().size();
98 }
99
100 public int compareTo(Object obj)
101 {
102
103 TreeNode otherNode = (TreeNode)obj;
104
105 if (isLeaf() && !otherNode.isLeaf())
106 {
107
108 return 1;
109 }
110 else if (!isLeaf() && otherNode.isLeaf())
111 {
112
113 return -1;
114 }
115 else
116 {
117
118 return getDescription().compareTo(otherNode.getDescription());
119 }
120 }
121 }