From 9cf677072d910b0cb8ff86a168683782c2d084b3 Mon Sep 17 00:00:00 2001 From: Toby Jee Date: Sat, 20 May 2006 16:11:06 +0000 Subject: [PATCH] WW-1316 git-svn-id: https://svn.apache.org/repos/asf/struts/action2/trunk@408016 13f79535-47bb-0310-9956-ffa450edef68 --- .../struts/action2/components/Tree.java | 277 ++++++++++++- .../action2/views/jsp/ui/TreeNodeTag.java | 5 +- .../struts/action2/views/jsp/ui/TreeTag.java | 207 +++++++++- core/src/main/resources/META-INF/taglib.tld | 386 +++++++++++++++++- .../org/apache/struts/action2/static/tree.css | 29 ++ .../src/main/resources/template/ajax/tree.ftl | 61 ++- .../main/resources/template/ajax/treenode.ftl | 7 +- .../struts/action2/views/jsp/ui/Category.java | 104 +++++ .../struts/action2/views/jsp/ui/TreeTest.java | 133 ++++++ .../struts/action2/views/jsp/ui/tree-1.txt | 42 ++ .../struts/action2/views/jsp/ui/tree-2.txt | 70 ++++ 11 files changed, 1262 insertions(+), 59 deletions(-) create mode 100644 core/src/main/resources/org/apache/struts/action2/static/tree.css create mode 100644 core/src/test/java/org/apache/struts/action2/views/jsp/ui/Category.java create mode 100644 core/src/test/java/org/apache/struts/action2/views/jsp/ui/TreeTest.java create mode 100644 core/src/test/resources/org/apache/struts/action2/views/jsp/ui/tree-1.txt create mode 100644 core/src/test/resources/org/apache/struts/action2/views/jsp/ui/tree-2.txt diff --git a/core/src/main/java/org/apache/struts/action2/components/Tree.java b/core/src/main/java/org/apache/struts/action2/components/Tree.java index b7602ea8c..72a9b144b 100644 --- a/core/src/main/java/org/apache/struts/action2/components/Tree.java +++ b/core/src/main/java/org/apache/struts/action2/components/Tree.java @@ -25,17 +25,34 @@ import java.io.Writer; * description="Render a tree widget." */ public class Tree extends ClosingUIBean { - private static final String TEMPLATE = "tree-close"; + + private static final String TEMPLATE = "tree-close"; private static final String OPEN_TEMPLATE = "tree"; + private String toggle = "fade"; private String treeSelectedTopic; private String treeExpandedTopic; private String treeCollapsedTopic; - private String openAll; protected String rootNodeAttr; protected String childCollectionProperty; protected String nodeTitleProperty; protected String nodeIdProperty; + private String showRootGrid; + + private String showGrid; + private String blankIconSrc; + private String gridIconSrcL; + private String gridIconSrcV; + private String gridIconSrcP; + private String gridIconSrcC; + private String gridIconSrcX; + private String gridIconSrcY; + private String expandIconSrcPlus; + private String expandIconSrcMinus; + private String iconWidth; + private String iconHeight; + private String toggleDuration; + private String templateCssPath; public Tree(OgnlValueStack stack, HttpServletRequest request, HttpServletResponse response) { super(stack, request, response); @@ -75,8 +92,6 @@ public class Tree extends ClosingUIBean { addParameter("treeCollapsedTopic", findString(treeCollapsedTopic)); } - addParameter("openAll", Boolean.valueOf(openAll)); - if (rootNodeAttr != null) { addParameter("rootNode", findValue(rootNodeAttr)); } @@ -92,6 +107,64 @@ public class Tree extends ClosingUIBean { if (nodeIdProperty != null) { addParameter("nodeIdProperty", findString(nodeIdProperty)); } + + if (showRootGrid != null) { + addParameter("showRootGrid", findValue(showRootGrid, Boolean.class)); + } + + + if (showGrid != null) { + addParameter("showGrid", findValue(showGrid, Boolean.class)); + } + + if (blankIconSrc != null) { + addParameter("blankIconSrc", findString(blankIconSrc)); + } + + if (gridIconSrcL != null) { + addParameter("gridIconSrcL", findString(gridIconSrcL)); + } + + if (gridIconSrcV != null) { + addParameter("gridIconSrcV", findString(gridIconSrcV)); + } + + if (gridIconSrcP != null) { + addParameter("gridIconSrcP", findString(gridIconSrcP)); + } + + if (gridIconSrcC != null) { + addParameter("gridIconSrcC", findString(gridIconSrcC)); + } + + if (gridIconSrcX != null) { + addParameter("gridIconSrcX", findString(gridIconSrcX)); + } + + if (gridIconSrcY != null) { + addParameter("gridIconSrcY", findString(gridIconSrcY)); + } + + if (expandIconSrcPlus != null) { + addParameter("expandIconSrcPlus", findString(expandIconSrcPlus)); + } + + if (expandIconSrcMinus != null) { + addParameter("expandIconSrcMinus", findString(expandIconSrcMinus)); + } + + if (iconWidth != null) { + addParameter("iconWidth", findValue(iconWidth, Integer.class)); + } + if (iconHeight != null) { + addParameter("iconHeight", findValue(iconHeight, Integer.class)); + } + if (toggleDuration != null) { + addParameter("toggleDuration", findValue(toggleDuration, Integer.class)); + } + if (templateCssPath != null) { + addParameter("templateCssPath", findString(templateCssPath)); + } } public String getDefaultOpenTemplate() { @@ -107,7 +180,7 @@ public class Tree extends ClosingUIBean { } /** - * The toggle property. + * The toggle property (either 'explode' or 'fade'). Default is 'fade'. * @a2.tagattribute required="false" */ public void setToggle(String toggle) { @@ -150,18 +223,6 @@ public class Tree extends ClosingUIBean { this.treeCollapsedTopic = treeCollapsedTopic; } - public String getOpenAll() { - return openAll; - } - - /** - * The openAll property. - * @a2.tagattribute required="false" type="boolean" default="false" - */ - public void setOpenAll(String openAll) { - this.openAll = openAll; - } - public String getRootNode() { return rootNodeAttr; } @@ -209,7 +270,189 @@ public class Tree extends ClosingUIBean { public void setNodeIdProperty(String nodeIdProperty) { this.nodeIdProperty = nodeIdProperty; } + + /** + * The showRootGrid property (default true). + * @a2.tagattribute required="false" + */ + public void setShowRootGrid(String showRootGrid) { + this.showRootGrid = showRootGrid; + } + + public String getShowRootGrid() { + return showRootGrid; + } + public String getBlankIconSrc() { + return blankIconSrc; + } + /** + * Blank icon image source. + * @a2.tagattribute required="false" + */ + public void setBlankIconSrc(String blankIconSrc) { + this.blankIconSrc = blankIconSrc; + } + + public String getExpandIconSrcMinus() { + return expandIconSrcMinus; + } + + /** + * Expand icon (-) image source. + * @a2.tagattribute required="false" + */ + public void setExpandIconSrcMinus(String expandIconSrcMinus) { + this.expandIconSrcMinus = expandIconSrcMinus; + } + + public String getExpandIconSrcPlus() { + return expandIconSrcPlus; + } + + /** + * Expand Icon (+) image source. + * @a2.tagattribute required="false" + */ + public void setExpandIconSrcPlus(String expandIconSrcPlus) { + this.expandIconSrcPlus = expandIconSrcPlus; + } + + public String getGridIconSrcC() { + return gridIconSrcC; + } + + /** + * Image source for under child item child icons. + * @a2.tagattribute required="false" + */ + public void setGridIconSrcC(String gridIconSrcC) { + this.gridIconSrcC = gridIconSrcC; + } + + public String getGridIconSrcL() { + return gridIconSrcL; + } + + + /** + * Image source for last child grid. + * @a2.tagattribute required="false" + */ + public void setGridIconSrcL(String gridIconSrcL) { + this.gridIconSrcL = gridIconSrcL; + } + + public String getGridIconSrcP() { + return gridIconSrcP; + } + + /** + * Image source for under parent item child icons. + * @a2.tagattribute required="false" + */ + public void setGridIconSrcP(String gridIconSrcP) { + this.gridIconSrcP = gridIconSrcP; + } + + public String getGridIconSrcV() { + return gridIconSrcV; + } + + /** + * Image source for vertical line. + * @a2.tagattribute required="false" + */ + public void setGridIconSrcV(String gridIconSrcV) { + this.gridIconSrcV = gridIconSrcV; + } + + public String getGridIconSrcX() { + return gridIconSrcX; + } + + /** + * Image source for grid for sole root item. + * @a2.tagattribute required="false" + */ + public void setGridIconSrcX(String gridIconSrcX) { + this.gridIconSrcX = gridIconSrcX; + } + + public String getGridIconSrcY() { + return gridIconSrcY; + } + + /** + * Image source for grid for last root item. + * @a2.tagattribute required="false" + */ + public void setGridIconSrcY(String gridIconSrcY) { + this.gridIconSrcY = gridIconSrcY; + } + + public String getIconHeight() { + return iconHeight; + } + + + /** + * Icon height (default 18 pixels). + * @a2.tagattribute required="false" + */ + public void setIconHeight(String iconHeight) { + this.iconHeight = iconHeight; + } + + public String getIconWidth() { + return iconWidth; + } + + /** + * Icon width (default 19 pixels). + * @a2.tagattribute required="false" + */ + public void setIconWidth(String iconWidth) { + this.iconWidth = iconWidth; + } + + + + public String getTemplateCssPath() { + return templateCssPath; + } + + /** + * Template css path (default {contextPath}/struts/tree.css. + * @a2.tagattribute required="false" + */ + public void setTemplateCssPath(String templateCssPath) { + this.templateCssPath = templateCssPath; + } + + public String getToggleDuration() { + return toggleDuration; + } + + /** + * Toggle duration (default 150 ms) + * @a2.tagattribute required="false" + */ + public void setToggleDuration(String toggleDuration) { + this.toggleDuration = toggleDuration; + } + + public String getShowGrid() { + return showGrid; + } + + /** + * Show grid (default true). + * @a2.tagattribute required="false" + */ + public void setShowGrid(String showGrid) { + this.showGrid = showGrid; + } } diff --git a/core/src/main/java/org/apache/struts/action2/views/jsp/ui/TreeNodeTag.java b/core/src/main/java/org/apache/struts/action2/views/jsp/ui/TreeNodeTag.java index e4817686e..4e78fefbf 100644 --- a/core/src/main/java/org/apache/struts/action2/views/jsp/ui/TreeNodeTag.java +++ b/core/src/main/java/org/apache/struts/action2/views/jsp/ui/TreeNodeTag.java @@ -31,7 +31,6 @@ public class TreeNodeTag extends AbstractClosingTag { private static final long serialVersionUID = 7340746943017900803L; - private String label; public Component getBean(OgnlValueStack stack, HttpServletRequest req, HttpServletResponse res) { return new TreeNode(stack,req,res); @@ -41,11 +40,11 @@ public class TreeNodeTag extends AbstractClosingTag { this.label = label; } - protected void populateParams() { + /*protected void populateParams() { if (label != null) { TreeNode treeNode = (TreeNode)component; treeNode.setLabel(label); } super.populateParams(); - } + }*/ } diff --git a/core/src/main/java/org/apache/struts/action2/views/jsp/ui/TreeTag.java b/core/src/main/java/org/apache/struts/action2/views/jsp/ui/TreeTag.java index 6fdfdc2e3..5397fb2e6 100644 --- a/core/src/main/java/org/apache/struts/action2/views/jsp/ui/TreeTag.java +++ b/core/src/main/java/org/apache/struts/action2/views/jsp/ui/TreeTag.java @@ -34,15 +34,30 @@ public class TreeTag extends AbstractClosingTag { private String toggle; private String treeSelectedTopic; private String treeExpandedTopic; - private String treeCollapsedTopic; - private String openAll; + private String treeCollapsedTopic; private String rootNode; private String childCollectionProperty; private String nodeTitleProperty; private String nodeIdProperty; + private String showRootGrid; + + private String showGrid; + private String blankIconSrc; + private String gridIconSrcL; + private String gridIconSrcV; + private String gridIconSrcP; + private String gridIconSrcC; + private String gridIconSrcX; + private String gridIconSrcY; + private String expandIconSrcPlus; + private String expandIconSrcMinus; + private String iconWidth; + private String iconHeight; + private String toggleDuration; + private String templateCssPath; + - - public Component getBean(OgnlValueStack stack, HttpServletRequest req, HttpServletResponse res) { + public Component getBean(OgnlValueStack stack, HttpServletRequest req, HttpServletResponse res) { return new Tree(stack,req,res); } @@ -50,15 +65,53 @@ public class TreeTag extends AbstractClosingTag { super.populateParams(); Tree tree = (Tree) component; - tree.setChildCollectionProperty(childCollectionProperty); - tree.setNodeIdProperty(nodeIdProperty); - tree.setNodeTitleProperty(nodeTitleProperty); - tree.setOpenAll(openAll); - tree.setRootNode(rootNode); - tree.setToggle(toggle); - tree.setTreeCollapsedTopic(treeCollapsedTopic); - tree.setTreeExpandedTopic(treeExpandedTopic); - tree.setTreeSelectedTopic(treeSelectedTopic); + if (childCollectionProperty != null) + tree.setChildCollectionProperty(childCollectionProperty); + if (nodeIdProperty != null) + tree.setNodeIdProperty(nodeIdProperty); + if (nodeTitleProperty != null) + tree.setNodeTitleProperty(nodeTitleProperty); + if (rootNode != null) + tree.setRootNode(rootNode); + if (toggle != null) + tree.setToggle(toggle); + if (treeCollapsedTopic != null) + tree.setTreeCollapsedTopic(treeCollapsedTopic); + if (treeExpandedTopic != null) + tree.setTreeExpandedTopic(treeExpandedTopic); + if (treeSelectedTopic != null) + tree.setTreeSelectedTopic(treeSelectedTopic); + if (showRootGrid != null) + tree.setShowRootGrid(showRootGrid); + + if (showGrid != null) + tree.setShowGrid(showGrid); + if (blankIconSrc != null) + tree.setBlankIconSrc(blankIconSrc); + if (gridIconSrcL != null) + tree.setGridIconSrcL(gridIconSrcC); + if (gridIconSrcV != null) + tree.setGridIconSrcV(gridIconSrcV); + if (gridIconSrcP != null) + tree.setGridIconSrcP(gridIconSrcP); + if (gridIconSrcC != null) + tree.setGridIconSrcC(gridIconSrcC); + if (gridIconSrcX != null) + tree.setGridIconSrcX(gridIconSrcX); + if (gridIconSrcY != null) + tree.setGridIconSrcY(gridIconSrcY); + if (expandIconSrcPlus != null) + tree.setExpandIconSrcPlus(expandIconSrcPlus); + if (expandIconSrcMinus != null) + tree.setExpandIconSrcMinus(expandIconSrcMinus); + if (iconWidth != null) + tree.setIconWidth(iconWidth); + if (iconHeight != null) + tree.setIconHeight(iconHeight); + if (toggleDuration != null) + tree.setToggleDuration(toggleDuration); + if (templateCssPath != null) + tree.setTemplateCssPath(templateCssPath); } public String getToggle() { @@ -93,14 +146,6 @@ public class TreeTag extends AbstractClosingTag { this.treeCollapsedTopic = treeCollapsedTopic; } - public String getOpenAll() { - return openAll; - } - - public void setOpenAll(String openAll) { - this.openAll = openAll; - } - public String getRootNode() { return rootNode; } @@ -132,5 +177,125 @@ public class TreeTag extends AbstractClosingTag { public void setNodeIdProperty(String nodeIdProperty) { this.nodeIdProperty = nodeIdProperty; } + + public String getShowRootGrid() { + return showRootGrid; + } + + public void setShowRootGrid(String showRootGrid) { + this.showRootGrid = showRootGrid; + } + + public String getBlankIconSrc() { + return blankIconSrc; + } + + public void setBlankIconSrc(String blankIconSrc) { + this.blankIconSrc = blankIconSrc; + } + + public String getExpandIconSrcMinus() { + return expandIconSrcMinus; + } + + public void setExpandIconSrcMinus(String expandIconSrcMinus) { + this.expandIconSrcMinus = expandIconSrcMinus; + } + + public String getExpandIconSrcPlus() { + return expandIconSrcPlus; + } + + public void setExpandIconSrcPlus(String expandIconSrcPlus) { + this.expandIconSrcPlus = expandIconSrcPlus; + } + + public String getGridIconSrcC() { + return gridIconSrcC; + } + + public void setGridIconSrcC(String gridIconSrcC) { + this.gridIconSrcC = gridIconSrcC; + } + + public String getGridIconSrcL() { + return gridIconSrcL; + } + + public void setGridIconSrcL(String gridIconSrcL) { + this.gridIconSrcL = gridIconSrcL; + } + + public String getGridIconSrcP() { + return gridIconSrcP; + } + + public void setGridIconSrcP(String gridIconSrcP) { + this.gridIconSrcP = gridIconSrcP; + } + + public String getGridIconSrcV() { + return gridIconSrcV; + } + + public void setGridIconSrcV(String gridIconSrcV) { + this.gridIconSrcV = gridIconSrcV; + } + + public String getGridIconSrcX() { + return gridIconSrcX; + } + + public void setGridIconSrcX(String gridIconSrcX) { + this.gridIconSrcX = gridIconSrcX; + } + + public String getGridIconSrcY() { + return gridIconSrcY; + } + + public void setGridIconSrcY(String gridIconSrcY) { + this.gridIconSrcY = gridIconSrcY; + } + + public String getIconHeight() { + return iconHeight; + } + + public void setIconHeight(String iconHeight) { + this.iconHeight = iconHeight; + } + + public String getIconWidth() { + return iconWidth; + } + + public void setIconWidth(String iconWidth) { + this.iconWidth = iconWidth; + } + + public String getTemplateCssPath() { + return templateCssPath; + } + + public void setTemplateCssPath(String templateCssPath) { + this.templateCssPath = templateCssPath; + } + + public String getToggleDuration() { + return toggleDuration; + } + + public void setToggleDuration(String toggleDuration) { + this.toggleDuration = toggleDuration; + } + + public String getShowGrid() { + return showGrid; + } + + public void setShowGrid(String showGrid) { + this.showGrid = showGrid; + } } diff --git a/core/src/main/resources/META-INF/taglib.tld b/core/src/main/resources/META-INF/taglib.tld index 4d89f6508..3f7dff3bd 100644 --- a/core/src/main/resources/META-INF/taglib.tld +++ b/core/src/main/resources/META-INF/taglib.tld @@ -130,6 +130,14 @@ + + + templateDir + false + true + + + theme @@ -475,6 +483,14 @@ + + + templateDir + false + true + + + theme @@ -1005,6 +1021,14 @@ + + + templateDir + false + true + + + theme @@ -1311,6 +1335,14 @@ + + + templateDir + false + true + + + theme @@ -1648,7 +1680,7 @@ false true - + @@ -1674,14 +1706,6 @@ - - - openAll - false - true - - - rootNode @@ -1714,6 +1738,126 @@ + + + showRootGrid + false + true + + + + + + blankIconSrc + false + true + + + + + + expandIconSrcMinus + false + true + + + + + + expandIconSrcPlus + false + true + + + + + + gridIconSrcC + false + true + + + + + + gridIconSrcL + false + true + + + + + + gridIconSrcP + false + true + + + + + + gridIconSrcV + false + true + + + + + + gridIconSrcX + false + true + + + + + + gridIconSrcY + false + true + + + + + + iconHeight + false + true + + + + + + iconWidth + false + true + + + + + + templateCssPath + false + true + + + + + + toggleDuration + false + true + + + + + + showGrid + false + true + + + openTemplate @@ -1722,6 +1866,14 @@ + + + templateDir + false + true + + + theme @@ -2283,6 +2435,14 @@ + + + templateDir + false + true + + + theme @@ -3004,6 +3164,14 @@ + + + templateDir + false + true + + + theme @@ -3374,6 +3542,14 @@ input, button and image.]]> + + + templateDir + false + true + + + theme @@ -3844,6 +4020,14 @@ JSP + + templateDir + false + true + + + + theme false @@ -4101,6 +4285,14 @@ JSP + + templateDir + false + true + + + + theme false @@ -4358,6 +4550,14 @@ JSP + + templateDir + false + true + + + + theme false @@ -4640,6 +4840,14 @@ empty + + templateDir + false + true + + + + theme false @@ -4993,6 +5201,14 @@ + + + templateDir + false + true + + + template @@ -5332,6 +5548,14 @@ + + + templateDir + false + true + + + theme @@ -5629,6 +5853,14 @@ + + + templateDir + false + true + + + theme @@ -6302,6 +6534,14 @@ + + + templateDir + false + true + + + theme @@ -6567,6 +6807,14 @@ + + + templateDir + false + true + + + theme @@ -6921,6 +7169,14 @@ + + + templateDir + false + true + + + theme @@ -7243,6 +7499,14 @@ input, button and image.]]> + + + templateDir + false + true + + + theme @@ -7516,6 +7780,14 @@ + + + templateDir + false + true + + + theme @@ -7805,6 +8077,14 @@ + + + templateDir + false + true + + + theme @@ -8063,6 +8343,14 @@ empty + + templateDir + false + true + + + + theme false @@ -8335,6 +8623,14 @@ + + + templateDir + false + true + + + theme @@ -8673,6 +8969,14 @@ + + + templateDir + false + true + + + theme @@ -8946,6 +9250,14 @@ + + + templateDir + false + true + + + theme @@ -9204,6 +9516,14 @@ JSP + + templateDir + false + true + + + + theme false @@ -9492,6 +9812,14 @@ + + + templateDir + false + true + + + theme @@ -9773,6 +10101,14 @@ + + + templateDir + false + true + + + theme @@ -10102,6 +10438,14 @@ + + + templateDir + false + true + + + template @@ -10375,6 +10719,14 @@ + + + templateDir + false + true + + + theme @@ -10696,6 +11048,14 @@ + + + templateDir + false + true + + + theme @@ -11082,6 +11442,14 @@ + + + templateDir + false + true + + + template diff --git a/core/src/main/resources/org/apache/struts/action2/static/tree.css b/core/src/main/resources/org/apache/struts/action2/static/tree.css new file mode 100644 index 000000000..0af721d4d --- /dev/null +++ b/core/src/main/resources/org/apache/struts/action2/static/tree.css @@ -0,0 +1,29 @@ +.dojoTree { + font: caption; + font-size: 11px; + font-weight: normal; + overflow: auto; +} + +.dojoTreeNodeLabel { + padding: 1px 2px; + color: WindowText; + cursor: default; +} + +.dojoTreeNodeLabel:hover { + text-decoration: underline; +} + +.dojoTreeNodeLabelSelected { + background-color: Highlight; + color: HighlightText; +} + +.dojoTree div { + white-space: nowrap; +} + +.dojoTree img { + vertical-align: middle; +} diff --git a/core/src/main/resources/template/ajax/tree.ftl b/core/src/main/resources/template/ajax/tree.ftl index 897e0a28a..70b5070da 100644 --- a/core/src/main/resources/template/ajax/tree.ftl +++ b/core/src/main/resources/template/ajax/tree.ftl @@ -6,8 +6,58 @@ // dojo.hostenv.writeIncludes(); --> -
id="${parameters.id?html}" +
+ gridIconSrcT="<@saf.url value='${parameters.blankIconSrc}' encode="false" />" + + <#if parameters.gridIconSrcL?exists> + gridIconSrcL="<@saf.url value='${parameters.gridIconSrcL}' encode="false" />" + + <#if parameters.gridIconSrcV?exists> + gridIconSrcV="<@saf.url value='${parameters.gridIconSrcV}' encode="false" />" + + <#if parameters.gridIconSrcP?exists> + gridIconSrcP="<@saf.url value='${parameters.gridIconSrcP}' encode="false" />" + + <#if parameters.gridIconSrcC?exists> + gridIconSrcC="<@saf.url value='${parameters.gridIconSrcC}' encode="false" />" + + <#if parameters.gridIconSrcX?exists> + gridIconSrcX="<@saf.url value='${parameters.gridIconSrcX}' encode="false" />" + + <#if parameters.gridIconSrcY?exists> + gridIconSrcY="<@saf.url value='${parameters.gridIconSrcY}' encode="false" />" + + <#if parameters.gridIconSrcZ?exists> + gridIconSrcZ="<@saf.url value='${parameters.gridIconSrcZ}' encode="false" />" + + <#if parameters.expandIconSrcPlus?exists> + expandIconSrcPlus="<@saf.url value='${parameters.expandIconSrcPlus}' />" + + <#if parameters.expandIconSrcMinus?exists> + expandIconSrcMinus="<@saf.url value='${parameters.expandIconSrcMinus?html}' />" + + <#if parameters.iconWidth?exists> + iconWidth="<@saf.url value='${parameters.iconWidth?html}' encode="false" />" + + <#if parameters.iconHeight?exists> + iconHeight="<@saf.url value='${parameters.iconHeight?html}' encode="false" />" + + <#if parameters.toggleDuration?exists> + toggleDuration=${parameters.toggleDuration?c} + + <#if parameters.templateCssPath?exists> + templateCssPath="<@saf.url value='${parameters.templateCssPath}' encode="false" />" + + <#if parameters.showGrid?exists> + showGrid="${parameters.showGrid?default(true)?string}" + + <#if parameters.showRootGrid?exists> + showRootGrid="${parameters.showRootGrid?default(true)?string}" + + <#if parameters.id?exists> + id="${parameters.id?html}" + <#if parameters.treeSelectedTopic?exists> publishSelectionTopic="${parameters.treeSelectedTopic?html}" @@ -18,14 +68,11 @@ publishCollapsedTopic="${parameters.treeCollapsedTopic?html}" <#if parameters.toggle?exists> - toggle="${parameters.toggle}" - - <#if parameters.openAll?exists> - openAll="${parameters.openAll?string}" + toggle="${parameters.toggle?html}" > <#if parameters.label?exists> -
id="${stack.findValue(parameters.nodeIdProperty)}" diff --git a/core/src/main/resources/template/ajax/treenode.ftl b/core/src/main/resources/template/ajax/treenode.ftl index 08dac5713..b24fc2ee2 100644 --- a/core/src/main/resources/template/ajax/treenode.ftl +++ b/core/src/main/resources/template/ajax/treenode.ftl @@ -1,3 +1,6 @@ -
+ childIconSrc="<@saf.url value='${parameters.childIconSrc}' encode="false" />" + <#if parameters.id?exists>id="${parameters.id?html}" - title="${parameters.label?html}"> + title="${parameters.label}"> diff --git a/core/src/test/java/org/apache/struts/action2/views/jsp/ui/Category.java b/core/src/test/java/org/apache/struts/action2/views/jsp/ui/Category.java new file mode 100644 index 000000000..fc3553eda --- /dev/null +++ b/core/src/test/java/org/apache/struts/action2/views/jsp/ui/Category.java @@ -0,0 +1,104 @@ +/* + * $Id: AbstractUITagTest.java 394477 2006-04-16 12:50:53Z tmjee $ + * + * Copyright 2006 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.struts.action2.views.jsp.ui; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * Used by Tree Component Test. Copied from showcase. + */ +public class Category { + private static Map catMap = new HashMap(); + + static { + new Category(1, "Root", + new Category(2, "Java", + new Category(3, "Web Frameworks", + new Category(4, "WebWork"), + new Category(5, "Struts Action"), + new Category(6, "Struts Shale"), + new Category(7, "Stripes"), + new Category(8, "Rife")), + new Category(9, "Persistence", + new Category(10, "iBatis"), + new Category(11, "Hibernate"), + new Category(12, "JDO"), + new Category(13, "JDBC"))), + new Category(14, "JavaScript", + new Category(15, "Dojo"), + new Category(16, "Prototype"), + new Category(17, "Scriptaculous"), + new Category(18, "OpenRico"), + new Category(19, "DWR"))); + } + + public static Category getById(long id) { + return catMap.get(id); + } + + private long id; + private String name; + private List children; + private boolean toggle; + + public Category(long id, String name, Category... children) { + this.id = id; + this.name = name; + this.children = new ArrayList(); + for (Category child : children) { + this.children.add(child); + } + + catMap.put(id, this); + } + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public List getChildren() { + return children; + } + + public void setChildren(List children) { + this.children = children; + } + + public void toggle() { + toggle = !toggle; + } + + public boolean isToggle() { + return toggle; + } +} diff --git a/core/src/test/java/org/apache/struts/action2/views/jsp/ui/TreeTest.java b/core/src/test/java/org/apache/struts/action2/views/jsp/ui/TreeTest.java new file mode 100644 index 000000000..84c21f934 --- /dev/null +++ b/core/src/test/java/org/apache/struts/action2/views/jsp/ui/TreeTest.java @@ -0,0 +1,133 @@ +/* + * $Id: AbstractUITagTest.java 394477 2006-04-16 12:50:53Z tmjee $ + * + * Copyright 2006 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.struts.action2.views.jsp.ui; + +import org.apache.struts.action2.views.jsp.AbstractUITagTest; + +import com.opensymphony.xwork.Action; +import com.opensymphony.xwork.ActionSupport; + +/** + * Test case for Tree component. + */ +public class TreeTest extends AbstractUITagTest{ + + public void testStaticTree() throws Exception { + // Root + TreeTag tag = new TreeTag(); + tag.setShowRootGrid("false"); + tag.setShowGrid("false"); + tag.setTemplateCssPath("/struts/tree.css"); + tag.setTheme("ajax"); + tag.setPageContext(pageContext); + tag.setId("rootId"); + tag.setLabel("Root"); + tag.doStartTag(); + + // Child 1 + TreeNodeTag nodeTag1 = new TreeNodeTag(); + nodeTag1.setTheme("ajax"); + nodeTag1.setPageContext(pageContext); + nodeTag1.setId("child1"); + nodeTag1.setLabel("Child 1"); + nodeTag1.doStartTag(); + nodeTag1.doEndTag(); + + // Child 2 + TreeNodeTag nodeTag2 = new TreeNodeTag(); + nodeTag2.setTheme("ajax"); + nodeTag2.setPageContext(pageContext); + nodeTag2.setId("child2"); + nodeTag2.setLabel("Child 2"); + nodeTag2.doStartTag(); + + // Grand Child 1 + TreeNodeTag gNodeTag1 = new TreeNodeTag(); + gNodeTag1.setTheme("ajax"); + gNodeTag1.setPageContext(pageContext); + gNodeTag1.setId("gChild1"); + gNodeTag1.setLabel("Grand Child 1"); + gNodeTag1.doStartTag(); + gNodeTag1.doEndTag(); + + // Grand Child 2 + TreeNodeTag gNodeTag2 = new TreeNodeTag(); + gNodeTag2.setTheme("ajax"); + gNodeTag2.setPageContext(pageContext); + gNodeTag2.setId("gChild2"); + gNodeTag2.setLabel("Grand Child 2"); + gNodeTag2.doStartTag(); + gNodeTag2.doEndTag(); + + // Grand Child 3 + TreeNodeTag gNodeTag3= new TreeNodeTag(); + gNodeTag3.setTheme("ajax"); + gNodeTag3.setPageContext(pageContext); + gNodeTag3.setId("gChild3"); + gNodeTag3.setLabel("Grand Child 3"); + gNodeTag3.doStartTag(); + gNodeTag3.doEndTag(); + + nodeTag2.doEndTag(); + + + // Child 3 + TreeNodeTag nodeTag3 = new TreeNodeTag(); + nodeTag3.setTheme("ajax"); + nodeTag3.setPageContext(pageContext); + nodeTag3.setId("child3"); + nodeTag3.setLabel("Child 4"); + nodeTag3.doStartTag(); + nodeTag3.doEndTag(); + + tag.doEndTag(); + + //System.out.println(writer.toString()); + verify(TreeTest.class.getResource("tree-1.txt")); + } + + + + public void testDynamicTree() throws Exception { + + TreeTag tag = new TreeTag(); + tag.setPageContext(pageContext); + tag.setTheme("ajax"); + tag.setId("myTree"); + tag.setRootNode("%{myTreeRoot}"); + tag.setNodeIdProperty("id"); + tag.setNodeTitleProperty("name"); + tag.setChildCollectionProperty("children"); + tag.doStartTag(); + tag.doEndTag(); + + //System.out.println(writer.toString()); + verify(TreeTest.class.getResource("tree-2.txt")); + } + + + public Action getAction() { + return new InternalActionSupport(); + } + + public static class InternalActionSupport extends ActionSupport { + public Category getMyTreeRoot() { + return Category.getById(1); + } + } +} diff --git a/core/src/test/resources/org/apache/struts/action2/views/jsp/ui/tree-1.txt b/core/src/test/resources/org/apache/struts/action2/views/jsp/ui/tree-1.txt new file mode 100644 index 000000000..bcd853605 --- /dev/null +++ b/core/src/test/resources/org/apache/struts/action2/views/jsp/ui/tree-1.txt @@ -0,0 +1,42 @@ + +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file diff --git a/core/src/test/resources/org/apache/struts/action2/views/jsp/ui/tree-2.txt b/core/src/test/resources/org/apache/struts/action2/views/jsp/ui/tree-2.txt new file mode 100644 index 000000000..76c4b5d4c --- /dev/null +++ b/core/src/test/resources/org/apache/struts/action2/views/jsp/ui/tree-2.txt @@ -0,0 +1,70 @@ + +
+ +
+ +
+ +
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+
+ +
+ +
+
+ +
+
+ +
+
+ +
+
+
+
+ +
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+
+
+
\ No newline at end of file