1 package fr.improve.struts.taglib.layout.util; 2 3 import java.util.HashMap ; 4 import java.util.Map ; 5 6 import javax.servlet.jsp.JspException ; 7 import javax.servlet.jsp.PageContext ; 8 import javax.servlet.jsp.tagext.TagSupport ; 9 10 import fr.improve.struts.taglib.layout.collection.CollectionItemTag; 11 import fr.improve.struts.taglib.layout.collection.CollectionTag; 12 import fr.improve.struts.taglib.layout.datagrid.Datagrid; 13 import fr.improve.struts.taglib.layout.el.Expression; 14 15 20 public class BasicDatagrid implements IDatagridRenderer { 21 protected Map styles = new HashMap (); 22 protected CollectionTag collectionTag; 23 protected PageContext pageContext; 24 protected String styleClass; 25 26 public void init(PageContext pg, String in_styleClass, TagSupport in_tag) throws JspException { 27 collectionTag = (CollectionTag) in_tag; 28 pageContext = pg; 29 styleClass = collectionTag.getStyleClass(); 30 styles.clear(); 31 styles.put(Datagrid.SELECTED, styleClass + "_SEL"); 32 styles.put(Datagrid.REMOVED, styleClass + "_DEL"); 33 } 34 37 public void doPrintEmptyCollection(StringBuffer out_buffer, String in_message) { 38 out_buffer.append("<tr><td colspan=\""); 39 out_buffer.append(collectionTag.getHeaders().size()); 40 out_buffer.append("\" class=\""); 41 out_buffer.append(styleClass); 42 out_buffer.append("\"> "); 43 out_buffer.append(in_message); 44 out_buffer.append("</td></tr>"); 45 } 46 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 } 63 } 64 67 public void doStartPanel(StringBuffer buffer, String align, String width) { 68 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 buffer.append("<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\""); 85 if (align!=null) { 86 buffer.append(" align=\""); 87 buffer.append(align); 88 buffer.append("\""); 89 } 90 if (width!=null) { 91 buffer.append(" width=\""); 92 buffer.append(width); 93 buffer.append("\""); 94 } 95 if (styleClass!=null) { 96 buffer.append(" class=\""); 97 buffer.append(styleClass); 98 buffer.append("\""); 99 } 100 buffer.append("><tr><td valign=\"top\">"); 101 buffer.append("<table cellspacing=\"1\" cellpadding=\"1\" border=\"0\" width=\"100%\""); 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(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 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 219 out_buffer.append(" class=\""); 220 if (collectionTag.getIndex() % 2 ==0) { 221 out_buffer.append(getRowStyleClass()); 222 } else { 223 out_buffer.append(getRowStyleClass2()); 224 } 225 out_buffer.append("\">"); 226 } 227 230 public void doPrintItem(StringBuffer out_buffer, String in_item, String [] in_styleClass, String in_id) { 231 out_buffer.append("<td"); 232 239 if (in_styleClass.length>1) { 240 out_buffer.append(" style=\""); 241 for (int i = 0; i < in_styleClass.length-1; i++) { 242 out_buffer.append(in_styleClass[i+1]); 243 } 244 out_buffer.append("\""); 245 } 246 247 Integer lc_int = (Integer ) pageContext.getAttribute(CollectionItemTag.SPAN_KEY); 248 if (lc_int!=null && lc_int.intValue()!=1) { 249 out_buffer.append(" rowspan=\""); 250 out_buffer.append(lc_int.intValue()); 251 out_buffer.append("\""); 252 } 253 254 out_buffer.append(">"); 255 256 if (in_id!=null) { 257 out_buffer.append("<div id=\""); 258 out_buffer.append(in_id); 259 out_buffer.append("\">"); 260 } 261 262 out_buffer.append(in_item); 263 264 if (in_id!=null) { 265 out_buffer.append("</div>"); 266 } 267 268 out_buffer.append("</td>"); 269 } 270 273 public void doEndItems(StringBuffer out_buffer) { 274 out_buffer.append("</tr>"); 275 } 276 public void doEndPanel(StringBuffer buffer) { 277 buffer.append("</table></td></tr></table>\n"); 278 if (collectionTag.getWidth()!=null || collectionTag.getHeight()!=null) { 279 buffer.append("</div>"); 280 } 281 } 282 283 285 288 public String getColumnStyleClass(int in_columnNumber) { 289 return ""; 291 } 292 293 296 public String getRowStyleClass() { 297 return styleClass; 298 } 299 300 303 public String getRowStyleClass2() { 304 return styleClass + "2"; 305 } 306 307 310 public Map getRowStyleClassMap() { 311 return styles; 312 } 313 314 316 public void doAfterBody(StringBuffer buffer) throws JspException { 317 } 319 320 public void doBeforeBody(StringBuffer buffer, String align) throws JspException { 321 } 323 324 public void doPrintBlankLine(StringBuffer buffer, int cols) throws JspException { 325 } 327 328 } | Popular Tags |