1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.extremecomponents.tree.tag;
17
18 import javax.servlet.jsp.JspException;
19
20 import org.apache.commons.lang.StringUtils;
21 import org.apache.commons.logging.Log;
22 import org.apache.commons.logging.LogFactory;
23 import org.apache.taglibs.standard.lang.support.ExpressionEvaluatorManager;
24 import org.extremecomponents.table.ColumnAttributes;
25 import org.extremecomponents.table.bean.Column;
26 import org.extremecomponents.table.tag.ColumnTag;
27 import org.extremecomponents.table.tag.TableTag;
28 import org.extremecomponents.tree.bean.TreeNode;
29 import org.extremecomponents.tree.model.TreeModel;
30 import org.extremecomponents.util.ExceptionUtils;
31
32
33
34 /***
35 * The container which holds all the column specific information. A copy
36 * of each column will be fed to the Model.
37 *
38 * @author Jeff Johnston
39 */
40 public class TreeColumnTag extends ColumnTag implements ColumnAttributes
41 {
42 private static final long serialVersionUID = -2134703529160375990L;
43 private static Log logger = LogFactory.getLog(TreeColumnTag.class);
44
45 public static final String NO_PROPERTY_SPECIFIED = "NO_PROPERTY_SPECIFIED";
46 public static final String CELL = "tree";
47
48 private Object extendedValue;
49
50 /***
51 * Get the value for the column. First look to see if it displayed in the body
52 * of the column. If it is not in the body, then use the value attribute. If the
53 * value attribute is not specified then use the property attribute to find the value in
54 * the bean.
55 */
56 public void setColumnValue() throws JspException
57 {
58 logger.debug("TreeColumnTag.setColumnValue()");
59
60 TableTag tableTag;
61 try
62 {
63 tableTag = (TableTag) findAncestorWithClass(this, TableTag.class);
64
65 if (tableTag.getModelRowsSize() == 0)
66 {
67 return;
68 }
69
70 if (this.bodyContent != null)
71 {
72 setExtendedValue(getBodyContent().getString());
73 }
74
75 if (getExtendedValue() != null)
76 {
77 setExtendedValue((Object) ExpressionEvaluatorManager.evaluate("value", getExtendedValue().toString(), Object.class, this, pageContext));
78 }
79
80 TreeModel model = (TreeModel) tableTag.getModel();
81 model.setExtendedValue((String) getExtendedValue());
82 TreeNode node = (TreeNode) pageContext.getAttribute(tableTag.getCollection());
83 setValue(node);
84 }
85 catch (Exception e)
86 {
87 logger.error("TreeColumnTag.setColumnValue() Problem", e);
88 throw new JspException("TreeColumnTag.setColumnValue() Problem " + ExceptionUtils.formatStackTrace(e));
89 }
90 }
91
92 /***
93 * Must make a copy of the column because this tag may be reused. Send the copy up to the Model.
94 */
95 public int doEndTag() throws JspException
96 {
97 logger.debug("TreeColumnTag.doEndTag()");
98
99 try
100 {
101 TreeTag treeTag = (TreeTag) findAncestorWithClass(this, TableTag.class);
102
103 if (StringUtils.isBlank(getProperty())) setProperty(NO_PROPERTY_SPECIFIED);
104
105 if (treeTag.hasMetaData())
106 {
107 setColumnValue();
108 treeTag.addColumnValue(getProperty(), getValue());
109 }
110 else
111 {
112 Column column = new Column(treeTag.getModel());
113
114 if (NO_PROPERTY_SPECIFIED.equals(getProperty()))
115 {
116 if (StringUtils.isBlank(getTitle())) column.setTitle(" ");
117 else column.setTitle(getTitle());
118 column.setFilter("false");
119 column.setSort("false");
120 column.setProperty(NO_PROPERTY_SPECIFIED);
121 }
122 else
123 {
124 column.setProperty(getProperty());
125 column.setTitle(getTitle());
126 column.setFilter(getFilter());
127 column.setSort(getSort());
128 }
129
130 column.setValue(getValue());
131 column.setStyleClass(getStyleClass());
132 column.setHeaderClass(getHeaderClass());
133 column.setCell(CELL);
134 column.setFormat(getFormat());
135 column.setParse(getParse());
136 column.setWidth(getWidth());
137 column.setGroup(getGroup());
138 column.setStyle(getStyle());
139 column.setExport(getExport());
140 treeTag.addColumnMetaData(column);
141 }
142 }
143 catch (Exception e)
144 {
145 throw new JspException("TreeColumnTag.doEndTag() Problem: " + ExceptionUtils.formatStackTrace(e));
146 }
147
148 cleanup();
149
150 return EVAL_PAGE;
151 }
152
153 /***
154 * @return
155 */
156 public Object getExtendedValue()
157 {
158 return extendedValue;
159 }
160
161 /***
162 * @param string
163 */
164 public void setExtendedValue(Object object)
165 {
166 extendedValue = object;
167 }
168
169 }