KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > oddjob > webapp > struts > forms > TreeNodeBean


1 /*
2  * (c) Rob Gordon 2005
3  */

4 package org.oddjob.webapp.struts.forms;
5
6 import java.io.Serializable JavaDoc;
7 import java.util.ArrayList JavaDoc;
8 import java.util.Collection JavaDoc;
9 import java.util.HashMap JavaDoc;
10 import java.util.Map JavaDoc;
11
12 /**
13  * A wrapper for a TreeNode to keep the form as simple
14  * as possible.
15  */

16 public class TreeNodeBean implements Serializable JavaDoc {
17     private static final long serialVersionUID = 20051229;
18     
19     private transient TreeNodeBeanBuilder builder;
20     
21     /** The reference id for this node. */
22     private String JavaDoc refId;
23     
24     /** The node name */
25     private transient String JavaDoc nodeName;
26     
27     /** The collection of child TreeNodeBeans. */
28     private Map JavaDoc childCollection;
29     
30     /** Has this node been expanded */
31     private boolean showChildren;
32     
33     /** The depth int the hiearchy. */
34     private int depth;
35
36     /** The icon id of the node */
37     private transient String JavaDoc iconId;
38     
39     private boolean hasChildren;
40     
41     public void setTreeNodeBeanBuilder(TreeNodeBeanBuilder builder){
42         this.builder = builder;
43     }
44     
45     /**
46      * return the collection of children
47      */

48     public Collection JavaDoc getChildCollection() {
49         if (childCollection == null) {
50             return null;
51         }
52         return new ArrayList JavaDoc(childCollection.values());
53     }
54
55     void setChildMap(Map JavaDoc childMap) {
56         this.childCollection = childMap;
57     }
58     
59     Map JavaDoc getChildMap() {
60         return childCollection;
61     }
62     
63     /**
64      * The node name property.
65      *
66      * @return The node name.
67      */

68     public String JavaDoc getNodeName() {
69         return nodeName;
70     }
71
72     /**
73      * Set the node name.
74      *
75      * @param nodeName The node name.
76      */

77     public void setNodeName(String JavaDoc nodeName) {
78         this.nodeName = nodeName;
79     }
80
81     /**
82      * getter to return the depth.
83      */

84     public int getDepth() {
85         return depth;
86     }
87     
88     /**
89      * Setter for depth.
90      *
91      * @param depth The depth.
92      */

93     public void setDepth(int depth) {
94         this.depth = depth;
95     }
96
97     /**
98      * Getter for nodeIndent property.
99      *
100      * @return The node indent.
101      */

102     public int getNodeIndent() {
103         return 20 * depth;
104     }
105
106     /**
107      * Getter method for the "showChildren"
108      * property.
109      *
110      * @return true if expanded.
111      */

112     public boolean getShowChildren() {
113         return this.showChildren;
114     }
115
116     /**
117      * Getter for the "hasChildren" property.
118      *
119      * @return true if this node has child nodes
120      */

121     public boolean getHasChildren() {
122         return hasChildren;
123     }
124
125     public void setHasChildren(boolean hasChildren) {
126         this.hasChildren = hasChildren;
127         if (!hasChildren) {
128             showChildren = false;
129         }
130     }
131     
132     /**
133      * A "fake" nested bean property (for image submit)
134      * <p>
135      * This is called twice per request processing. Don't know why.
136      */

137     public TreeNodeBean getExpand() {
138         showChildren = true;
139         if (childCollection == null) {
140             // someones clicked on the expand children image
141
// so create the children ready for the form.
142
childCollection = builder.buildChildren(this);
143         }
144         return this;
145     }
146
147     /**
148      * A "fake" nested bean property (for image submit)
149      */

150     public TreeNodeBean getCollapse() {
151         showChildren = false;
152         childCollection = null;
153         return this;
154     }
155     
156     /**
157      * Setter for the image submit's ".x" property
158      *
159      * @param The unused x co-ordinate.
160      */

161     public void setX(int i) {
162     }
163
164     /**
165      * Empty setter for the image submit's ".y" property
166      *
167      * @param The unused y co-ordinate.
168      */

169     public void setY(int i) {
170     }
171
172     
173     public String JavaDoc getRefId() {
174         return refId;
175     }
176
177     public void setRefId(String JavaDoc refId) {
178         this.refId = refId;
179     }
180     
181     public void setIconId(String JavaDoc iconId) {
182         this.iconId = iconId;
183     }
184
185     public String JavaDoc getIconId() {
186         return iconId;
187     }
188     
189     public Map JavaDoc getRequest() {
190         Map JavaDoc map = new HashMap JavaDoc();
191         map.put("refId", refId);
192         return map;
193     }
194     
195     public Map JavaDoc getIconIdRequest() {
196         Map JavaDoc map = new HashMap JavaDoc();
197         map.put("iconId", iconId);
198         return map;
199     }
200 }
Popular Tags