1 package fr.improve.struts.taglib.layout.renderer; 2 3 import javax.servlet.jsp.JspException ; 4 import javax.servlet.jsp.PageContext ; 5 import javax.servlet.jsp.tagext.TagSupport ; 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 import fr.improve.struts.taglib.layout.util.CollectionInterface; 11 import fr.improve.struts.taglib.layout.util.IFooterRenderer; 12 import fr.improve.struts.taglib.layout.util.IMathCollectionRenderer; 13 import fr.improve.struts.taglib.layout.util.IMultiLevelHeaderRenderer; 14 import fr.improve.struts.taglib.layout.util.LayoutUtils; 15 16 21 public class SingleTableCollection implements CollectionInterface, IMathCollectionRenderer, IFooterRenderer, IMultiLevelHeaderRenderer { 22 protected CollectionTag collectionTag; 23 protected PageContext pageContext; 24 protected String styleClass; 25 26 29 public void init(PageContext pg, String in_styleClass, TagSupport in_tag) throws JspException { 30 collectionTag = (CollectionTag) in_tag; 31 pageContext = pg; 32 styleClass = collectionTag.getStyleClass(); 33 } 34 35 38 public void doPrintEmptyCollection(StringBuffer out_buffer, String in_message) { 39 out_buffer.append("<tr><td colspan=\""); 40 out_buffer.append(collectionTag.getHeaders().size()); 41 out_buffer.append("\" class=\""); 42 out_buffer.append(buildEmptyStyleClass(styleClass)); 43 out_buffer.append("\"> "); 44 out_buffer.append(in_message); 45 out_buffer.append("</td></tr>"); 46 } 47 50 public void doPrintTitle(StringBuffer buffer, String title) { 51 if (title!=null) { 52 if (styleClass!=null) { 53 buffer.append("<p class=\""); 54 buffer.append(styleClass); 55 buffer.append("\">"); 56 } 57 buffer.append(title); 58 if (styleClass!=null) { 59 buffer.append("</p>"); 60 } 61 } 62 } 63 66 public void doStartPanel(StringBuffer buffer, String align, String width) { 67 if (collectionTag.getWidth()!=null || collectionTag.getHeight()!=null) { 69 buffer.append("<div style=\""); 70 if (collectionTag.getWidth()!=null) { 71 buffer.append("width:"); 72 buffer.append(collectionTag.getWidth()); 73 buffer.append(";"); 74 buffer.append("overflow-x:auto;"); 75 } 76 if (collectionTag.getHeight()!=null) { 77 buffer.append("height:"); 78 buffer.append(collectionTag.getHeight()); 79 buffer.append(";"); 80 buffer.append("overflow-y:auto;"); 81 } 82 buffer.append("\">"); 83 } 84 85 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 112 public void doStartHeaders(StringBuffer out_buffer) { 113 out_buffer.append("<tr>"); 114 } 115 118 public void doPrintHeader(StringBuffer out_buffer, String in_header, String in_width, String in_sortUrl) { 119 out_buffer.append("<th"); 120 if (styleClass!=null) { 121 out_buffer.append(" class=\""); 122 out_buffer.append(buildHeaderStyleClass(styleClass, collectionTag.getColumn())); 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 141 protected String doPrintSortUrl(String in_header, String in_sortUrl) { 142 if (in_sortUrl == null) { 143 return in_header; 144 } 145 else if (collectionTag.getSortPictogram().equalsIgnoreCase("none")) { 146 StringBuffer lc_tempBuffer = new StringBuffer ("<table border=\"0\" width=\"100%\"><tr><td>"); 148 lc_tempBuffer.append(" "); 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 StringBuffer lc_tempBuffer = new StringBuffer ("<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 183 public void doEndHeaders(StringBuffer out_buffer) { 184 out_buffer.append("</tr>"); 185 } 186 189 public void doStartItems(StringBuffer 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 223 public void doPrintItem(StringBuffer out_buffer, String in_item, String [] in_styleClass, String 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 lc_int = (Integer ) 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 264 public void doEndItems(StringBuffer out_buffer) { 265 out_buffer.append("</tr>"); 266 } 267 public void doEndPanel(StringBuffer buffer) { 268 buffer.append("</table>\n"); 269 if (collectionTag.getWidth()!=null || collectionTag.getHeight()!=null) { 270 buffer.append("</div>"); 271 } 272 } 273 274 276 279 protected String buildHeaderStyleClass(String in_styleClass, int in_columnNumber) { 280 return in_styleClass; 281 } 282 283 286 protected String buildFooterStyleClass(int in_columnNumber) { 287 return null; 288 } 289 290 293 protected String buildEmptyStyleClass(String in_styleClass) { 294 return in_styleClass; 295 } 296 297 299 public void endFooter(StringBuffer in_buffer) { 300 in_buffer.append("</tr>\n"); 301 302 } 303 public void printFooterElement(StringBuffer in_buffer, String in_element, int in_span) { 304 in_buffer.append("<td "); 305 if (in_span>1) { 306 in_buffer.append(" colspan=\""); 307 in_buffer.append(in_span); 308 in_buffer.append("\""); 309 } 310 String lc_styleClass = buildFooterStyleClass(collectionTag.getColumn()); 311 if (lc_styleClass!=null) { 312 in_buffer.append(" class=\""); 313 in_buffer.append(lc_styleClass); 314 in_buffer.append("\""); 315 } 316 in_buffer.append(">"); 317 in_buffer.append(in_element); 318 in_buffer.append("</td>"); 319 320 } 321 public void startFooter(StringBuffer in_buffer) { 322 in_buffer.append("<tr>"); 323 } 324 325 327 330 public void endMathData(StringBuffer in_buffer) { 331 in_buffer.append("</tr>\n"); 332 } 333 334 public void renderMathData(StringBuffer in_buffer, String in_element, int in_span, String in_resultId, String in_styleClass) { 335 in_buffer.append("<td"); 336 if (in_styleClass!=null){ 337 in_buffer.append(" class=\""); 338 in_buffer.append(in_styleClass); 339 in_buffer.append("\""); 340 } 341 if (in_span>1){ 342 in_buffer.append(" colspan=\""); 343 in_buffer.append(in_span); 344 in_buffer.append("\""); 345 } 346 if (in_resultId!=null && in_resultId.length()!=0){ 347 in_buffer.append(" id=\"" + in_resultId + "\""); 348 } 349 in_buffer.append(">"); 350 in_buffer.append(in_element == null ? "" : in_element); 351 in_buffer.append("</td>\n"); 352 } 353 354 public void startMathData(StringBuffer in_buffer) { 355 in_buffer.append("<tr>\n"); 356 } 357 358 360 public void renderMultiLevelHeader(StringBuffer in_buffer, String in_title, String in_sortUrl, String in_styleClass, int in_colspan, int in_rowspan, String in_width) { 361 in_buffer.append("<th"); 362 if (in_colspan!=1) { 363 in_buffer.append(" colspan=\""); 364 in_buffer.append(in_colspan); 365 in_buffer.append("\""); 366 } 367 if (in_styleClass!=null) { 368 in_buffer.append(" class=\""); 369 in_buffer.append(buildHeaderStyleClass(in_styleClass, collectionTag.getColumn())); 370 in_buffer.append("\""); 371 } 372 if (in_rowspan!=1) { 373 in_buffer.append(" rowspan=\""); 374 in_buffer.append(in_rowspan); 375 in_buffer.append("\""); 376 } 377 if (in_width!=null) { 378 in_buffer.append(" width=\""); 379 in_buffer.append(in_width); 380 in_buffer.append("\""); 381 } 382 in_buffer.append(">"); 383 in_buffer.append(doPrintSortUrl(in_title, in_sortUrl)); 384 in_buffer.append("</th>"); 385 } 386 387 public void endMultiLevelHeaderRow(StringBuffer in_buffer) { 388 in_buffer.append("</tr>\n"); 389 } 390 public void startMultiLevelHeaderRow(StringBuffer in_buffer) { 391 in_buffer.append("<tr valign=\"top\">"); 392 } 393 394 396 public void doAfterBody(StringBuffer buffer) throws JspException { 397 } 399 400 public void doBeforeBody(StringBuffer buffer, String align) throws JspException { 401 } 403 404 public void doPrintBlankLine(StringBuffer buffer, int cols) throws JspException { 405 } 407 } | Popular Tags |