001: /*
002: * $Id: Tree.java 497654 2007-01-19 00:21:57Z rgielen $
003: *
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021: package org.apache.struts2.components;
022:
023: import java.io.Writer;
024:
025: import javax.servlet.http.HttpServletRequest;
026: import javax.servlet.http.HttpServletResponse;
027:
028: import org.apache.struts2.views.annotations.StrutsTag;
029: import org.apache.struts2.views.annotations.StrutsTagAttribute;
030:
031: import com.opensymphony.xwork2.util.ValueStack;
032:
033: /**
034: * <!-- START SNIPPET: javadoc -->
035: *
036: * Renders a tree widget with AJAX support.<p/>
037: *
038: * The id attribute is normally specified, such that it could be looked up using
039: * javascript if necessary.<p/>
040: *
041: * <!-- END SNIPPET: javadoc -->
042: *
043: * <p/> <b>Examples</b>
044: *
045: * <pre>
046: * <!-- START SNIPPET: example -->
047: *
048: * <-- statically -->
049: * <s:tree id="..." label="...">
050: * <s:treenode id="..." label="..." />
051: * <s:treenode id="..." label="...">
052: * <s:treenode id="..." label="..." />
053: * <s:treenode id="..." label="..." />
054: * &;lt;/s:treenode>
055: * <s:treenode id="..." label="..." />
056: * </s:tree>
057: *
058: * <-- dynamically -->
059: * <s:tree
060: * id="..."
061: * rootNode="..."
062: * nodeIdProperty="..."
063: * nodeTitleProperty="..."
064: * childCollectionProperty="..." />
065: *
066: * <!-- END SNIPPET: example -->
067: * </pre>
068: *
069: */
070: @StrutsTag(name="tree",tldTagClass="org.apache.struts2.views.jsp.ui.TreeTag",description="Render a tree widget.")
071: public class Tree extends ClosingUIBean {
072:
073: private static final String TEMPLATE = "tree-close";
074: private static final String OPEN_TEMPLATE = "tree";
075:
076: private String toggle = "fade";
077: private String treeSelectedTopic;
078: private String treeExpandedTopic;
079: private String treeCollapsedTopic;
080: protected String rootNodeAttr;
081: protected String childCollectionProperty;
082: protected String nodeTitleProperty;
083: protected String nodeIdProperty;
084: private String showRootGrid;
085:
086: private String showGrid;
087: private String blankIconSrc;
088: private String gridIconSrcL;
089: private String gridIconSrcV;
090: private String gridIconSrcP;
091: private String gridIconSrcC;
092: private String gridIconSrcX;
093: private String gridIconSrcY;
094: private String expandIconSrcPlus;
095: private String expandIconSrcMinus;
096: private String iconWidth;
097: private String iconHeight;
098: private String toggleDuration;
099: private String templateCssPath;
100:
101: public Tree(ValueStack stack, HttpServletRequest request,
102: HttpServletResponse response) {
103: super (stack, request, response);
104: }
105:
106: public boolean start(Writer writer) {
107: boolean result = super .start(writer);
108:
109: if (this .label == null) {
110: if ((rootNodeAttr == null)
111: || (childCollectionProperty == null)
112: || (nodeTitleProperty == null)
113: || (nodeIdProperty == null)) {
114: fieldError(
115: "label",
116: "The TreeTag requires either a value for 'label' or ALL of 'rootNode', "
117: + "'childCollectionProperty', 'nodeTitleProperty', and 'nodeIdProperty'",
118: null);
119: }
120: }
121: return result;
122: }
123:
124: protected void evaluateExtraParams() {
125: super .evaluateExtraParams();
126:
127: if (toggle != null) {
128: addParameter("toggle", findString(toggle));
129: }
130:
131: if (treeSelectedTopic != null) {
132: addParameter("treeSelectedTopic",
133: findString(treeSelectedTopic));
134: }
135:
136: if (treeExpandedTopic != null) {
137: addParameter("treeExpandedTopic",
138: findString(treeExpandedTopic));
139: }
140:
141: if (treeCollapsedTopic != null) {
142: addParameter("treeCollapsedTopic",
143: findString(treeCollapsedTopic));
144: }
145:
146: if (rootNodeAttr != null) {
147: addParameter("rootNode", findValue(rootNodeAttr));
148: }
149:
150: if (childCollectionProperty != null) {
151: addParameter("childCollectionProperty",
152: findString(childCollectionProperty));
153: }
154:
155: if (nodeTitleProperty != null) {
156: addParameter("nodeTitleProperty",
157: findString(nodeTitleProperty));
158: }
159:
160: if (nodeIdProperty != null) {
161: addParameter("nodeIdProperty", findString(nodeIdProperty));
162: }
163:
164: if (showRootGrid != null) {
165: addParameter("showRootGrid", findValue(showRootGrid,
166: Boolean.class));
167: }
168:
169: if (showGrid != null) {
170: addParameter("showGrid", findValue(showGrid, Boolean.class));
171: }
172:
173: if (blankIconSrc != null) {
174: addParameter("blankIconSrc", findString(blankIconSrc));
175: }
176:
177: if (gridIconSrcL != null) {
178: addParameter("gridIconSrcL", findString(gridIconSrcL));
179: }
180:
181: if (gridIconSrcV != null) {
182: addParameter("gridIconSrcV", findString(gridIconSrcV));
183: }
184:
185: if (gridIconSrcP != null) {
186: addParameter("gridIconSrcP", findString(gridIconSrcP));
187: }
188:
189: if (gridIconSrcC != null) {
190: addParameter("gridIconSrcC", findString(gridIconSrcC));
191: }
192:
193: if (gridIconSrcX != null) {
194: addParameter("gridIconSrcX", findString(gridIconSrcX));
195: }
196:
197: if (gridIconSrcY != null) {
198: addParameter("gridIconSrcY", findString(gridIconSrcY));
199: }
200:
201: if (expandIconSrcPlus != null) {
202: addParameter("expandIconSrcPlus",
203: findString(expandIconSrcPlus));
204: }
205:
206: if (expandIconSrcMinus != null) {
207: addParameter("expandIconSrcMinus",
208: findString(expandIconSrcMinus));
209: }
210:
211: if (iconWidth != null) {
212: addParameter("iconWidth", findValue(iconWidth,
213: Integer.class));
214: }
215: if (iconHeight != null) {
216: addParameter("iconHeight", findValue(iconHeight,
217: Integer.class));
218: }
219: if (toggleDuration != null) {
220: addParameter("toggleDuration", findValue(toggleDuration,
221: Integer.class));
222: }
223: if (templateCssPath != null) {
224: addParameter("templateCssPath", findString(templateCssPath));
225: }
226: }
227:
228: public String getDefaultOpenTemplate() {
229: return OPEN_TEMPLATE;
230: }
231:
232: protected String getDefaultTemplate() {
233: return TEMPLATE;
234: }
235:
236: public String getToggle() {
237: return toggle;
238: }
239:
240: @StrutsTagAttribute(description="The toggle property (either 'explode' or 'fade')",defaultValue="fade")
241: public void setToggle(String toggle) {
242: this .toggle = toggle;
243: }
244:
245: public String getTreeSelectedTopic() {
246: return treeSelectedTopic;
247: }
248:
249: @StrutsTagAttribute(description="The treeSelectedTopic property")
250: public void setTreeSelectedTopic(String treeSelectedTopic) {
251: this .treeSelectedTopic = treeSelectedTopic;
252: }
253:
254: public String getTreeExpandedTopic() {
255: return treeExpandedTopic;
256: }
257:
258: @StrutsTagAttribute(description="The treeExpandedTopic property.")
259: public void setTreeExpandedTopic(String treeExpandedTopic) {
260: this .treeExpandedTopic = treeExpandedTopic;
261: }
262:
263: public String getTreeCollapsedTopic() {
264: return treeCollapsedTopic;
265: }
266:
267: @StrutsTagAttribute(description="The treeCollapsedTopic property.")
268: public void setTreeCollapsedTopic(String treeCollapsedTopic) {
269: this .treeCollapsedTopic = treeCollapsedTopic;
270: }
271:
272: public String getRootNode() {
273: return rootNodeAttr;
274: }
275:
276: @StrutsTagAttribute(description="The rootNode property.")
277: public void setRootNode(String rootNode) {
278: this .rootNodeAttr = rootNode;
279: }
280:
281: public String getChildCollectionProperty() {
282: return childCollectionProperty;
283: }
284:
285: @StrutsTagAttribute(description="The childCollectionProperty property.")
286: public void setChildCollectionProperty(
287: String childCollectionProperty) {
288: this .childCollectionProperty = childCollectionProperty;
289: }
290:
291: public String getNodeTitleProperty() {
292: return nodeTitleProperty;
293: }
294:
295: @StrutsTagAttribute(description="The nodeTitleProperty property.")
296: public void setNodeTitleProperty(String nodeTitleProperty) {
297: this .nodeTitleProperty = nodeTitleProperty;
298: }
299:
300: public String getNodeIdProperty() {
301: return nodeIdProperty;
302: }
303:
304: @StrutsTagAttribute(description="The nodeIdProperty property.")
305: public void setNodeIdProperty(String nodeIdProperty) {
306: this .nodeIdProperty = nodeIdProperty;
307: }
308:
309: @StrutsTagAttribute(description="The showRootGrid property (default true).")
310: public void setShowRootGrid(String showRootGrid) {
311: this .showRootGrid = showRootGrid;
312: }
313:
314: public String getShowRootGrid() {
315: return showRootGrid;
316: }
317:
318: public String getBlankIconSrc() {
319: return blankIconSrc;
320: }
321:
322: @StrutsTagAttribute(description="Blank icon image source.")
323: public void setBlankIconSrc(String blankIconSrc) {
324: this .blankIconSrc = blankIconSrc;
325: }
326:
327: public String getExpandIconSrcMinus() {
328: return expandIconSrcMinus;
329: }
330:
331: @StrutsTagAttribute(description="Expand icon (-) image source.")
332: public void setExpandIconSrcMinus(String expandIconSrcMinus) {
333: this .expandIconSrcMinus = expandIconSrcMinus;
334: }
335:
336: public String getExpandIconSrcPlus() {
337: return expandIconSrcPlus;
338: }
339:
340: @StrutsTagAttribute(description="Expand Icon (+) image source.")
341: public void setExpandIconSrcPlus(String expandIconSrcPlus) {
342: this .expandIconSrcPlus = expandIconSrcPlus;
343: }
344:
345: public String getGridIconSrcC() {
346: return gridIconSrcC;
347: }
348:
349: @StrutsTagAttribute(description="Image source for under child item child icons.")
350: public void setGridIconSrcC(String gridIconSrcC) {
351: this .gridIconSrcC = gridIconSrcC;
352: }
353:
354: public String getGridIconSrcL() {
355: return gridIconSrcL;
356: }
357:
358: @StrutsTagAttribute(description=" Image source for last child grid.")
359: public void setGridIconSrcL(String gridIconSrcL) {
360: this .gridIconSrcL = gridIconSrcL;
361: }
362:
363: public String getGridIconSrcP() {
364: return gridIconSrcP;
365: }
366:
367: @StrutsTagAttribute(description="Image source for under parent item child icons.")
368: public void setGridIconSrcP(String gridIconSrcP) {
369: this .gridIconSrcP = gridIconSrcP;
370: }
371:
372: public String getGridIconSrcV() {
373: return gridIconSrcV;
374: }
375:
376: @StrutsTagAttribute(description="Image source for vertical line.")
377: public void setGridIconSrcV(String gridIconSrcV) {
378: this .gridIconSrcV = gridIconSrcV;
379: }
380:
381: public String getGridIconSrcX() {
382: return gridIconSrcX;
383: }
384:
385: @StrutsTagAttribute(description="Image source for grid for sole root item.")
386: public void setGridIconSrcX(String gridIconSrcX) {
387: this .gridIconSrcX = gridIconSrcX;
388: }
389:
390: public String getGridIconSrcY() {
391: return gridIconSrcY;
392: }
393:
394: @StrutsTagAttribute(description="Image source for grid for last root item.")
395: public void setGridIconSrcY(String gridIconSrcY) {
396: this .gridIconSrcY = gridIconSrcY;
397: }
398:
399: public String getIconHeight() {
400: return iconHeight;
401: }
402:
403: @StrutsTagAttribute(description="Icon height",defaultValue="18px")
404: public void setIconHeight(String iconHeight) {
405: this .iconHeight = iconHeight;
406: }
407:
408: public String getIconWidth() {
409: return iconWidth;
410: }
411:
412: @StrutsTagAttribute(description="Icon width",defaultValue="19px")
413: public void setIconWidth(String iconWidth) {
414: this .iconWidth = iconWidth;
415: }
416:
417: public String getTemplateCssPath() {
418: return templateCssPath;
419: }
420:
421: @StrutsTagAttribute(description="Template css path",defaultValue="{contextPath}/struts/tree.css.")
422: public void setTemplateCssPath(String templateCssPath) {
423: this .templateCssPath = templateCssPath;
424: }
425:
426: public String getToggleDuration() {
427: return toggleDuration;
428: }
429:
430: @StrutsTagAttribute(description="Toggle duration in milliseconds",defaultValue="150")
431: public void setToggleDuration(String toggleDuration) {
432: this .toggleDuration = toggleDuration;
433: }
434:
435: public String getShowGrid() {
436: return showGrid;
437: }
438:
439: @StrutsTagAttribute(description="Show grid",type="Boolean",defaultValue="true")
440: public void setShowGrid(String showGrid) {
441: this.showGrid = showGrid;
442: }
443: }
|