1 12 package org.displaytag.model; 13 14 import java.util.Comparator ; 15 16 import org.apache.commons.beanutils.Converter; 17 import org.apache.commons.lang.StringUtils; 18 import org.apache.commons.lang.builder.ToStringBuilder; 19 import org.apache.commons.lang.builder.ToStringStyle; 20 import org.displaytag.decorator.DisplaytagColumnDecorator; 21 import org.displaytag.exception.DecoratorException; 22 import org.displaytag.exception.ObjectLookupException; 23 import org.displaytag.properties.SortOrderEnum; 24 import org.displaytag.util.Href; 25 import org.displaytag.util.HtmlAttributeMap; 26 import org.displaytag.util.HtmlTagUtil; 27 import org.displaytag.util.MultipleHtmlAttribute; 28 import org.displaytag.util.TagConstants; 29 30 31 37 public class HeaderCell 38 { 39 40 43 private HtmlAttributeMap htmlAttributes; 44 45 48 private HtmlAttributeMap headerAttributes; 49 50 53 private Href href; 54 55 58 private String paramName; 59 60 63 private String paramProperty; 64 65 68 private String title; 69 70 73 private boolean sortable; 74 75 78 private String sortName; 79 80 83 private DisplaytagColumnDecorator[] columnDecorators; 84 85 88 private int columnNumber; 89 90 93 private boolean alreadySorted; 94 95 98 private String beanPropertyName; 99 100 103 private boolean showNulls; 104 105 108 private int maxLength; 109 110 113 private int maxWords; 114 115 118 private int group; 119 120 123 private String sortPropertyName; 124 125 128 private boolean totaled; 129 130 133 private SortOrderEnum defaultSortOrder; 134 135 138 private double total; 139 140 143 private Comparator comparator; 144 145 149 public int getGroup() 150 { 151 return this.group; 152 } 153 154 158 public void setGroup(int groupingOrder) 159 { 160 this.group = groupingOrder; 161 } 162 163 167 public int getMaxLength() 168 { 169 return this.maxLength; 170 } 171 172 176 public void setMaxLength(int numOfChars) 177 { 178 this.maxLength = numOfChars; 179 } 180 181 185 public int getMaxWords() 186 { 187 return this.maxWords; 188 } 189 190 194 public void setMaxWords(int numOfWords) 195 { 196 this.maxWords = numOfWords; 197 } 198 199 203 public boolean getShowNulls() 204 { 205 return this.showNulls; 206 } 207 208 212 public void setShowNulls(boolean outputNulls) 213 { 214 this.showNulls = outputNulls; 215 } 216 217 221 public String getBeanPropertyName() 222 { 223 return this.beanPropertyName; 224 } 225 226 230 public void setBeanPropertyName(String propertyName) 231 { 232 this.beanPropertyName = propertyName; 233 } 234 235 239 public boolean isAlreadySorted() 240 { 241 return this.alreadySorted; 242 } 243 244 247 public void setAlreadySorted() 248 { 249 this.alreadySorted = true; 250 } 251 252 256 public int getColumnNumber() 257 { 258 return this.columnNumber; 259 } 260 261 265 public void setColumnNumber(int number) 266 { 267 this.columnNumber = number; 268 } 269 270 274 public DisplaytagColumnDecorator[] getColumnDecorators() 275 { 276 return this.columnDecorators != null ? this.columnDecorators : new DisplaytagColumnDecorator[0]; 277 } 278 279 283 public void setColumnDecorators(DisplaytagColumnDecorator[] decorator) 284 { 285 this.columnDecorators = decorator; 286 } 287 288 292 public boolean getSortable() 293 { 294 return this.sortable; 295 } 296 297 301 public void setSortable(boolean isSortable) 302 { 303 this.sortable = isSortable; 304 } 305 306 310 public String getSortName() 311 { 312 return sortName; 313 } 314 315 319 public void setSortName(String sortName) 320 { 321 this.sortName = sortName; 322 } 323 324 328 public String getTitle() 329 { 330 if (this.title != null) 331 { 332 return this.title; 333 } 334 else if (this.beanPropertyName != null) 335 { 336 return StringUtils.capitalize(this.beanPropertyName); 337 } 338 339 return TagConstants.EMPTY_STRING; 340 } 341 342 346 public void setTitle(String value) 347 { 348 this.title = value; 349 } 350 351 355 public HtmlAttributeMap getHtmlAttributes() 356 { 357 return this.htmlAttributes; 358 } 359 360 364 public void setHtmlAttributes(HtmlAttributeMap attributes) 365 { 366 this.htmlAttributes = attributes; 367 } 368 369 373 public HtmlAttributeMap getHeaderAttributes() 374 { 375 return this.headerAttributes; 376 } 377 378 382 public void setHeaderAttributes(HtmlAttributeMap attributes) 383 { 384 this.headerAttributes = attributes; 385 } 386 387 391 public void addHeaderClass(String cssClass) 392 { 393 if (StringUtils.isBlank(cssClass)) 395 { 396 return; 397 } 398 399 if (headerAttributes == null) 401 { 402 headerAttributes = new HtmlAttributeMap(); 403 } 404 405 Object classAttributes = this.headerAttributes.get(TagConstants.ATTRIBUTE_CLASS); 406 407 if (classAttributes == null) 409 { 410 this.headerAttributes.put(TagConstants.ATTRIBUTE_CLASS, new MultipleHtmlAttribute(cssClass)); 411 } 412 else 413 { 414 ((MultipleHtmlAttribute) classAttributes).addAttributeValue(cssClass); 415 } 416 } 417 418 422 public String getHeaderOpenTag() 423 { 424 return HtmlTagUtil.createOpenTagString(TagConstants.TAGNAME_COLUMN_HEADER, this.headerAttributes); 425 } 426 427 431 public String getCloseTag() 432 { 433 return TagConstants.TAG_OPENCLOSING + TagConstants.TAGNAME_COLUMN + TagConstants.TAG_CLOSE; 434 } 435 436 440 public String getHeaderCloseTag() 441 { 442 return TagConstants.TAG_OPENCLOSING + TagConstants.TAGNAME_COLUMN_HEADER + TagConstants.TAG_CLOSE; 443 } 444 445 449 public void setHref(Href baseHref) 450 { 451 this.href = baseHref; 452 } 453 454 458 public Href getHref() 459 { 460 return this.href; 461 } 462 463 467 public void setParamName(String name) 468 { 469 this.paramName = name; 470 } 471 472 476 public String getParamName() 477 { 478 return this.paramName; 479 } 480 481 485 public void setParamProperty(String property) 486 { 487 this.paramProperty = property; 488 } 489 490 494 public String getParamProperty() 495 { 496 return this.paramProperty; 497 } 498 499 503 public String getSortProperty() 504 { 505 return this.sortPropertyName; 506 } 507 508 512 public void setSortProperty(String propertyName) 513 { 514 this.sortPropertyName = propertyName; 515 } 516 517 521 public SortOrderEnum getDefaultSortOrder() 522 { 523 return this.defaultSortOrder; 524 } 525 526 530 public void setDefaultSortOrder(SortOrderEnum order) 531 { 532 this.defaultSortOrder = order; 533 } 534 535 538 public String toString() 539 { 540 return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE) .append("columnNumber", this.columnNumber) .append("title", this.title) .append("beanPropertyName", this.beanPropertyName) .toString(); 545 } 546 547 551 public void setComparator(Comparator columnComparator) 552 { 553 this.comparator = columnComparator; 554 } 555 556 560 public Comparator getComparator() 561 { 562 return this.comparator; 563 } 564 565 569 public boolean isTotaled() 570 { 571 return totaled; 572 } 573 574 578 public void setTotaled(boolean isTotaled) 579 { 580 this.totaled = isTotaled; 581 } 582 583 589 private void addToTotal(Object value) 590 { 591 if (value != null) 592 { 593 this.total = this.total + ((Number ) value).doubleValue(); 594 } 595 } 596 597 601 public double getTotal() 602 { 603 return this.total; 604 } 605 606 610 public void addCell(Column column) 611 { 612 if (this.totaled) 614 { 615 try 616 { 617 Object val = column.getValue(false); 618 addToTotal(val); 619 } 620 catch (ObjectLookupException e) 621 { 622 throw new RuntimeException (e); 623 } 624 catch (DecoratorException e) 625 { 626 throw new RuntimeException (e); 627 } 628 } 629 } 630 631 } | Popular Tags |