1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package info.magnolia.cms.gui.control;
35
36 import info.magnolia.cms.gui.misc.CssConstants;
37
38 import java.util.Hashtable;
39 import java.util.Map;
40
41 import javax.servlet.http.HttpServletRequest;
42
43 import org.apache.commons.lang.StringUtils;
44 import org.slf4j.Logger;
45 import org.slf4j.LoggerFactory;
46
47
48
49
50
51
52 public class TreeColumn extends ControlImpl {
53
54 public static final String EDIT_CSSCLASS_EDIT = CssConstants.CSSCLASS_EDIT;
55
56 public static final String EDIT_CSSCLASS_SELECT = CssConstants.CSSCLASS_SELECT;
57
58 public static final String EDIT_NAMEADDITION = "_EditNodeData";
59
60 public static final String EDIT_JSSAVE = ".saveNodeData(this.value);";
61
62 public static final String EMPTY = "-";
63
64
65
66
67 private static Logger log = LoggerFactory.getLogger(TreeColumn.class);
68
69 boolean isMeta;
70
71 boolean isLabel;
72
73 boolean isIcons;
74
75 boolean iconsActivation;
76
77 boolean iconsPermission;
78
79 boolean isNodeDataValue;
80
81 boolean isNodeDataType;
82
83 String dateFormat;
84
85 String title = StringUtils.EMPTY;
86
87 boolean permissionWrite;
88
89 String htmlEdit = StringUtils.EMPTY;
90
91 TreeColumnHtmlRenderer htmlRenderer;
92
93 private String javascriptTree = StringUtils.EMPTY;
94
95 private int width = 1;
96
97
98
99 private Map keyValue = new Hashtable();
100
101 public TreeColumn() {
102 this.setCssClass("mgnlTreeText");
103
104 this.setHtmlRenderer(new TreeColumnHtmlRendererImpl());
105
106 }
107
108
109
110
111
112
113
114 public TreeColumn(String javascriptTree, HttpServletRequest request) {
115 this();
116 this.setJavascriptTree(javascriptTree);
117 this.setRequest(request);
118 }
119
120 public void setIsMeta(boolean b) {
121 this.isMeta = b;
122 }
123
124 public boolean getIsMeta() {
125 return this.isMeta;
126 }
127
128 public void setIsIcons(boolean b) {
129 this.isIcons = b;
130 }
131
132 public boolean getIsIcons() {
133 return this.isIcons;
134 }
135
136 public void setIconsActivation(boolean b) {
137 this.iconsActivation = b;
138 }
139
140 public boolean getIconsActivation() {
141 return this.iconsActivation;
142 }
143
144 public void setIconsPermission(boolean b) {
145 this.iconsPermission = b;
146 }
147
148 public boolean getIconsPermission() {
149 return this.iconsPermission;
150 }
151
152 public void setIsLabel(boolean b) {
153 this.isLabel = b;
154 }
155
156 public boolean getIsLabel() {
157 return this.isLabel;
158 }
159
160 public void setIsNodeDataValue(boolean b) {
161 this.isNodeDataValue = b;
162 }
163
164 public boolean getIsNodeDataValue() {
165 return this.isNodeDataValue;
166 }
167
168 public void setIsNodeDataType(boolean b) {
169 this.isNodeDataType = b;
170 }
171
172 public boolean getIsNodeDataType() {
173 return this.isNodeDataType;
174 }
175
176 public void setDateFormat(String s) {
177 this.dateFormat = s;
178 }
179
180 public String getDateFormat() {
181 return this.dateFormat;
182 }
183
184 public void setTitle(String s) {
185 this.title = s;
186 }
187
188 public String getTitle() {
189 return this.title;
190 }
191
192
193
194
195
196
197 public void setWidth(int i) {
198 this.width = i;
199 }
200
201 public int getWidth() {
202 return this.width;
203 }
204
205 public void setPermissionWrite(boolean b) {
206 this.permissionWrite = b;
207 }
208
209 public boolean getPermissionWrite() {
210 return this.permissionWrite;
211 }
212
213
214
215
216
217
218
219 public void setJavascriptTree(String variableName) {
220 this.javascriptTree = variableName;
221 }
222
223 public String getJavascriptTree() {
224 return this.javascriptTree;
225 }
226
227 public void setKeyValue(Map h) {
228 this.keyValue = h;
229 }
230
231 public Map getKeyValue() {
232 return this.keyValue;
233 }
234
235 public String getKeyValue(String key) {
236 return (String) this.getKeyValue().get(key);
237 }
238
239 public void addKeyValue(String key, String value) {
240 this.getKeyValue().put(key, value);
241 }
242
243 public void setHtmlEdit(String s) {
244 this.htmlEdit = s;
245 }
246
247 public String getHtmlEdit() {
248 return this.htmlEdit;
249 }
250
251 public void setHtmlEdit() {
252 Edit edit = new Edit();
253 edit.setName(this.getJavascriptTree() + EDIT_NAMEADDITION);
254 edit.setSaveInfo(false);
255 edit.setCssClass(EDIT_CSSCLASS_EDIT);
256 edit.setEvent("onkeydown", this.getJavascriptTree() + ".editNodeDataKeydown(event,this);");
257 edit.setEvent("onblur", this.getJavascriptTree() + EDIT_JSSAVE);
258
259 this.setHtmlEdit(edit.getHtml());
260 }
261
262 public String getHtml() {
263 String html = null;
264 try {
265 html = getHtmlRenderer().renderHtml(this, this.getWebsiteNode());
266 }
267 catch (Exception e) {
268 log.error(e.getMessage(), e);
269 }
270
271 if (StringUtils.isEmpty(html)) {
272 html = TreeColumn.EMPTY;
273 }
274 return html;
275 }
276
277
278
279
280 public TreeColumnHtmlRenderer getHtmlRenderer() {
281 return htmlRenderer;
282 }
283
284
285
286
287 public void setHtmlRenderer(TreeColumnHtmlRenderer htmlRenderer) {
288 this.htmlRenderer = htmlRenderer;
289 }
290
291 public static TreeColumn createColumn(Tree tree, String title) {
292 TreeColumn treeColumn = new TreeColumn();
293
294 treeColumn.setJavascriptTree(tree.getJavascriptTree());
295 treeColumn.setTitle(title);
296 return treeColumn;
297 }
298
299 public static TreeColumn createColumn(Tree tree, String title, TreeColumnHtmlRenderer htmlRenderer) {
300 TreeColumn treeColumn = createColumn(tree, title);
301 if (htmlRenderer != null) {
302 treeColumn.setHtmlRenderer(htmlRenderer);
303 }
304 return treeColumn;
305 }
306
307 public static TreeColumn createLabelColumn(Tree tree, String title, boolean editable) {
308 TreeColumn treeColumn = createColumn(tree, title);
309 treeColumn.setIsLabel(true);
310 if (editable) {
311 treeColumn.setHtmlEdit();
312 }
313 return treeColumn;
314 }
315
316 public static TreeColumn createNodeDataColumn(Tree tree, String title, String nodeDataName, boolean editable) {
317 TreeColumn treeColumn = createColumn(tree, title);
318 treeColumn.setName(nodeDataName);
319 if (editable) {
320 treeColumn.setHtmlEdit();
321 }
322 return treeColumn;
323 }
324
325 public static TreeColumn createNodeDataColumn(Tree tree, String title, String nodeDataName, String dateFormat) {
326 TreeColumn treeColumn = createColumn(tree, title);
327 treeColumn.setName(nodeDataName);
328 treeColumn.setDateFormat(dateFormat);
329 return treeColumn;
330 }
331
332 public static TreeColumn createNodeDataColumn(Tree tree, String title, String nodeDataName, TreeColumnHtmlRenderer renderer) {
333 TreeColumn treeColumn = createColumn(tree, title);
334 treeColumn.setName(nodeDataName);
335 treeColumn.setHtmlRenderer(renderer);
336 return treeColumn;
337 }
338
339 public static TreeColumn createMetaDataColumn(Tree tree, String title, String name, String dateFormat) {
340 TreeColumn treeColumn = createColumn(tree, title);
341 treeColumn.setIsMeta(true);
342 treeColumn.setName(name);
343 if (dateFormat != null) {
344 treeColumn.setDateFormat(dateFormat);
345 }
346 return treeColumn;
347 }
348
349 public static TreeColumn createIconColumn(Tree tree, String title, TreeColumnHtmlRenderer htmlRenderer) {
350 TreeColumn treeColumn = createColumn(tree, title, htmlRenderer);
351 treeColumn.setIsIcons(true);
352 return treeColumn;
353 }
354
355 public static TreeColumn createActivationColumn(Tree tree, String title) {
356 TreeColumn columnActivation = TreeColumn.createIconColumn(tree, "", null);
357 columnActivation.setIconsActivation(true);
358 columnActivation.setCssClass(StringUtils.EMPTY);
359 columnActivation.setTitle(title);
360 columnActivation.setWidth(1);
361 return columnActivation;
362 }
363
364 }