1 18 package org.apache.beehive.netui.tags.databinding.datagrid; 19 20 import org.apache.beehive.netui.util.internal.InternalStringBuilder; 21 22 import java.io.StringWriter ; 23 import java.io.IOException ; 24 import javax.servlet.jsp.tagext.JspFragment ; 25 import javax.servlet.jsp.JspException ; 26 import javax.servlet.jsp.JspContext ; 27 import javax.servlet.http.HttpServletRequest ; 28 29 import org.apache.beehive.netui.tags.IHtmlI18n; 30 import org.apache.beehive.netui.tags.IHtmlEvents; 31 import org.apache.beehive.netui.tags.html.HtmlConstants; 32 import org.apache.beehive.netui.tags.rendering.THeadTag; 33 import org.apache.beehive.netui.tags.rendering.TrTag; 34 import org.apache.beehive.netui.tags.rendering.AbstractRenderAppender; 35 import org.apache.beehive.netui.tags.rendering.StringBuilderRenderAppender; 36 import org.apache.beehive.netui.tags.rendering.AbstractHtmlState; 37 import org.apache.beehive.netui.databinding.datagrid.api.rendering.DataGridTagModel; 38 import org.apache.beehive.netui.databinding.datagrid.api.rendering.StyleModel; 39 import org.apache.beehive.netui.databinding.datagrid.runtime.rendering.table.TableRenderer; 40 import org.apache.beehive.netui.databinding.datagrid.runtime.util.JspUtil; 41 import org.apache.beehive.netui.util.Bundle; 42 43 104 public class Header 105 extends AbstractDataGridHtmlTag 106 implements IHtmlEvents, IHtmlI18n { 107 108 private boolean _renderRow = true; 109 private THeadTag.State _theadTag = new THeadTag.State(); 110 111 115 public String getTagName() { 116 return "Header"; 117 } 118 119 127 public void setOnClick(String onClick) { 128 _theadTag.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, HtmlConstants.ONCLICK, onClick); 129 } 130 131 139 public void setOnDblClick(String onDblClick) { 140 _theadTag.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, HtmlConstants.ONDBLCLICK, onDblClick); 141 } 142 143 151 public void setOnKeyDown(String onKeyDown) { 152 _theadTag.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, HtmlConstants.ONKEYDOWN, onKeyDown); 153 } 154 155 163 public void setOnKeyUp(String onKeyUp) { 164 _theadTag.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, HtmlConstants.ONKEYUP, onKeyUp); 165 } 166 167 175 public void setOnKeyPress(String onKeyPress) { 176 _theadTag.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, HtmlConstants.ONKEYPRESS, onKeyPress); 177 } 178 179 187 public void setOnMouseDown(String onMouseDown) { 188 _theadTag.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, HtmlConstants.ONMOUSEDOWN, onMouseDown); 189 } 190 191 199 public void setOnMouseUp(String onMouseUp) { 200 _theadTag.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, HtmlConstants.ONMOUSEUP, onMouseUp); 201 } 202 203 211 public void setOnMouseMove(String onMouseMove) { 212 _theadTag.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, HtmlConstants.ONMOUSEMOVE, onMouseMove); 213 } 214 215 223 public void setOnMouseOut(String onMouseOut) { 224 _theadTag.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, HtmlConstants.ONMOUSEOUT, onMouseOut); 225 } 226 227 235 public void setOnMouseOver(String onMouseOver) { 236 _theadTag.registerAttribute(AbstractHtmlState.ATTR_JAVASCRIPT, HtmlConstants.ONMOUSEOVER, onMouseOver); 237 } 238 239 247 public void setStyle(String style) { 248 if("".equals(style)) return; 249 250 _theadTag.style = style; 251 } 252 253 261 public void setStyleClass(String styleClass) { 262 if("".equals(styleClass)) return; 263 264 _theadTag.styleClass = styleClass; 265 } 266 267 275 public void setTitle(String title) { 276 _theadTag.registerAttribute(AbstractHtmlState.ATTR_GENERAL, HtmlConstants.TITLE, title); 277 } 278 279 287 public void setAlign(String align) { 288 289 _theadTag.registerAttribute(AbstractHtmlState.ATTR_GENERAL, HtmlConstants.ALIGN, align); 290 } 291 292 300 public void setChar(String alignChar) { 301 _theadTag.registerAttribute(AbstractHtmlState.ATTR_GENERAL, HtmlConstants.CHAR, alignChar); 302 } 303 304 312 public void setCharoff(String alignCharOff) { 313 _theadTag.registerAttribute(AbstractHtmlState.ATTR_GENERAL, HtmlConstants.CHAROFF, alignCharOff); 314 } 315 316 324 public void setValign(String valign) { 325 326 _theadTag.registerAttribute(AbstractHtmlState.ATTR_GENERAL, HtmlConstants.VALIGN, valign); 327 } 328 329 337 public void setLang(String lang) { 338 _theadTag.registerAttribute(AbstractHtmlState.ATTR_GENERAL, HtmlConstants.LANG, lang); 339 } 340 341 349 public void setDir(String dir) { 350 _theadTag.registerAttribute(AbstractHtmlState.ATTR_GENERAL, HtmlConstants.DIR, dir); 351 } 352 353 367 public void setRenderRow(boolean renderRow) { 368 _renderRow = renderRow; 369 } 370 371 380 public void setTagId(String tagId) 381 throws JspException { 382 applyTagId(_theadTag, tagId); 383 } 384 385 395 public void doTag() 396 throws JspException , IOException { 397 398 JspContext jspContext = getJspContext(); 399 DataGridTagModel dgm = DataGridUtil.getDataGridTagModel(jspContext); 400 if(dgm == null) 401 throw new JspException (Bundle.getErrorString("DataGridTags_MissingDataGridModel")); 402 403 int gridRenderState = dgm.getRenderState(); 404 if(gridRenderState == DataGridTagModel.RENDER_STATE_HEADER) { 405 406 InternalStringBuilder content = new InternalStringBuilder(); 407 AbstractRenderAppender appender = new StringBuilderRenderAppender(content); 408 409 StyleModel styleModel = dgm.getStyleModel(); 410 assert styleModel != null; 411 412 TableRenderer tableRenderer = dgm.getTableRenderer(); 413 assert tableRenderer != null; 414 415 if(dgm.isRenderRowGroups()) { 416 _theadTag.styleClass = (_theadTag.styleClass != null ? _theadTag.styleClass : styleModel.getTableHeadClass()); 417 tableRenderer.openTableHead(_theadTag, appender); 418 } 419 420 TrTag.State trState = null; 421 if(_renderRow) { 422 trState = new TrTag.State(); 423 trState.styleClass = styleModel.getHeaderRowClass(); 424 tableRenderer.openHeaderRow(trState, appender); 425 } 426 427 JspFragment fragment = getJspBody(); 428 if(fragment != null) { 429 StringWriter sw = new StringWriter (); 430 fragment.invoke(sw); 431 appender.append(sw.toString()); 432 } 433 434 if(_renderRow) 435 tableRenderer.closeHeaderRow(appender); 436 437 if(dgm.isRenderRowGroups()) { 438 tableRenderer.closeTableHead(appender); 439 String tfootScript = null; 440 if(_theadTag.id != null) { 441 HttpServletRequest request = JspUtil.getRequest(getJspContext()); 442 tfootScript = renderNameAndId(request, _theadTag, null); 443 } 444 445 if(tfootScript != null) 446 appender.append(tfootScript); 447 } 448 449 jspContext.getOut().write(content.toString()); 450 } 451 } 452 } 453 | Popular Tags |