Search in sources :

Example 1 with TableCellBuilder

use of org.gwtproject.dom.builder.shared.TableCellBuilder 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)

Example 2 with TableCellBuilder

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

the class DefaultHeaderOrFooterBuilder method buildTableHeader.

/**
 * Build the table header for the column.
 */
private void buildTableHeader(TableRowBuilder tr, Column<T, ?> column, Header<?> header, boolean isSortable, boolean isSorted, boolean isSortAscending, StringBuilder classesBuilder, String sortableStyle, String sortedStyle, int prevColspan, int curColumn) {
    if (isSortable) {
        classesBuilder.append(sortableStyle);
    }
    if (isSorted) {
        classesBuilder.append(sortedStyle);
    }
    appendExtraStyles(header, classesBuilder);
    TableCellBuilder th = tr.startTH().colSpan(prevColspan).className(classesBuilder.toString());
    enableColumnHandlers(th, column);
    if (header != null) {
        // Build the header.
        Context context = new Context(0, curColumn - prevColspan, header.getKey());
        if (isSortable) {
            // TODO: Figure out aria-label and translation of label text
            th.attribute("role", "button");
            th.tabIndex(-1);
        }
        renderSortableHeader(th, context, header, isSorted, isSortAscending);
    }
    th.endTH();
}
Also used : Context(org.gwtproject.cell.client.Cell.Context) TableCellBuilder(org.gwtproject.dom.builder.shared.TableCellBuilder)

Aggregations

Context (org.gwtproject.cell.client.Cell.Context)2 TableCellBuilder (org.gwtproject.dom.builder.shared.TableCellBuilder)2 DivBuilder (org.gwtproject.dom.builder.shared.DivBuilder)1 TableRowBuilder (org.gwtproject.dom.builder.shared.TableRowBuilder)1 HorizontalAlignmentConstant (org.gwtproject.user.client.ui.HasHorizontalAlignment.HorizontalAlignmentConstant)1 VerticalAlignmentConstant (org.gwtproject.user.client.ui.HasVerticalAlignment.VerticalAlignmentConstant)1