KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > magnolia > cms > gui > control > TreeColumn


1 /**
2  *
3  * Magnolia and its source-code is licensed under the LGPL.
4  * You may copy, adapt, and redistribute this file for commercial or non-commercial use.
5  * When copying, adapting, or redistributing this document in keeping with the guidelines above,
6  * you are required to provide proper attribution to obinary.
7  * If you reproduce or distribute the document without making any substantive modifications to its content,
8  * please use the following attribution line:
9  *
10  * Copyright 1993-2005 obinary Ltd. (http://www.obinary.com) All rights reserved.
11  *
12  */

13 package info.magnolia.cms.gui.control;
14
15 import info.magnolia.cms.gui.misc.CssConstants;
16
17 import java.util.Hashtable JavaDoc;
18 import java.util.Map JavaDoc;
19
20 import javax.servlet.http.HttpServletRequest JavaDoc;
21
22 import org.apache.commons.lang.StringUtils;
23 import org.apache.log4j.Logger;
24
25
26 /**
27  * @author Vinzenz Wyser
28  * @version 2.0
29  */

30 public class TreeColumn extends ControlSuper {
31
32     public static final String JavaDoc EDIT_CSSCLASS_EDIT = CssConstants.CSSCLASS_EDIT;
33
34     public static final String JavaDoc EDIT_CSSCLASS_SELECT = CssConstants.CSSCLASS_SELECT;
35
36     public static final String JavaDoc EDIT_NAMEADDITION = "_EditNodeData"; //$NON-NLS-1$
37

38     public static final String JavaDoc EDIT_JSSAVE = ".saveNodeData(this.value);"; //$NON-NLS-1$
39

40     public static final String JavaDoc EMPTY = "-"; //$NON-NLS-1$
41

42     /**
43      * Logger.
44      */

45     private static Logger log = Logger.getLogger(TreeColumn.class);
46
47     boolean isMeta;
48
49     boolean isLabel;
50
51     boolean isIcons;
52
53     boolean iconsActivation;
54
55     boolean iconsPermission;
56
57     boolean isNodeDataValue;
58
59     boolean isNodeDataType;
60
61     String JavaDoc dateFormat;
62
63     String JavaDoc title = StringUtils.EMPTY;
64
65     boolean permissionWrite;
66
67     String JavaDoc htmlEdit = StringUtils.EMPTY;
68
69     TreeColumnHtmlRenderer htmlRenderer;
70
71     private String JavaDoc javascriptTree = StringUtils.EMPTY;
72
73     private int width = 1;
74
75     // if EMPTY changes, it has to be updated also in tree.js; note: if you use html tags, use upper-case letters (and
76
// test it well ;)
77
private Map JavaDoc keyValue = new Hashtable JavaDoc();
78
79     /**
80      * Constructor.
81      * @param javascriptTree name of the js variable
82      * @param request http request, needed for context path
83      */

84     public TreeColumn(String JavaDoc javascriptTree, HttpServletRequest JavaDoc request) {
85         this.setJavascriptTree(javascriptTree);
86         this.setCssClass("mgnlTreeText"); //$NON-NLS-1$
87
this.setRequest(request);
88         // default delegate
89
this.setHtmlRenderer(new TreeColumnHtmlRendererImpl());
90     }
91
92     public void setIsMeta(boolean b) {
93         this.isMeta = b;
94     }
95
96     public boolean getIsMeta() {
97         return this.isMeta;
98     }
99
100     public void setIsIcons(boolean b) {
101         this.isIcons = b;
102     }
103
104     public boolean getIsIcons() {
105         return this.isIcons;
106     }
107
108     public void setIconsActivation(boolean b) {
109         this.iconsActivation = b;
110     }
111
112     public boolean getIconsActivation() {
113         return this.iconsActivation;
114     }
115
116     public void setIconsPermission(boolean b) {
117         this.iconsPermission = b;
118     }
119
120     public boolean getIconsPermission() {
121         return this.iconsPermission;
122     }
123
124     public void setIsLabel(boolean b) {
125         this.isLabel = b;
126     }
127
128     public boolean getIsLabel() {
129         return this.isLabel;
130     }
131
132     public void setIsNodeDataValue(boolean b) {
133         this.isNodeDataValue = b;
134     }
135
136     public boolean getIsNodeDataValue() {
137         return this.isNodeDataValue;
138     }
139
140     public void setIsNodeDataType(boolean b) {
141         this.isNodeDataType = b;
142     }
143
144     public boolean getIsNodeDataType() {
145         return this.isNodeDataType;
146     }
147
148     public void setDateFormat(String JavaDoc s) {
149         this.dateFormat = s;
150     }
151
152     public String JavaDoc getDateFormat() {
153         return this.dateFormat;
154     }
155
156     public void setTitle(String JavaDoc s) {
157         this.title = s;
158     }
159
160     public String JavaDoc getTitle() {
161         return this.title;
162     }
163
164     /**
165      * <p>
166      * set the name relative width of the column; default is 1
167      * </p>
168      */

169     public void setWidth(int i) {
170         this.width = i;
171     }
172
173     public int getWidth() {
174         return this.width;
175     }
176
177     public void setPermissionWrite(boolean b) {
178         this.permissionWrite = b;
179     }
180
181     public boolean getPermissionWrite() {
182         return this.permissionWrite;
183     }
184
185     /**
186      * <p>
187      * set the name of the javascript tree object
188      * </p>
189      * @param variableName
190      */

191     public void setJavascriptTree(String JavaDoc variableName) {
192         this.javascriptTree = variableName;
193     }
194
195     public String JavaDoc getJavascriptTree() {
196         return this.javascriptTree;
197     }
198
199     public void setKeyValue(Map JavaDoc h) {
200         this.keyValue = h;
201     }
202
203     public Map JavaDoc getKeyValue() {
204         return this.keyValue;
205     }
206
207     public String JavaDoc getKeyValue(String JavaDoc key) {
208         return (String JavaDoc) this.getKeyValue().get(key);
209     }
210
211     public void addKeyValue(String JavaDoc key, String JavaDoc value) {
212         this.getKeyValue().put(key, value);
213     }
214
215     public void setHtmlEdit(String JavaDoc s) {
216         this.htmlEdit = s;
217     }
218
219     public String JavaDoc getHtmlEdit() {
220         return this.htmlEdit;
221     }
222
223     public void setHtmlEdit() {
224         Edit edit = new Edit();
225         edit.setName(this.getJavascriptTree() + EDIT_NAMEADDITION);
226         edit.setSaveInfo(false);
227         edit.setCssClass(EDIT_CSSCLASS_EDIT);
228         edit.setEvent("onkeydown", this.getJavascriptTree() + ".editNodeDataKeydown(event,this);"); //$NON-NLS-1$ //$NON-NLS-2$
229
edit.setEvent("onblur", this.getJavascriptTree() + EDIT_JSSAVE); //$NON-NLS-1$
230
// edit.setCssStyles("width","100%");
231
this.setHtmlEdit(edit.getHtml());
232     }
233
234     public String JavaDoc getHtml() {
235         String JavaDoc html = null;
236         try {
237             html = htmlRenderer.renderHtml(this, this.getWebsiteNode());
238         }
239         catch (Exception JavaDoc e) {
240             log.error(e.getMessage(), e);
241         }
242         // "" not clickable!
243
if (StringUtils.isEmpty(html)) {
244             html = TreeColumn.EMPTY;
245         }
246         return html;
247     }
248
249     /**
250      * @return Returns the htmlRenderer.
251      */

252     public TreeColumnHtmlRenderer getHtmlRenderer() {
253         return htmlRenderer;
254     }
255
256     /**
257      * @param htmlRenderer Set the delecate Object which will render the html column for each row
258      */

259     public void setHtmlRenderer(TreeColumnHtmlRenderer htmlRenderer) {
260         this.htmlRenderer = htmlRenderer;
261     }
262 }
263
Popular Tags