litesoft
@ 947
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 |
// This Source Code is in the Public Domain per: http://unlicense.org package org.litesoft.GWT.client.widgets.datatables; import org.litesoft.commonfoundation.html.*; import org.litesoft.commonfoundation.typeutils.*; import java.util.*; import org.litesoft.GWT.client.widgets.datatables.DetailRowModel.*; import org.litesoft.GWT.client.widgets.nonpublic.*; import com.google.gwt.dom.client.*; import com.google.gwt.event.dom.client.*; import com.google.gwt.event.logical.shared.*; import com.google.gwt.event.shared.*; import com.google.gwt.gen2.table.client.*; import com.google.gwt.gen2.table.client.TableDefinition.*; import com.google.gwt.gen2.table.client.TableModelHelper.*; import com.google.gwt.gen2.table.client.property.*; import com.google.gwt.user.client.Element; import com.google.gwt.user.client.*; import com.google.gwt.user.client.Timer; import com.google.gwt.user.client.ui.*; import com.google.gwt.user.client.ui.HasHorizontalAlignment.*; import com.google.gwt.user.client.ui.HasVerticalAlignment.*; import com.google.gwt.widgetideas.client.*; public class AccordionTable<RowType> extends Composite implements HasTableDefinition<RowType>, HasShowRangeHandlers<Integer> { private final ListTableModel<RowType> mModel = new ListTableModel<RowType>(); private final AccordionTableTable mTable = new AccordionTableTable(); private final Element mGlassPane = Document.get().createDivElement().cast(); private DetailRowModelImpl<RowType> mDetailRowModel = new DetailRowModelImpl<RowType>(); private TableDefinitionPlus<RowType> mTableDefinition; private TableModel<RowType> mDataSource; private TableModelHelper.Request mOutstandingRequest = null; private TableRowCountCallback mRowCountCallback = null; private int mMaxWholeRows = 0; private int mViewportHeight = 0; private int mHeaderRowHeight = 0; private int mFooterRowHeight = 0; private int mPrototypeDetailRowHeight = 0; private int mPrototypeNormalRowHeight = 0; private Iterator<RowType> mDataToRenderPendingSize = null; private static final String STYLE = "AccordionTable"; public AccordionTable() { AbsolutePanel viewport = new AbsolutePanel(); ResizableWidgetCollection.get().add( new ResizableWidgetAdaptor( this, viewport.getElement() ) { @Override public void onResize( int pWidth, int pHeight ) { mViewportHeight = pHeight; sizeOrDataChanged(); } } ); viewport.add( mTable, 0, 0 ); UIObject.setVisible( mGlassPane, false ); mGlassPane.getStyle().setProperty( "width", "100%" ); viewport.getElement().appendChild( mGlassPane ); initWidget( viewport ); setStyleName( STYLE ); setHeight( "100%" ); setWidth( "100%" ); mTable.setWidth( "100%" ); mTable.addHighlightHandler( new HoverController() ); } /** * Will be called when the data changes or the count of rendered rows * changes. Useful for updating calulations based on the data. * * @see #getVisibleRowCount() */ @Override public HandlerRegistration addShowRangeHandler( ShowRangeHandler<Integer> pHandler ) { return addHandler( pHandler, ShowRangeEvent.getType() ); } public void init( TableModel<RowType> pTableModel, TableDefinitionPlus<RowType> pTableDefinition ) { RowType prototypeRowValue = pTableDefinition.getPrototypeRowValue(); if ( prototypeRowValue == null ) { throw new IllegalArgumentException( "TableDefinition.prototypeRowValue cannot be null for AccordionTable" ); } mDataSource = pTableModel; mTableDefinition = pTableDefinition; List<ColumnDefinition<RowType, ?>> colDefs = pTableDefinition.getVisibleColumnDefinitions(); for ( int col = 0, size = colDefs.size(); col < size; col++ ) { ColumnDefinition<RowType, ?> colDef = colDefs.get( col ); Object headerValue = colDef.getColumnProperty( HeaderProperty.TYPE ).getHeader( 0 ); HorizontalAlignmentConstant alignment = colDef.getColumnProperty( HorizontalAlignmentProperty.TYPE ).getValue(); Element td = mTable.setHeader( col, headerValue, alignment ); Style style = td.getStyle(); style.setPropertyPx( "paddingLeft", colDef.getColumnProperty( PaddingProperty.LEFT ).getValue() ); style.setPropertyPx( "paddingRight", colDef.getColumnProperty( PaddingProperty.RIGHT ).getValue() ); style.setPropertyPx( "paddingTop", colDef.getColumnProperty( PaddingProperty.TOP ).getValue() ); style.setPropertyPx( "paddingBottom", colDef.getColumnProperty( PaddingProperty.BOTTOM ).getValue() ); int minWidth = colDef.getColumnProperty( MinimumWidthProperty.TYPE ).getMinimumColumnWidth(); int maxWidth = colDef.getColumnProperty( MaximumWidthProperty.TYPE ).getMaximumColumnWidth(); if ( minWidth != MinimumWidthProperty.NO_MINIMUM_WIDTH ) { mTable.setColumnWidth( col, maxWidth ); } else if ( maxWidth != MaximumWidthProperty.NO_MAXIMUM_WIDTH ) { mTable.setColumnWidth( col, maxWidth ); } } // setup w/ some fake data so we can calculate row heights mTable.setFooter( 0, HTMLConstants.NBSP, null, 0 ); mTable.resizeRows( 2 ); final Element detailTr = mTable.getRowElement( 0 ); final Element normalTr = mTable.getRowElement( 1 ); CommonElementHelper.hide( detailTr ); CommonElementHelper.hide( normalTr ); AccordionTable.AccordionTableTable.RowView<RowType> rowView = mTable.new RowView<RowType>(); AccordionTable.AccordionTableTable.CellView<RowType> cellView = mTable.new CellView<RowType>( -1, new DetailRowModel<RowType>() { @Override public DetailRowAlignment getAlign() { return DetailRowAlignment.Top; } @Override public int getDetailRow() { return 0; } @Override public boolean isDetailRow( int pIndex ) { return pIndex == 0; } } ); renderRowImpl( 0, prototypeRowValue, rowView, cellView ); renderRowImpl( 1, prototypeRowValue, rowView, cellView ); ResizableWidgetCollection.get().add( new TemporaryResizableWidgetAdaptor( this, mTable.getElement() ) { @Override protected void onSizeInitialized( int pWidth, int pHeight ) { mHeaderRowHeight = mTable.getHeaderRowElement().getOffsetHeight(); mFooterRowHeight = mTable.getFooterRowElement().getOffsetHeight(); mPrototypeDetailRowHeight = detailTr.getOffsetHeight(); mPrototypeNormalRowHeight = normalTr.getOffsetHeight(); mTable.resizeRows( 0 ); sizeOrDataChanged(); } } ); mTable.addClickHandler( new TableHelper.GridClickHandler<RowType>( 1, mTable.getGridHelper(), colDefs ) { @Override protected RowType getRowValue( int pRow ) { return mModel.get( pRow ); } } ); loadData(); } public void loadData() { mOutstandingRequest = new TableModelHelper.Request(); mDataSource.requestRows( mOutstandingRequest, new TableModel.Callback<RowType>() { @Override public void onRowsReady( Request pRequest, Response<RowType> pResponse ) { // ignore responses to stale requests if ( pRequest == mOutstandingRequest ) { mOutstandingRequest = null; mDataToRenderPendingSize = pResponse.getRowValues(); sizeOrDataChanged(); } } @Override public void onFailure( Throwable pCaught ) { // TODO: handle requestRows() failure Window.alert( pCaught.getMessage() ); } } ); } private boolean isSizeInitialized() { return mViewportHeight > 0 && mHeaderRowHeight > 0 && mFooterRowHeight > 0 && mPrototypeDetailRowHeight > 0 && mPrototypeNormalRowHeight > 0; } private void sizeOrDataChanged() { if ( isSizeInitialized() ) { boolean fireRowCountChanged = false; boolean fireShowRange = false; int oldVisibleRowCount = getVisibleRowCount(); // TODO: subtract header and (optional) footer height int maxWholeRows = Math.max( 1, (mViewportHeight - mPrototypeDetailRowHeight - mHeaderRowHeight - mFooterRowHeight) / mPrototypeNormalRowHeight + 1 ); if ( mMaxWholeRows != maxWholeRows ) { mMaxWholeRows = maxWholeRows; fireRowCountChanged = true; } int visibleRowCount; if ( mDataToRenderPendingSize != null ) { int oldModelRowCount = getRowCount(); mModel.setAll( mDataToRenderPendingSize ); visibleRowCount = getVisibleRowCount(); // note: calculated using model size mDetailRowModel.update( mModel.mList, 0, visibleRowCount ); mDataToRenderPendingSize = null; fireRowCountChanged |= getRowCount() != oldModelRowCount; fireShowRange = true; mTable.resizeRows( visibleRowCount ); renderRows( 0, visibleRowCount ); } else { visibleRowCount = getVisibleRowCount(); mTable.resizeRows( visibleRowCount ); if ( mDetailRowModel.update( mModel.mList, 0, visibleRowCount ) && mDetailRowModel.getDetailRow() != -1 ) { renderRow( mDetailRowModel.getDetailRow() ); } renderRows( oldVisibleRowCount, visibleRowCount - oldVisibleRowCount ); } fireShowRange |= visibleRowCount != oldVisibleRowCount; if ( fireRowCountChanged && mRowCountCallback != null ) { mRowCountCallback.rowCountChanged( visibleRowCount, mModel.getRowCount(), mMaxWholeRows ); } if ( fireShowRange ) { ShowRangeEvent.fire( AccordionTable.this, 0, visibleRowCount ); } } } public void renderRow( int pIndex ) { renderRows( pIndex, 1 ); } /** * @param pCount negative or 0 will be NOOP */ private void renderRows( int pStartRow, int pCount ) { if ( pCount <= 0 ) { return; } AccordionTable.AccordionTableTable.RowView<RowType> rowView = mTable.new RowView<RowType>(); AccordionTable.AccordionTableTable.CellView<RowType> cellView = mTable.new CellView<RowType>( mPrototypeNormalRowHeight, mDetailRowModel ); for ( int row = pStartRow, terminus = pStartRow + pCount; row < terminus; row++ ) { RowType rowValue = mModel.get( row ); renderRowImpl( row, rowValue, rowView, cellView ); } } private void renderRowImpl( int pRowIndex, RowType pRowValue, AccordionTable.AccordionTableTable.RowView<RowType> pRowView, AccordionTable.AccordionTableTable.CellView<RowType> pCellView ) { setGlassPaneVisible( true ); RowRenderer<RowType> rowRenderer = mTableDefinition.getRowRenderer(); List<ColumnDefinition<RowType, ?>> colDefs = mTableDefinition.getVisibleColumnDefinitions(); pRowView.setRowIndex( pRowIndex ); rowRenderer.renderRowValue( pRowValue, pRowView ); for ( int col = 0, colCount = colDefs.size(); col < colCount; col++ ) { pCellView.renderAccordionCell( pRowIndex, col, pRowValue, colDefs.get( col ) ); } setGlassPaneVisible( false ); } public void renderFooter( String[] pValues ) { if ( pValues.length > mTable.getColumnCount() ) { throw new IllegalArgumentException( String.valueOf( pValues.length ) ); } if ( mTableDefinition == null ) { throw new IllegalStateException(); } List<ColumnDefinition<RowType, ?>> colDefs = mTableDefinition.getVisibleColumnDefinitions(); for ( int col = 0; col < pValues.length; col++ ) { ColumnDefinition<RowType, ?> colDef = colDefs.get( col ); int zPaddingRight = colDef.getColumnProperty( PaddingProperty.RIGHT ).getValue(); String footerValue = pValues[col]; HorizontalAlignmentConstant alignment = colDef.getColumnProperty( HorizontalAlignmentProperty.TYPE ).getValue(); mTable.setFooter( col, footerValue, alignment, zPaddingRight ); } } private void setGlassPaneVisible( boolean visible ) { mGlassPane.getStyle().setPropertyPx( "height", mViewportHeight ); UIObject.setVisible( mGlassPane, visible ); } public void setFooterAlignment( int col, HorizontalAlignmentConstant pAlign ) { mTable.setFooterAlignment( col, pAlign ); } public DetailRowCallback<RowType> getDetailRowCallback() { return mDetailRowModel.getCallback(); } public void setDetailRowCallback( DetailRowCallback<RowType> pDetailRowCallback ) { mDetailRowModel.setCallback( pDetailRowCallback ); } @Override public TableDefinitionPlus<RowType> getTableDefinition() { return mTableDefinition; } public RowType getRowValue( int pRow ) { return mModel.get( pRow ); } public int getVisibleRowCount() { return Math.min( mModel.size(), mMaxWholeRows ); } public int getRowCount() { return mModel.size(); } public TableRowCountCallback getRowCountCallback() { return mRowCountCallback; } public void setRowCountCallback( TableRowCountCallback pRowCountCallback ) { mRowCountCallback = pRowCountCallback; } private class HoverController implements HighlightHandler<Integer> { private final HoverTimer mHoverTimer = new HoverTimer(); @Override public void onHighlight( HighlightEvent<Integer> pEvent ) { mHoverTimer.setHoverRow( pEvent.getHighlighted() ); } private void doHighlight( int pNewRow ) { int oldRow = mDetailRowModel.getDetailRow(); if ( mDetailRowModel.maybeSetDetailRow( pNewRow, mModel.get( pNewRow ) ) ) { // render greater row first to avoid layout settling from incremental rendering int greaterRow = Math.max( oldRow, pNewRow ); int lesserRow = Math.min( oldRow, pNewRow ); if ( greaterRow != -1 ) { renderRows( greaterRow, 1 ); } if ( lesserRow != -1 ) { renderRows( lesserRow, 1 ); } } } private class HoverTimer extends Timer { /** * This is -1 if not running, a valid value if running. */ private int mRow = -1; public void setHoverRow( int pRow ) { if ( mRow != -1 ) { cancel(); } mRow = pRow; if ( mRow != -1 ) { schedule( 250 ); } } @Override public void run() { doHighlight( mRow ); mRow = -1; } } } private static class AccordionTableTable extends FixedWidthFlexTable implements HasHighlightHandlers<Integer> { private static final int HEADER_ROW = 0; private final TableHelper.GridHelper mGridHelper; private int mFooterRow = -1; /** * The row that is currently under the mouse. Used for highlight. Not * necessarily the detail row due to delay in setting the detail row. */ private int mHilightedRow = -1; public AccordionTableTable() { RowFormatter rowFormatter = new RowFormatter(); setRowFormatter( rowFormatter ); setCellFormatter( new CellFormatter() ); UIObject.setStylePrimaryName( rowFormatter.ensureElement( 0 ), "AccordionTable-headerRow" ); setCellPadding( 0 ); setCellSpacing( 0 ); sinkEvents( Event.ONMOUSEOVER ); sinkEvents( Event.ONMOUSEOUT ); mGridHelper = new TableHelper.GridHelper( this ) { @Override protected int getRowIndex( com.google.gwt.user.client.Element pRowElement ) { return AccordionTableTable.this.getRowIndex( pRowElement ); } @Override protected int getCellIndex( Element pRowElement, Element pCellElement ) { return AccordionTableTable.this.getCellIndex( pRowElement, pCellElement ); } }; } public HandlerRegistration addClickHandler( ClickHandler pHandler ) { return addDomHandler( pHandler, ClickEvent.getType() ); } @Override public HandlerRegistration addHighlightHandler( HighlightHandler<Integer> pHandler ) { return addHandler( pHandler, HighlightEvent.getType() ); } public TableHelper.GridHelper getGridHelper() { return mGridHelper; } @Override protected Element getBodyElement() { return super.getBodyElement(); } /** * Get the element for the normal row (index is adjusted to account for header row). */ public Element getRowElement( int pRow ) { return getRowFormatter().getElement( pRow + 1 ); } public Element getHeaderRowElement() { return getRowFormatter().getElement( HEADER_ROW ); } public Element getFooterRowElement() { ensureFooter(); return getRowFormatter().getElement( mFooterRow ); } public Element setHeader( int pCol, Object pValue, HorizontalAlignmentConstant pAlign ) { Element innerTd = ((CellFormatter) getCellFormatter()).ensureElement( HEADER_ROW, pCol ); Element innerTr = innerTd.getParentElement().cast(); Element innerTbody = innerTr.getParentElement().cast(); Element innerTable = innerTbody.getParentElement().cast(); Element outerTd = innerTable.getParentElement().cast(); // set the style name on the containing td so background styles will be 100% row height UIObject.setStylePrimaryName( outerTd, "AccordionTable-headerCell" ); if ( pAlign != null ) { innerTd.setPropertyString( "align", pAlign.getTextAlignString() ); } String stringValue = Strings.noEmpty( (String) pValue ); innerTd.setInnerHTML( (stringValue != null) ? stringValue : HTMLConstants.NBSP ); return innerTd; } public void setFooter( int pCol, Object pValue, HorizontalAlignmentConstant pAlign, int pPaddingRight ) { int footerRow = ensureFooter(); Element td = ((CellFormatter) getCellFormatter()).ensureElement( footerRow, pCol ); UIObject.setStylePrimaryName( td, "AccordionTable-footerCell" ); if ( pAlign != null ) { td.setPropertyString( "align", pAlign.getTextAlignString() ); } if ( pPaddingRight > 0 ) { Style style = td.getStyle(); style.setPropertyPx( "paddingRight", pPaddingRight ); } String stringValue = Strings.noEmpty( (String) pValue ); td.setInnerHTML( (stringValue != null) ? stringValue : HTMLConstants.NBSP ); } public void setFooterAlignment( int pCol, HorizontalAlignmentConstant pAlign ) { Element td = ((CellFormatter) getCellFormatter()).ensureElement( mFooterRow, pCol ); td.setPropertyString( "align", pAlign.getTextAlignString() ); } private int ensureFooter() { int footerRowIndex; boolean hasFooterRow = mFooterRow != -1; if ( !hasFooterRow ) { footerRowIndex = getRowCount(); insertRow( footerRowIndex ); mFooterRow = footerRowIndex; } else { footerRowIndex = getRowCount() - 1; } return footerRowIndex; } public void resizeRows( int pRowCount ) { int actualCount = getRowCount() - 1; // subtract header row boolean hasFooterRow = mFooterRow != -1; if ( hasFooterRow ) { actualCount--; } while ( actualCount > pRowCount ) { removeRow( actualCount-- ); } while ( actualCount < pRowCount ) { insertRow( ++actualCount ); } if ( hasFooterRow ) { mFooterRow = actualCount + 1; } if ( mHilightedRow >= actualCount ) { mHilightedRow = -1; } } /** * Have to override super method to append div to td */ @Override protected void addCells( int pRow, int pNum ) { // Account for ghost row addCells( getBodyElement(), pRow + 1, pNum ); clearIdealWidths0(); } private native void clearIdealWidths0() /*-{ this.@com.google.gwt.gen2.table.client.FixedWidthFlexTable::clearIdealWidths()(); }-*/; private static native void addCells( Element table, int row, int num ) /*-{ var rowElem = table.rows[row]; for ( var i = 0; i < num; i++ ) { var cell = $doc.createElement( "td" ); cell['colSpan'] = 1; cell['rowSpan'] = 1; var innerCell = $doc.createElement( "td" ); innerCell.style["overflow"] = "hidden"; var tr = $doc.createElement( "tr" ); tr.appendChild( innerCell ); var tbody = $doc.createElement( "tbody" ); tbody.appendChild( tr ); var table = $doc.createElement( "table" ); table.appendChild( tbody ); table.style["width"] = "100%"; table["cellSpacing"] = 0; table["cellPadding"] = 0; cell.appendChild( table ); rowElem.appendChild( cell ); } }-*/; @Override public void onBrowserEvent( Event pEvent ) { // the current incubator HTMLTable does not call super() switch ( pEvent.getTypeInt() ) { case Event.ONCLICK: DomEvent.fireNativeEvent( pEvent, this, getElement() ); break; case Event.ONMOUSEOVER: int row = mGridHelper.getRowForEvent( pEvent ); updateHighlightedRow( row ); break; case Event.ONMOUSEOUT: // only process mouse out if exiting the widget Element toElement = pEvent.getRelatedEventTarget().cast(); if ( toElement == null || !getElement().isOrHasChild( toElement ) ) { updateHighlightedRow( -1 ); } break; } super.onBrowserEvent( pEvent ); } private void updateHighlightedRow( int pRow ) { assert pRow >= -1; if ( pRow == 0 || pRow == mFooterRow ) { pRow = -1; } if ( mHilightedRow != pRow ) { RowFormatter rowFormatter = (RowFormatter) getRowFormatter(); if ( mHilightedRow != -1 ) { Element tr = rowFormatter.getElement( mHilightedRow ); UIObject.setStyleName( tr, "highlighted", false ); } mHilightedRow = pRow; if ( mHilightedRow != -1 ) { Element tr = rowFormatter.getElement( mHilightedRow ); UIObject.setStyleName( tr, "highlighted", true ); } HighlightEvent.fire( this, (mHilightedRow == -1) ? -1 : mHilightedRow - 1 ); } } private class RowFormatter extends FixedWidthFlexRowFormatter { /** * Override to gain access */ @Override protected Element ensureElement( int pRow ) { return super.ensureElement( pRow ); } /** * Override to gain access */ @Override protected Element getRawElement( int pRow ) { return super.getRawElement( pRow ); } } private class CellFormatter extends FixedWidthFlexCellFormatter { /** * Override to gain access */ @Override protected Element getRawElement( int pRow, int pColumn ) { Element outerTd = super.getRawElement( pRow, pColumn ); Element table = outerTd.getFirstChildElement().cast(); Element tbody = table.getFirstChildElement().cast(); Element tr = tbody.getFirstChildElement().cast(); Element td = tr.getFirstChildElement().cast(); return td; } /** * Override to gain access */ @Override protected Element ensureElement( int pRow, int pColumn ) { return super.ensureElement( pRow, pColumn ); } } private class RowView<RowType> extends AbstractRowView<RowType> { private int mRowIndex; public RowView() { super( null ); } @Override public int getRowIndex() { return mRowIndex; } public void setRowIndex( int pRowIndex ) { mRowIndex = pRowIndex; } @Override public void setStyleAttribute( String attr, String value ) { ((RowFormatter) getRowFormatter()).getRawElement( getRowIndex() + 1 ).getStyle().setProperty( attr, value ); } @Override public void setStyleName( String stylename ) { if ( getRowIndex() + 1 == mHilightedRow ) { stylename += " highlighted"; } getRowFormatter().setStyleName( getRowIndex() + 1, stylename ); } } private class CellView<RowType> extends AbstractCellView<RowType> { private final DetailRowModel<RowType> mDetailRowModel; private final int mNormalRowHeight; private Element mViewTableElement; // the inner TD in each TD public CellView( int normalRowHeight, DetailRowModel<RowType> detailRowModel ) { super( null ); mNormalRowHeight = normalRowHeight; mDetailRowModel = detailRowModel; } public void renderAccordionCell( int rowIndex, int cellIndex, RowType rowValue, ColumnDefinition<RowType, ?> columnDef ) { // ensure element first so we can getRawElement() for all future needs mViewTableElement = ((CellFormatter) getCellFormatter()).ensureElement( rowIndex + 1, cellIndex ); Element tr = mViewTableElement.getParentElement().cast(); Element tbody = tr.getParentElement().cast(); Element table = tbody.getParentElement().cast(); Element outerTd = table.getParentElement().cast(); UIObject.setStylePrimaryName( mViewTableElement, "AccordionTable-dataCell" ); boolean detailRow = mDetailRowModel.isDetailRow( rowIndex ); String valign = null; if ( detailRow ) { valign = (mDetailRowModel.getAlign() == DetailRowAlignment.Top) ? "top" : "bottom"; } outerTd.getStyle().setProperty( "verticalAlign", valign ); super.renderCellImpl( rowIndex, cellIndex, rowValue, columnDef ); mViewTableElement = null; } @Override @SuppressWarnings("unchecked") protected void renderRowValue( RowType rowValue, ColumnDefinition columnDef ) { CellRenderer cellRenderer = columnDef.getCellRenderer(); boolean detailRow = mDetailRowModel.isDetailRow( getRowIndex() ); boolean maxHeight = false; // typically true for detail cells if ( cellRenderer instanceof DetailCellRenderer ) { DetailCellRenderer<RowType> detailRenderer = (DetailCellRenderer<RowType>) cellRenderer; maxHeight = detailRow && detailRenderer.isMaxHeight(); ((DetailCellRenderer) cellRenderer).setDetailRow( detailRow ); } if ( mNormalRowHeight > 0 ) { mViewTableElement.getStyle().setProperty( "height", (detailRow && !maxHeight) ? mNormalRowHeight + "px" : "" ); } cellRenderer.renderRowValue( rowValue, columnDef, this ); } @Override public void setHorizontalAlignment( HorizontalAlignmentConstant align ) { mViewTableElement.setPropertyString( "align", align.getTextAlignString() ); } @Override public void setHTML( String html ) { AccordionTableTable.this.setHTML( getRowIndex() + 1, getCellIndex(), html ); } @Override public void setStyleAttribute( String attr, String value ) { mViewTableElement.getStyle().setProperty( attr, value != null ? value : "" ); // de-null to avoid IE error } @Override public void setStyleName( String stylename ) { if ( stylename.length() > 0 ) { UIObject.setStyleName( mViewTableElement, stylename ); } } @Override public void setText( String text ) { AccordionTableTable.this.setText( getRowIndex() + 1, getCellIndex(), text ); } @Override public void setVerticalAlignment( VerticalAlignmentConstant align ) { mViewTableElement.getStyle().setProperty( "verticalAlign", align.getVerticalAlignString() ); } @Override public void setWidget( Widget widget ) { AccordionTableTable.this.setWidget( getRowIndex() + 1, getCellIndex(), widget ); } } } } |
Commits for litesoft/trunk/Java/GWT/Client/src/org/litesoft/GWT/client/widgets/datatables/AccordionTable.java
Revision | Author | Commited | Message |
---|---|---|---|
947 Diff | GeorgeS | Fri 06 Jun, 2014 23:36:56 +0000 | Correct Spelling of package! |
942 Diff | GeorgeS | Mon 02 Jun, 2014 23:41:46 +0000 | Extracting commonfoundation |
939 Diff | GeorgeS | Mon 02 Jun, 2014 21:30:31 +0000 | Extracting commonfoundation |
801 Diff | GeorgeS | Wed 15 Aug, 2012 03:59:02 +0000 | |
720 Diff | GeorgeS | Sun 10 Jun, 2012 16:20:42 +0000 | |
712 Diff | GeorgeS | Sat 09 Jun, 2012 22:46:04 +0000 | Move PAV stuff into LiteSoft |
243 Diff | GeorgeS | Sun 05 Jun, 2011 20:29:12 +0000 | |
151 Diff | GeorgeS | Thu 17 Mar, 2011 04:16:22 +0000 | |
49 Diff | GeorgeS | Mon 12 Apr, 2010 02:59:10 +0000 | License Text |
23 | GeorgeS | Wed 24 Feb, 2010 00:34:32 +0000 |