1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.struts2.components;
19
20 import java.io.Writer;
21
22 import javax.servlet.http.HttpServletRequest;
23 import javax.servlet.http.HttpServletResponse;
24
25 import com.opensymphony.xwork2.util.ValueStack;
26
27 /***
28 * <!-- START SNIPPET: javadoc -->
29 *
30 * Renders a tree widget with AJAX support.<p/>
31 *
32 * The id attribute is normally specified, such that it could be looked up using
33 * javascript if necessary.<p/>
34 *
35 * <!-- END SNIPPET: javadoc -->
36 *
37 * <p/> <b>Examples</b>
38 *
39 * <pre>
40 * <!-- START SNIPPET: example -->
41 *
42 * <-- statically -->
43 * <s:tree id="..." label="...">
44 * <s:treenode id="..." label="..." />
45 * <s:treenode id="..." label="...">
46 * <s:treenode id="..." label="..." />
47 * <s:treenode id="..." label="..." />
48 * &;lt;/s:treenode>
49 * <s:treenode id="..." label="..." />
50 * </s:tree>
51 *
52 * <-- dynamically -->
53 * <s:tree
54 * id="..."
55 * rootNode="..."
56 * nodeIdProperty="..."
57 * nodeTitleProperty="..."
58 * childCollectionProperty="..." />
59 *
60 * <!-- END SNIPPET: example -->
61 * </pre>
62 *
63 *
64 * @s.tag name="tree" tld-body-content="JSP" tld-tag-class="org.apache.struts2.views.jsp.ui.TreeTag"
65 * description="Render a tree widget."
66 */
67 public class Tree extends ClosingUIBean {
68
69 private static final String TEMPLATE = "tree-close";
70 private static final String OPEN_TEMPLATE = "tree";
71
72 private String toggle = "fade";
73 private String treeSelectedTopic;
74 private String treeExpandedTopic;
75 private String treeCollapsedTopic;
76 protected String rootNodeAttr;
77 protected String childCollectionProperty;
78 protected String nodeTitleProperty;
79 protected String nodeIdProperty;
80 private String showRootGrid;
81
82 private String showGrid;
83 private String blankIconSrc;
84 private String gridIconSrcL;
85 private String gridIconSrcV;
86 private String gridIconSrcP;
87 private String gridIconSrcC;
88 private String gridIconSrcX;
89 private String gridIconSrcY;
90 private String expandIconSrcPlus;
91 private String expandIconSrcMinus;
92 private String iconWidth;
93 private String iconHeight;
94 private String toggleDuration;
95 private String templateCssPath;
96
97 public Tree(ValueStack stack, HttpServletRequest request, HttpServletResponse response) {
98 super(stack, request, response);
99 }
100
101 public boolean start(Writer writer) {
102 boolean result = super.start(writer);
103
104 if (this.label == null) {
105 if ((rootNodeAttr == null)
106 || (childCollectionProperty == null)
107 || (nodeTitleProperty == null)
108 || (nodeIdProperty == null)) {
109 fieldError("label","The TreeTag requires either a value for 'label' or ALL of 'rootNode', " +
110 "'childCollectionProperty', 'nodeTitleProperty', and 'nodeIdProperty'", null);
111 }
112 }
113 return result;
114 }
115
116 protected void evaluateExtraParams() {
117 super.evaluateExtraParams();
118
119 if (toggle != null) {
120 addParameter("toggle", findString(toggle));
121 }
122
123 if (treeSelectedTopic != null) {
124 addParameter("treeSelectedTopic", findString(treeSelectedTopic));
125 }
126
127 if (treeExpandedTopic != null) {
128 addParameter("treeExpandedTopic", findString(treeExpandedTopic));
129 }
130
131 if (treeCollapsedTopic != null) {
132 addParameter("treeCollapsedTopic", findString(treeCollapsedTopic));
133 }
134
135 if (rootNodeAttr != null) {
136 addParameter("rootNode", findValue(rootNodeAttr));
137 }
138
139 if (childCollectionProperty != null) {
140 addParameter("childCollectionProperty", findString(childCollectionProperty));
141 }
142
143 if (nodeTitleProperty != null) {
144 addParameter("nodeTitleProperty", findString(nodeTitleProperty));
145 }
146
147 if (nodeIdProperty != null) {
148 addParameter("nodeIdProperty", findString(nodeIdProperty));
149 }
150
151 if (showRootGrid != null) {
152 addParameter("showRootGrid", findValue(showRootGrid, Boolean.class));
153 }
154
155
156 if (showGrid != null) {
157 addParameter("showGrid", findValue(showGrid, Boolean.class));
158 }
159
160 if (blankIconSrc != null) {
161 addParameter("blankIconSrc", findString(blankIconSrc));
162 }
163
164 if (gridIconSrcL != null) {
165 addParameter("gridIconSrcL", findString(gridIconSrcL));
166 }
167
168 if (gridIconSrcV != null) {
169 addParameter("gridIconSrcV", findString(gridIconSrcV));
170 }
171
172 if (gridIconSrcP != null) {
173 addParameter("gridIconSrcP", findString(gridIconSrcP));
174 }
175
176 if (gridIconSrcC != null) {
177 addParameter("gridIconSrcC", findString(gridIconSrcC));
178 }
179
180 if (gridIconSrcX != null) {
181 addParameter("gridIconSrcX", findString(gridIconSrcX));
182 }
183
184 if (gridIconSrcY != null) {
185 addParameter("gridIconSrcY", findString(gridIconSrcY));
186 }
187
188 if (expandIconSrcPlus != null) {
189 addParameter("expandIconSrcPlus", findString(expandIconSrcPlus));
190 }
191
192 if (expandIconSrcMinus != null) {
193 addParameter("expandIconSrcMinus", findString(expandIconSrcMinus));
194 }
195
196 if (iconWidth != null) {
197 addParameter("iconWidth", findValue(iconWidth, Integer.class));
198 }
199 if (iconHeight != null) {
200 addParameter("iconHeight", findValue(iconHeight, Integer.class));
201 }
202 if (toggleDuration != null) {
203 addParameter("toggleDuration", findValue(toggleDuration, Integer.class));
204 }
205 if (templateCssPath != null) {
206 addParameter("templateCssPath", findString(templateCssPath));
207 }
208 }
209
210 public String getDefaultOpenTemplate() {
211 return OPEN_TEMPLATE;
212 }
213
214 protected String getDefaultTemplate() {
215 return TEMPLATE;
216 }
217
218 public String getToggle() {
219 return toggle;
220 }
221
222 /***
223 * The toggle property (either 'explode' or 'fade'). Default is 'fade'.
224 * @s.tagattribute required="false"
225 */
226 public void setToggle(String toggle) {
227 this.toggle = toggle;
228 }
229
230 public String getTreeSelectedTopic() {
231 return treeSelectedTopic;
232 }
233
234 /***
235 * The treeSelectedTopic property.
236 * @s.tagattribute required="false"
237 */
238 public void setTreeSelectedTopic(String treeSelectedTopic) {
239 this.treeSelectedTopic = treeSelectedTopic;
240 }
241
242 public String getTreeExpandedTopic() {
243 return treeExpandedTopic;
244 }
245
246 /***
247 * The treeExpandedTopic property.
248 * @s.tagattribute required="false"
249 */
250 public void setTreeExpandedTopic(String treeExpandedTopic) {
251 this.treeExpandedTopic = treeExpandedTopic;
252 }
253
254 public String getTreeCollapsedTopic() {
255 return treeCollapsedTopic;
256 }
257
258 /***
259 * The treeCollapsedTopic property.
260 * @s.tagattribute required="false"
261 */
262 public void setTreeCollapsedTopic(String treeCollapsedTopic) {
263 this.treeCollapsedTopic = treeCollapsedTopic;
264 }
265
266 public String getRootNode() {
267 return rootNodeAttr;
268 }
269
270 /***
271 * The rootNode property.
272 * @s.tagattribute required="false"
273 */
274 public void setRootNode(String rootNode) {
275 this.rootNodeAttr = rootNode;
276 }
277
278 public String getChildCollectionProperty() {
279 return childCollectionProperty;
280 }
281
282 /***
283 * The childCollectionProperty property.
284 * @s.tagattribute required="false"
285 */
286 public void setChildCollectionProperty(String childCollectionProperty) {
287 this.childCollectionProperty = childCollectionProperty;
288 }
289
290 public String getNodeTitleProperty() {
291 return nodeTitleProperty;
292 }
293
294 /***
295 * The nodeTitleProperty property.
296 * @s.tagattribute required="false"
297 */
298 public void setNodeTitleProperty(String nodeTitleProperty) {
299 this.nodeTitleProperty = nodeTitleProperty;
300 }
301
302 public String getNodeIdProperty() {
303 return nodeIdProperty;
304 }
305
306 /***
307 * The nodeIdProperty property.
308 * @s.tagattribute required="false"
309 */
310 public void setNodeIdProperty(String nodeIdProperty) {
311 this.nodeIdProperty = nodeIdProperty;
312 }
313
314 /***
315 * The showRootGrid property (default true).
316 * @s.tagattribute required="false"
317 */
318 public void setShowRootGrid(String showRootGrid) {
319 this.showRootGrid = showRootGrid;
320 }
321
322 public String getShowRootGrid() {
323 return showRootGrid;
324 }
325
326 public String getBlankIconSrc() {
327 return blankIconSrc;
328 }
329
330 /***
331 * Blank icon image source.
332 * @s.tagattribute required="false"
333 */
334 public void setBlankIconSrc(String blankIconSrc) {
335 this.blankIconSrc = blankIconSrc;
336 }
337
338 public String getExpandIconSrcMinus() {
339 return expandIconSrcMinus;
340 }
341
342 /***
343 * Expand icon (-) image source.
344 * @s.tagattribute required="false"
345 */
346 public void setExpandIconSrcMinus(String expandIconSrcMinus) {
347 this.expandIconSrcMinus = expandIconSrcMinus;
348 }
349
350 public String getExpandIconSrcPlus() {
351 return expandIconSrcPlus;
352 }
353
354 /***
355 * Expand Icon (+) image source.
356 * @s.tagattribute required="false"
357 */
358 public void setExpandIconSrcPlus(String expandIconSrcPlus) {
359 this.expandIconSrcPlus = expandIconSrcPlus;
360 }
361
362 public String getGridIconSrcC() {
363 return gridIconSrcC;
364 }
365
366 /***
367 * Image source for under child item child icons.
368 * @s.tagattribute required="false"
369 */
370 public void setGridIconSrcC(String gridIconSrcC) {
371 this.gridIconSrcC = gridIconSrcC;
372 }
373
374 public String getGridIconSrcL() {
375 return gridIconSrcL;
376 }
377
378
379 /***
380 * Image source for last child grid.
381 * @s.tagattribute required="false"
382 */
383 public void setGridIconSrcL(String gridIconSrcL) {
384 this.gridIconSrcL = gridIconSrcL;
385 }
386
387 public String getGridIconSrcP() {
388 return gridIconSrcP;
389 }
390
391 /***
392 * Image source for under parent item child icons.
393 * @s.tagattribute required="false"
394 */
395 public void setGridIconSrcP(String gridIconSrcP) {
396 this.gridIconSrcP = gridIconSrcP;
397 }
398
399 public String getGridIconSrcV() {
400 return gridIconSrcV;
401 }
402
403 /***
404 * Image source for vertical line.
405 * @s.tagattribute required="false"
406 */
407 public void setGridIconSrcV(String gridIconSrcV) {
408 this.gridIconSrcV = gridIconSrcV;
409 }
410
411 public String getGridIconSrcX() {
412 return gridIconSrcX;
413 }
414
415 /***
416 * Image source for grid for sole root item.
417 * @s.tagattribute required="false"
418 */
419 public void setGridIconSrcX(String gridIconSrcX) {
420 this.gridIconSrcX = gridIconSrcX;
421 }
422
423 public String getGridIconSrcY() {
424 return gridIconSrcY;
425 }
426
427 /***
428 * Image source for grid for last root item.
429 * @s.tagattribute required="false"
430 */
431 public void setGridIconSrcY(String gridIconSrcY) {
432 this.gridIconSrcY = gridIconSrcY;
433 }
434
435 public String getIconHeight() {
436 return iconHeight;
437 }
438
439
440 /***
441 * Icon height (default 18 pixels).
442 * @s.tagattribute required="false"
443 */
444 public void setIconHeight(String iconHeight) {
445 this.iconHeight = iconHeight;
446 }
447
448 public String getIconWidth() {
449 return iconWidth;
450 }
451
452 /***
453 * Icon width (default 19 pixels).
454 * @s.tagattribute required="false"
455 */
456 public void setIconWidth(String iconWidth) {
457 this.iconWidth = iconWidth;
458 }
459
460
461
462 public String getTemplateCssPath() {
463 return templateCssPath;
464 }
465
466 /***
467 * Template css path (default {contextPath}/struts/tree.css.
468 * @s.tagattribute required="false"
469 */
470 public void setTemplateCssPath(String templateCssPath) {
471 this.templateCssPath = templateCssPath;
472 }
473
474 public String getToggleDuration() {
475 return toggleDuration;
476 }
477
478 /***
479 * Toggle duration (default 150 ms)
480 * @s.tagattribute required="false"
481 */
482 public void setToggleDuration(String toggleDuration) {
483 this.toggleDuration = toggleDuration;
484 }
485
486 public String getShowGrid() {
487 return showGrid;
488 }
489
490 /***
491 * Show grid (default true).
492 * @s.tagattribute required="false"
493 */
494 public void setShowGrid(String showGrid) {
495 this.showGrid = showGrid;
496 }
497 }
498