Search in sources :

Example 1 with TableRowBuilder

use of org.gwtproject.dom.builder.shared.TableRowBuilder in project gwtproject by treblereel.

the class AbstractCellTableTestBase method testSetHeaderBuilder.

public void testSetHeaderBuilder() {
    T table = createAbstractHasData();
    HeaderBuilder<String> headerBuilder = new AbstractHeaderOrFooterBuilder<String>(table, false) {

        @Override
        protected boolean buildHeaderOrFooterImpl() {
            TableRowBuilder tr = startRow();
            tr.startTH().text("Col 0").endTH();
            tr.startTH().text("Col 1").endTH();
            tr.startTH().text("Col 2").endTH();
            tr.endTR();
            return true;
        }
    };
    // Change the header builder.
    table.setHeaderBuilder(headerBuilder);
    assertEquals(headerBuilder, table.getHeaderBuilder());
    table.getPresenter().flush();
    // Verify the new header.
    NodeList<TableRowElement> rows = table.getTableHeadElement().getRows();
    assertEquals(1, rows.getLength());
    NodeList<TableCellElement> cells = rows.getItem(0).getCells();
    assertEquals(3, cells.getLength());
    assertEquals("Col 0", cells.getItem(0).getInnerText());
    assertEquals("Col 1", cells.getItem(1).getInnerText());
    assertEquals("Col 2", cells.getItem(2).getInnerText());
}
Also used : TableRowElement(org.gwtproject.dom.client.TableRowElement) TableRowBuilder(org.gwtproject.dom.builder.shared.TableRowBuilder) TableCellElement(org.gwtproject.dom.client.TableCellElement)

Example 2 with TableRowBuilder

use of org.gwtproject.dom.builder.shared.TableRowBuilder in project gwtproject by treblereel.

the class AbstractCellTableTestBase method testBuildTooManyEnds.

/**
 * Test that an error is thrown if the builder ends the table body element
 * instead of the table row element.
 */
public void testBuildTooManyEnds() {
    final List<Integer> builtRows = new ArrayList<Integer>();
    T table = createAbstractHasData(new TextCell());
    CellTableBuilder<String> builder = new DefaultCellTableBuilder<String>(table) {

        @Override
        public void buildRowImpl(String rowValue, int absRowIndex) {
            builtRows.add(absRowIndex);
            TableRowBuilder tr = startRow(rowValue);
            // End the tr.
            tr.endTR();
            // Accidentally end the table section.
            tr.end();
            // Try to start another row.
            try {
                startRow(rowValue);
                fail("Expected IllegalStateException: tbody is already ended");
            } catch (IllegalStateException e) {
            // Expected.
            }
        }
    };
    table.setTableBuilder(builder);
    table.setVisibleRange(0, 1);
    populateData(table);
    table.getPresenter().flush();
    assertEquals(1, builtRows.size());
    assertEquals(0, builtRows.get(0).intValue());
}
Also used : ArrayList(java.util.ArrayList) TableRowBuilder(org.gwtproject.dom.builder.shared.TableRowBuilder) TextCell(org.gwtproject.cell.client.TextCell)

Example 3 with TableRowBuilder

use of org.gwtproject.dom.builder.shared.TableRowBuilder in project gwtproject by treblereel.

the class AbstractHeaderOrFooterBuilder method startRow.

/**
 * Add a header (or footer) row to the table, below any rows previously added.
 *
 * @return the row to add
 */
protected final TableRowBuilder startRow() {
    // End any dangling rows.
    while (section.getDepth() > 1) {
        section.end();
    }
    // Verify the depth.
    if (section.getDepth() < 1) {
        throw new IllegalStateException("Cannot start a row.  Did you call TableRowBuilder.end() too many times?");
    }
    // Start the next row.
    TableRowBuilder row = section.startTR();
    row.attribute(ROW_ATTRIBUTE, rowIndex);
    rowIndex++;
    return row;
}
Also used : TableRowBuilder(org.gwtproject.dom.builder.shared.TableRowBuilder)

Example 4 with TableRowBuilder

use of org.gwtproject.dom.builder.shared.TableRowBuilder in project gwtproject by treblereel.

the class AbstractCellTableBuilder method startRow.

/**
 * Start a row and return the {@link TableRowBuilder} for this row. The row can be initialized
 * according to its corresponding value.
 *
 * @param rowValue the value for the row corresponding to the element. Can be null.
 */
public final TableRowBuilder startRow(T rowValue) {
    // End any dangling rows.
    while (tbody.getDepth() > 1) {
        tbody.end();
    }
    // Verify the depth.
    if (tbody.getDepth() < 1) {
        throw new IllegalStateException("Cannot start a row.  Did you call TableRowBuilder.end() too many times?");
    }
    // Start the next row.
    TableRowBuilder row = tbody.startTR();
    row.attribute(ROW_ATTRIBUTE, rowIndex);
    row.attribute(SUBROW_ATTRIBUTE, subrowIndex);
    addRowAttributes(row, rowValue);
    subrowIndex++;
    return row;
}
Also used : TableRowBuilder(org.gwtproject.dom.builder.shared.TableRowBuilder)

