1 package fr.improve.struts.taglib.layout.util; 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 11 16 public class BasicCollection extends BasicPanel implements CollectionInterface, IMathCollectionRenderer, IFooterRenderer, IMultiLevelHeaderRenderer { 17 protected CollectionTag collectionTag; 18 protected PageContext pageContext; 19 20 public void init(PageContext pg, String in_styleClass, TagSupport in_tag) throws JspException { 21 super.init(pg, in_styleClass, in_tag); 22 collectionTag = (CollectionTag) in_tag; 23 pageContext = pg; 24 } 25 26 29 public void doPrintEmptyCollection(StringBuffer out_buffer, String 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("\"> "); 35 out_buffer.append(in_message); 36 out_buffer.append("</td></tr>"); 37 } 38 42 public void doPrintTitle(StringBuffer buffer, String 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 } 55 } 56 59 public void doStartPanel(StringBuffer buffer, String align, String width) { 60 if (collectionTag.getWidth()!=null || collectionTag.getHeight()!=null) { 61 buffer.append("<div style=\""); 62 if (collectionTag.getWidth()!=null) { 63 buffer.append("width:"); 64 buffer.append(collectionTag.getWidth()); 65 buffer.append(";"); 66 buffer.append("overflow-x:auto;"); 67 } 68 if (collectionTag.getHeight()!=null) { 69 buffer.append("height:"); 70 buffer.append(collectionTag.getHeight()); 71 buffer.append(";"); 72 buffer.append("overflow-y:auto;"); 73 } 74 buffer.append("\">"); 75 } 76 buffer.append("<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\""); 77 if (align!=null) { 78 buffer.append(" align=\""); 79 buffer.append(align); 80 buffer.append("\""); 81 } 82 if (width!=null) { 83 buffer.append(" width=\""); 84 buffer.append(width); 85 buffer.append("\""); 86 } 87 if (styleClass!=null) { 88 buffer.append(" class=\""); 89 buffer.append(styleClass); 90 buffer.append("\""); 91 } 92 buffer.append("><tr><td valign=\"top\">"); 93 buffer.append("<table cellspacing=\"1\" cellpadding=\"1\" border=\"0\" width=\"100%\""); 94 if (collectionTag.getStyleId()!=null) { 95 buffer.append(" id=\""); 96 buffer.append(collectionTag.getStyleId()); 97 buffer.append("\""); 98 } 99 buffer.append(">\n"); 100 } 101 104 public void doStartHeaders(StringBuffer out_buffer) { 105 out_buffer.append("<tr>"); 106 } 107 110 public void doPrintHeader(StringBuffer out_buffer, String in_header, String in_width, String in_sortUrl) { 111 out_buffer.append("<th"); 112 if (styleClass!=null) { 113 out_buffer.append(" class=\""); 114 out_buffer.append(styleClass); 115 out_buffer.append("\""); 116 } 117 if (in_width!=null) { 118 out_buffer.append(" width=\""); 119 out_buffer.append(in_width); 120 out_buffer.append("\""); 121 } 122 out_buffer.append(">"); 123 124 out_buffer.append(doPrintSortUrl(in_header, in_sortUrl)); 125 126 127 out_buffer.append("</th>"); 128 } 129 130 133 protected String doPrintSortUrl(String in_header, String in_sortUrl) { 134 if (in_sortUrl == null) { 135 return in_header; 136 } 137 else if (collectionTag.getSortPictogram().equalsIgnoreCase("none")) { 138 StringBuffer lc_tempBuffer = new StringBuffer ("<table border=\"0\" width=\"100%\"><tr><td>"); 140 lc_tempBuffer.append(" "); 141 lc_tempBuffer.append("</td><td>"); 142 lc_tempBuffer.append("<a HREF=\""); 143 lc_tempBuffer.append(in_sortUrl); 144 lc_tempBuffer.append("\">"); 145 lc_tempBuffer.append(in_header); 146 lc_tempBuffer.append("</a>"); 147 lc_tempBuffer.append("</td></tr></table>"); 148 return lc_tempBuffer.toString(); 149 } 150 else { 151 StringBuffer lc_tempBuffer = new StringBuffer ("<table border=\"0\" width=\"100%\"><tr><td>"); 153 lc_tempBuffer.append("<a HREF=\""); 154 lc_tempBuffer.append(in_sortUrl); 155 lc_tempBuffer.append("\"><img SRC=\""); 156 lc_tempBuffer.append(LayoutUtils.getSkin(pageContext.getSession()).getImageDirectory(pageContext.getRequest())); 157 lc_tempBuffer.append("/"); 158 lc_tempBuffer.append(LayoutUtils.getSkin(pageContext.getSession()).getProperty(collectionTag.getSortPictogram())); 159 lc_tempBuffer.append("\" border=\"0\" alt=\""); 160 lc_tempBuffer.append(LayoutUtils.getSkin(pageContext.getSession()).getProperty(collectionTag.getSortLabel())); 161 lc_tempBuffer.append("\"></a>"); 162 163 lc_tempBuffer.append("</td><td>"); 164 lc_tempBuffer.append(in_header); 165 lc_tempBuffer.append("</td></tr></table>"); 166 167 return lc_tempBuffer.toString(); 168 } 169 } 170 171 172 175 public void doEndHeaders(StringBuffer out_buffer) { 176 out_buffer.append("</tr>"); 177 } 178 181 public void doStartItems(StringBuffer out_buffer) { 182 out_buffer.append("<tr"); 183 boolean lc_onclick = false; 184 if (collectionTag.getOnRowClick()!=null) { 185 out_buffer.append(" onclick=\""); 186 out_buffer.append(Expression.evaluate(collectionTag.getOnRowClick(), pageContext)); 187 out_buffer.append("\""); 188 lc_onclick = true; 189 } 190 if (collectionTag.getOnRowDblClick()!=null) { 191 out_buffer.append(" ondblclick=\""); 192 out_buffer.append(Expression.evaluate(collectionTag.getOnRowDblClick(), pageContext)); 193 out_buffer.append("\""); 194 lc_onclick = true; 195 } 196 if (collectionTag.getOnRowMouseOver()!=null) { 197 out_buffer.append(" onmouseover=\""); 198 out_buffer.append(Expression.evaluate(collectionTag.getOnRowMouseOver(), pageContext)); 199 out_buffer.append("\""); 200 lc_onclick = true; 201 } 202 if (collectionTag.getOnRowMouseOut()!=null) { 203 out_buffer.append(" onmouseout=\""); 204 out_buffer.append(Expression.evaluate(collectionTag.getOnRowMouseOut(), pageContext)); 205 out_buffer.append("\""); 206 } 207 if (lc_onclick) { 208 out_buffer.append(" style=\"cursor:pointer;cursor:hand;\""); 209 } 210 out_buffer.append(">"); 211 } 212 215 public void doPrintItem(StringBuffer out_buffer, String in_item, String [] in_styleClass, String in_id) { 216 out_buffer.append("<td"); 217 if (in_styleClass[0] != null) { 218 out_buffer.append(" class=\""); 219 out_buffer.append(in_styleClass[0]); 220 out_buffer.append("\""); 221 } 222 if (in_styleClass.length>1) { 223 out_buffer.append(" style=\""); 224 for (int i = 0; i < in_styleClass.length-1; i++) { 225 out_buffer.append(in_styleClass[i+1]); 226 } 227 out_buffer.append("\""); 228 } 229 230 Integer lc_int = (Integer ) pageContext.getAttribute(CollectionItemTag.SPAN_KEY); 231 if (lc_int!=null && lc_int.intValue()!=1) { 232 out_buffer.append(" rowspan=\""); 233 out_buffer.append(lc_int.intValue()); 234 out_buffer.append("\""); 235 } 236 237 out_buffer.append(">"); 238 239 if (in_id!=null) { 240 out_buffer.append("<div id=\""); 241 out_buffer.append(in_id); 242 out_buffer.append("\">"); 243 } 244 245 out_buffer.append(in_item); 246 247 if (in_id!=null) { 248 out_buffer.append("</div>"); 249 } 250 251 out_buffer.append("</td>"); 252 } 253 256 public void doEndItems(StringBuffer out_buffer) { 257 out_buffer.append("</tr>"); 258 } 259 public void doEndPanel(StringBuffer buffer) { 260 buffer.append("</table></td></tr></table>\n"); 261 if (collectionTag.getWidth()!=null || collectionTag.getHeight()!=null) { 262 buffer.append("</div>"); 263 } 264 } 265 public void endFooter(StringBuffer in_buffer) { 266 in_buffer.append("</tr>\n"); 267 268 } 269 public void printFooterElement(StringBuffer in_buffer, String in_element, int in_span) { 270 in_buffer.append("<td "); 271 if (in_span>1) { 272 in_buffer.append(" colspan=\""); 273 in_buffer.append(in_span); 274 in_buffer.append("\""); 275 } 276 in_buffer.append(">"); 277 in_buffer.append(in_element); 278 in_buffer.append("</td>"); 279 280 } 281 public void startFooter(StringBuffer in_buffer) { 282 in_buffer.append("<tr>"); 283 } 284 285 287 290 public void endMathData(StringBuffer in_buffer) { 291 in_buffer.append("</tr>\n"); 292 } 293 294 public void renderMathData(StringBuffer in_buffer, String in_element, int in_span, String in_resultId, String in_styleClass) { 295 in_buffer.append("<td"); 296 if (in_styleClass!=null){ 297 in_buffer.append(" class=\""); 298 in_buffer.append(in_styleClass); 299 in_buffer.append("\""); 300 } 301 if (in_span>1){ 302 in_buffer.append(" colspan=\""); 303 in_buffer.append(in_span); 304 in_buffer.append("\""); 305 } 306 if (in_resultId!=null && in_resultId.length()!=0){ 307 in_buffer.append(" id=\"" + in_resultId + "\""); 308 } 309 in_buffer.append(">"); 310 in_buffer.append(in_element == null ? "" : in_element); 311 in_buffer.append("</td>\n"); 312 } 313 314 public void startMathData(StringBuffer in_buffer) { 315 in_buffer.append("<tr>\n"); 316 } 317 318 320 public void renderMultiLevelHeader(StringBuffer in_buffer, String in_title, String in_sortUrl, String in_styleClass, int in_colspan, int in_rowspan, String in_width) { 321 in_buffer.append("<th"); 322 if (in_colspan!=1) { 323 in_buffer.append(" colspan=\""); 324 in_buffer.append(in_colspan); 325 in_buffer.append("\""); 326 } 327 if (in_styleClass!=null) { 328 in_buffer.append(" class=\""); 329 in_buffer.append(in_styleClass); 330 in_buffer.append("\""); 331 } 332 if (in_rowspan!=1) { 333 in_buffer.append(" rowspan=\""); 334 in_buffer.append(in_rowspan); 335 in_buffer.append("\""); 336 } 337 if (in_width!=null) { 338 in_buffer.append(" width=\""); 339 in_buffer.append(in_width); 340 in_buffer.append("\""); 341 } 342 in_buffer.append(">"); 343 in_buffer.append(doPrintSortUrl(in_title, in_sortUrl)); 344 in_buffer.append("</th>"); 345 } 346 347 public void endMultiLevelHeaderRow(StringBuffer in_buffer) { 348 in_buffer.append("</tr>\n"); 349 } 350 public void startMultiLevelHeaderRow(StringBuffer in_buffer) { 351 in_buffer.append("<tr valign=\"top\">"); 352 } 353 } | Popular Tags |