KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > fr > improve > struts > taglib > layout > util > FixedHeaderCollection


1 package fr.improve.struts.taglib.layout.util;
2
3 import javax.servlet.jsp.JspException JavaDoc;
4 import javax.servlet.jsp.PageContext JavaDoc;
5 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
6
7 import fr.improve.struts.taglib.layout.collection.CollectionItemTag;
8 import fr.improve.struts.taglib.layout.collection.CollectionTag;
9 import fr.improve.struts.taglib.layout.el.Expression;
10
11 /**
12  * New implementation of the CollectionInterface, with fixed header.
13  *
14  * @author: Jean-Noël Ribette, F. BELLINGARD, Damien Viel
15  */

16 public class FixedHeaderCollection extends BasicPanel implements CollectionInterface, IMathCollectionRenderer, IFooterRenderer, IMultiLevelHeaderRenderer {
17     protected CollectionTag collectionTag;
18     protected PageContext JavaDoc pageContext;
19     
20     public void init(PageContext JavaDoc pg, String JavaDoc in_styleClass, TagSupport JavaDoc in_tag) throws JspException JavaDoc {
21         super.init(pg, in_styleClass, in_tag);
22         collectionTag = (CollectionTag) in_tag;
23         pageContext = pg;
24     }
25     
26     /**
27      * Display a special message if the collection is empty.
28      */

29     public void doPrintEmptyCollection(StringBuffer JavaDoc out_buffer, String JavaDoc in_message) {
30         out_buffer.append("<tr><td colspan=\"");
31         out_buffer.append(collectionTag.getHeaders().size());
32         out_buffer.append("\" class=\"");
33         out_buffer.append(styleClass);
34         out_buffer.append("\">&nbsp;");
35         out_buffer.append(in_message);
36         out_buffer.append("</td></tr>");
37     }
38     /**
39      * Overrides the display ot the title.
40      * PENDING: use a nice layout.
41      */

42     public void doPrintTitle(StringBuffer JavaDoc buffer, String JavaDoc title) {
43         if (title!=null) {
44             if (styleClass!=null) {
45                 buffer.append("<p class=\"");
46                 buffer.append(styleClass);
47                 buffer.append("\">");
48             }
49             buffer.append(title);
50             if (styleClass!=null) {
51                 buffer.append("</p>");
52             }
53             //buffer.append("</td></tr><tr align=\"center\"><td colspan=\"2\">");
54
}
55     }
56     /**
57      * Override doStartPanel
58      */

59     public void doStartPanel(StringBuffer JavaDoc buffer, String JavaDoc align, String JavaDoc width) {
60         if (collectionTag.getWidth()!=null || collectionTag.getHeight()!=null) {
61             buffer.append("<div style=\"");
62             if (collectionTag.getWidth()!=null && collectionTag.getHeight()!=null) {
63                 buffer.append("width:");
64                 buffer.append(collectionTag.getWidth());
65                 buffer.append("px;");
66                 buffer.append("height:");
67                 buffer.append(collectionTag.getHeight());
68                 buffer.append("px;");
69                 buffer.append("overflow:auto;");
70             } else {
71                 if (collectionTag.getWidth()!=null) {
72                     buffer.append("width:");
73                     buffer.append(collectionTag.getWidth());
74                     buffer.append("px;");
75                     buffer.append("overflow-x:auto;");
76                 }
77                 if (collectionTag.getHeight()!=null) {
78                     buffer.append("height:");
79                     buffer.append(collectionTag.getHeight());
80                     buffer.append("px;");
81                     buffer.append("overflow-y:auto;overflow:-moz-scrollbars-vertical;");
82                 }
83             }
84             buffer.append("\">");
85         }
86         buffer.append("<table");
87         if (align!=null) {
88             buffer.append(" align=\"");
89             buffer.append(align);
90             buffer.append("\"");
91         }
92         if (width!=null) {
93             buffer.append(" width=\"");
94             buffer.append(width);
95             buffer.append("\"");
96         }
97         if (styleClass!=null) {
98             buffer.append(" class=\"");
99             buffer.append(styleClass);
100             buffer.append("\"");
101         }
102         if (collectionTag.getStyleId()!=null) {
103             buffer.append(" id=\"");
104             buffer.append(collectionTag.getStyleId());
105             buffer.append("\"");
106         }
107         buffer.append(">\n");
108     }
109     /**
110      * Prepare to display the headers.
111      */

112     public void doStartHeaders(StringBuffer JavaDoc out_buffer) {
113         out_buffer.append("<tr id=\"head\">");
114     }
115     /**
116      * Display a header.
117      */

118     public void doPrintHeader(StringBuffer JavaDoc out_buffer, String JavaDoc in_header, String JavaDoc in_width, String JavaDoc in_sortUrl) {
119         out_buffer.append("<th");
120         if (styleClass!=null) {
121             out_buffer.append(" class=\"");
122             out_buffer.append(styleClass);
123             out_buffer.append("\"");
124         }
125         if (in_width!=null) {
126             out_buffer.append(" width=\"");
127             out_buffer.append(in_width);
128             out_buffer.append("\"");
129         }
130         out_buffer.append(">");
131                     
132         out_buffer.append(doPrintSortUrl(in_header, in_sortUrl));
133             
134         
135         out_buffer.append("</th>");
136     }
137     
138     /**
139      * Display an hyperlink to sort the column.
140      */

141     protected String JavaDoc doPrintSortUrl(String JavaDoc in_header, String JavaDoc in_sortUrl) {
142         if (in_sortUrl == null) {
143             return in_header;
144         }
145         else if (collectionTag.getSortPictogram().equalsIgnoreCase("none")) {
146             // pas d'image pour faire le tri, mais un lien sur le titre
147
StringBuffer JavaDoc lc_tempBuffer = new StringBuffer JavaDoc("<table border=\"0\" width=\"100%\"><tr><td>");
148             lc_tempBuffer.append("&nbsp;");
149             lc_tempBuffer.append("</td><td>");
150             lc_tempBuffer.append("<a HREF=\"");
151             lc_tempBuffer.append(in_sortUrl);
152             lc_tempBuffer.append("\">");
153             lc_tempBuffer.append(in_header);
154             lc_tempBuffer.append("</a>");
155             lc_tempBuffer.append("</td></tr></table>");
156             return lc_tempBuffer.toString();
157         }
158         else {
159             // utilisation d'une image pour faire le tri
160
StringBuffer JavaDoc lc_tempBuffer = new StringBuffer JavaDoc("<table border=\"0\" width=\"100%\"><tr><td>");
161             lc_tempBuffer.append("<a HREF=\"");
162             lc_tempBuffer.append(in_sortUrl);
163             lc_tempBuffer.append("\"><img SRC=\"");
164             lc_tempBuffer.append(LayoutUtils.getSkin(pageContext.getSession()).getImageDirectory(pageContext.getRequest()));
165             lc_tempBuffer.append("/");
166             lc_tempBuffer.append(LayoutUtils.getSkin(pageContext.getSession()).getProperty(collectionTag.getSortPictogram()));
167             lc_tempBuffer.append("\" border=\"0\" alt=\"");
168             lc_tempBuffer.append(LayoutUtils.getSkin(pageContext.getSession()).getProperty(collectionTag.getSortLabel()));
169             lc_tempBuffer.append("\"></a>");
170     
171             lc_tempBuffer.append("</td><td>");
172             lc_tempBuffer.append(in_header);
173             lc_tempBuffer.append("</td></tr></table>");
174         
175             return lc_tempBuffer.toString();
176         }
177     }
178
179      
180     /**
181      * Finish to render the headers.
182      */

183     public void doEndHeaders(StringBuffer JavaDoc out_buffer) {
184         out_buffer.append("</tr>");
185     }
186     /**
187      * Prepare to render a line.
188      */

189     public void doStartItems(StringBuffer JavaDoc out_buffer) {
190         out_buffer.append("<tr");
191         boolean lc_onclick = false;
192         if (collectionTag.getOnRowClick()!=null) {
193             out_buffer.append(" onclick=\"");
194             out_buffer.append(Expression.evaluate(collectionTag.getOnRowClick(), pageContext));
195             out_buffer.append("\"");
196             lc_onclick = true;
197         }
198         if (collectionTag.getOnRowDblClick()!=null) {
199             out_buffer.append(" ondblclick=\"");
200             out_buffer.append(Expression.evaluate(collectionTag.getOnRowDblClick(), pageContext));
201             out_buffer.append("\"");
202             lc_onclick = true;
203         }
204         if (collectionTag.getOnRowMouseOver()!=null) {
205             out_buffer.append(" onmouseover=\"");
206             out_buffer.append(Expression.evaluate(collectionTag.getOnRowMouseOver(), pageContext));
207             out_buffer.append("\"");
208             lc_onclick = true;
209         }
210         if (collectionTag.getOnRowMouseOut()!=null) {
211             out_buffer.append(" onmouseout=\"");
212             out_buffer.append(Expression.evaluate(collectionTag.getOnRowMouseOut(), pageContext));
213             out_buffer.append("\"");
214         }
215         if (lc_onclick) {
216             out_buffer.append(" style=\"cursor:pointer;cursor:hand;\"");
217         }
218         out_buffer.append(">");
219     }
220     /**
221      * Render an element in the line.
222      */

223     public void doPrintItem(StringBuffer JavaDoc out_buffer, String JavaDoc in_item, String JavaDoc[] in_styleClass, String JavaDoc in_id) {
224         out_buffer.append("<td");
225         if (in_styleClass[0] != null) {
226             out_buffer.append(" class=\"");
227             out_buffer.append(in_styleClass[0]);
228             out_buffer.append("\"");
229         }
230         if (in_styleClass.length>1) {
231             out_buffer.append(" style=\"");
232             for (int i = 0; i < in_styleClass.length-1; i++) {
233                 out_buffer.append(in_styleClass[i+1]);
234             }
235             out_buffer.append("\"");
236         }
237         
238         Integer JavaDoc lc_int = (Integer JavaDoc) pageContext.getAttribute(CollectionItemTag.SPAN_KEY);
239         if (lc_int!=null && lc_int.intValue()!=1) {
240             out_buffer.append(" rowspan=\"");
241             out_buffer.append(lc_int.intValue());
242             out_buffer.append("\"");
243         }
244         
245         out_buffer.append(">");
246         
247         if (in_id!=null) {
248             out_buffer.append("<div id=\"");
249             out_buffer.append(in_id);
250             out_buffer.append("\">");
251         }
252         
253         out_buffer.append(in_item);
254         
255         if (in_id!=null) {
256             out_buffer.append("</div>");
257         }
258
259         out_buffer.append("</td>");
260     }
261     /**
262      * Finish to render a line.
263      */

264     public void doEndItems(StringBuffer JavaDoc out_buffer) {
265         out_buffer.append("</tr>");
266     }
267     public void doEndPanel(StringBuffer JavaDoc buffer) {
268         buffer.append("</table>\n");
269         if (collectionTag.getWidth()!=null || collectionTag.getHeight()!=null) {
270             buffer.append("</div>");
271             
272             // Generate the div that will hold the collection headers in front of the collection.
273
String JavaDoc lc_id = WidgetUtils.generateId(pageContext.getRequest(), "collectionLayerId");
274             buffer.append("<div style=\"position:absolute;top:0;left:0\" id=\"colLayer");
275             buffer.append(lc_id);
276             buffer.append("\"></div>");
277             
278             // Load collection scrollbar javascript.
279
if (pageContext.getRequest().getAttribute("zzz")==null) {
280                 buffer.append("<script SRC=\"");
281                 buffer.append(LayoutUtils.getSkin(pageContext.getSession()).getConfigDirectory(pageContext.getRequest()));
282                 buffer.append("/scrollbar.js\"></script>");
283                 pageContext.getRequest().setAttribute("zzz", "zzz");
284             }
285             
286             // Initialize the div content.
287
buffer.append("<script>addLoadEvent(function() {initScrollbar(\"");
288             buffer.append(collectionTag.getStyleId());
289             buffer.append("\",\"colLayer");
290             buffer.append(lc_id);
291             buffer.append("\")});</script>");
292         }
293     }
294     public void endFooter(StringBuffer JavaDoc in_buffer) {
295         in_buffer.append("</tr>\n");
296
297     }
298     public void printFooterElement(StringBuffer JavaDoc in_buffer, String JavaDoc in_element, int in_span) {
299         in_buffer.append("<td ");
300         if (in_span>1) {
301             in_buffer.append(" colspan=\"");
302             in_buffer.append(in_span);
303             in_buffer.append("\"");
304         }
305         in_buffer.append(">");
306         in_buffer.append(in_element);
307         in_buffer.append("</td>");
308
309     }
310     public void startFooter(StringBuffer JavaDoc in_buffer) {
311         in_buffer.append("<tr>");
312     }
313     
314     // ------------------- Math data renderer -----------------------
315

316     /**
317      * Print end of math data
318      */

319     public void endMathData(StringBuffer JavaDoc in_buffer) {
320         in_buffer.append("</tr>\n");
321     }
322     
323     public void renderMathData(StringBuffer JavaDoc in_buffer, String JavaDoc in_element, int in_span, String JavaDoc in_resultId, String JavaDoc in_styleClass) {
324         in_buffer.append("<td");
325         if (in_styleClass!=null){
326             in_buffer.append(" class=\"");
327             in_buffer.append(in_styleClass);
328             in_buffer.append("\"");
329         }
330         if (in_span>1){
331             in_buffer.append(" colspan=\"");
332             in_buffer.append(in_span);
333             in_buffer.append("\"");
334         }
335         if (in_resultId!=null && in_resultId.length()!=0){
336             in_buffer.append(" id=\"" + in_resultId + "\"");
337         }
338         in_buffer.append(">");
339         in_buffer.append(in_element);
340         in_buffer.append("</td>\n");
341     }
342     
343     public void startMathData(StringBuffer JavaDoc in_buffer) {
344         in_buffer.append("<tr>\n");
345     }
346     
347     // ---------------------- Multi level header renderer ---------------------
348

349     public void renderMultiLevelHeader(StringBuffer JavaDoc in_buffer, String JavaDoc in_title, String JavaDoc in_sortUrl, String JavaDoc in_styleClass, int in_colspan, int in_rowspan, String JavaDoc in_width) {
350         in_buffer.append("<th");
351         if (in_colspan!=1) {
352             in_buffer.append(" colspan=\"");
353             in_buffer.append(in_colspan);
354             in_buffer.append("\"");
355         }
356         if (in_styleClass!=null) {
357             in_buffer.append(" class=\"");
358             in_buffer.append(in_styleClass);
359             in_buffer.append("\"");
360         }
361         if (in_rowspan!=1) {
362             in_buffer.append(" rowspan=\"");
363             in_buffer.append(in_rowspan);
364             in_buffer.append("\"");
365         }
366         if (in_width!=null) {
367             in_buffer.append(" width=\"");
368             in_buffer.append(in_width);
369             in_buffer.append("\"");
370         }
371         in_buffer.append(">");
372         in_buffer.append(doPrintSortUrl(in_title, in_sortUrl));
373         in_buffer.append("</th>");
374     }
375
376     public void endMultiLevelHeaderRow(StringBuffer JavaDoc in_buffer) {
377         in_buffer.append("</tr>\n");
378     }
379     public void startMultiLevelHeaderRow(StringBuffer JavaDoc in_buffer) {
380         in_buffer.append("<tr valign=\"top\" id=\"header\">");
381     }
382 }
Popular Tags