Example 5 with TableRowBuilder

use of org.gwtproject.dom.builder.shared.TableRowBuilder in project gwtproject by treblereel.

the class DefaultCellTableBuilder method buildRowImpl.

@Override
public void buildRowImpl(T rowValue, int absRowIndex) {
    // Calculate the row styles.
    SelectionModel<? super T> selectionModel = cellTable.getSelectionModel();
    boolean isSelected = (selectionModel == null || rowValue == null) ? false : selectionModel.isSelected(rowValue);
    boolean isEven = absRowIndex % 2 == 0;
    StringBuilder trClasses = new StringBuilder(isEven ? evenRowStyle : oddRowStyle);
    if (isSelected) {
        trClasses.append(selectedRowStyle);
    }
    // Add custom row styles.
    RowStyles<T> rowStyles = cellTable.getRowStyles();
    if (rowStyles != null) {
        String extraRowStyles = rowStyles.getStyleNames(rowValue, absRowIndex);
        if (extraRowStyles != null) {
            trClasses.append(" ").append(extraRowStyles);
        }
    }
    // Build the row.
    TableRowBuilder tr = startRow(rowValue);
    tr.className(trClasses.toString());
    // Build the columns.
    int columnCount = cellTable.getColumnCount();
    for (int curColumn = 0; curColumn < columnCount; curColumn++) {
        Column<T, ?> column = cellTable.getColumn(curColumn);
        // Create the cell styles.
        StringBuilder tdClasses = new StringBuilder(cellStyle);
        tdClasses.append(isEven ? evenCellStyle : oddCellStyle);
        if (curColumn == 0) {
            tdClasses.append(firstColumnStyle);
        }
        if (isSelected) {
            tdClasses.append(selectedCellStyle);
        }
        // The first and last column could be the same column.
        if (curColumn == columnCount - 1) {
            tdClasses.append(lastColumnStyle);
        }
        // Add class names specific to the cell.
        Context context = new Context(absRowIndex, curColumn, cellTable.getValueKey(rowValue));
        String cellStyles = column.getCellStyleNames(context, rowValue);
        if (cellStyles != null) {
            tdClasses.append(" " + cellStyles);
        }
        // Build the cell.
        HorizontalAlignmentConstant hAlign = column.getHorizontalAlignment();
        VerticalAlignmentConstant vAlign = column.getVerticalAlignment();
        TableCellBuilder td = tr.startTD();
        td.className(tdClasses.toString());
        if (hAlign != null) {
            td.align(hAlign.getTextAlignString());
        }
        if (vAlign != null) {
            td.vAlign(vAlign.getVerticalAlignString());
        }
        addCellAttributes(td);
        // Add the inner div.
        DivBuilder div = td.startDiv();
        div.style().outlineStyle(OutlineStyle.NONE).endStyle();
        // Render the cell into the div.
        renderCell(div, context, column, rowValue);
        // End the cell.
        div.endDiv();
        td.endTD();
    }
    // End the row.
    tr.endTR();
}
Also used : Context(org.gwtproject.cell.client.Cell.Context) VerticalAlignmentConstant(org.gwtproject.user.client.ui.HasVerticalAlignment.VerticalAlignmentConstant) DivBuilder(org.gwtproject.dom.builder.shared.DivBuilder) TableRowBuilder(org.gwtproject.dom.builder.shared.TableRowBuilder) TableCellBuilder(org.gwtproject.dom.builder.shared.TableCellBuilder) HorizontalAlignmentConstant(org.gwtproject.user.client.ui.HasHorizontalAlignment.HorizontalAlignmentConstant)

Aggregations

TableRowBuilder (org.gwtproject.dom.builder.shared.TableRowBuilder)9 TextCell (org.gwtproject.cell.client.TextCell)3 TableCellElement (org.gwtproject.dom.client.TableCellElement)2 TableRowElement (org.gwtproject.dom.client.TableRowElement)2 TableSectionElement (org.gwtproject.dom.client.TableSectionElement)2 ArrayList (java.util.ArrayList)1 Context (org.gwtproject.cell.client.Cell.Context)1 DivBuilder (org.gwtproject.dom.builder.shared.DivBuilder)1 TableCellBuilder (org.gwtproject.dom.builder.shared.TableCellBuilder)1 HorizontalAlignmentConstant (org.gwtproject.user.client.ui.HasHorizontalAlignment.HorizontalAlignmentConstant)1 VerticalAlignmentConstant (org.gwtproject.user.client.ui.HasVerticalAlignment.VerticalAlignmentConstant)1