Search in sources :

Example 1 with DivBuilder

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

the class AbstractHeaderOrFooterBuilder method renderSortableHeader.

/**
 * Render a header, including a sort icon if the column is sortable and sorted.
 *
 * @param out the builder to render into
 * @param header the header to render
 * @param context the context of the header
 * @param isSorted true if the column is sorted
 * @param isSortAscending indicated the sort order, if sorted
 */
protected final void renderSortableHeader(ElementBuilderBase<?> out, Context context, Header<?> header, boolean isSorted, boolean isSortAscending) {
    ElementBuilderBase<?> headerContainer = out;
    // Wrap the header in a sort icon if sorted.
    isSorted = isSorted && !isFooter;
    if (isSorted) {
        // Determine the position of the sort icon.
        boolean posRight = LocaleInfo.getCurrentLocale().isRTL() ? isSortIconStartOfLine : !isSortIconStartOfLine;
        // Create an outer container to hold the icon and the header.
        int iconWidth = isSortAscending ? sortAscIconWidth : sortDescIconWidth;
        int halfHeight = isSortAscending ? sortAscIconHalfHeight : sortDescIconHalfHeight;
        DivBuilder outerDiv = out.startDiv();
        StylesBuilder style = outerDiv.style().position(Position.RELATIVE).trustedProperty("zoom", "1");
        if (posRight) {
            style.paddingRight(iconWidth, Unit.PX);
        } else {
            style.paddingLeft(iconWidth, Unit.PX);
        }
        style.endStyle();
        // Add the icon.
        DivBuilder imageHolder = outerDiv.startDiv();
        style = outerDiv.style().position(Position.ABSOLUTE).top(50.0, Unit.PCT).lineHeight(0.0, Unit.PX).marginTop(-halfHeight, Unit.PX);
        if (posRight) {
            style.right(0, Unit.PX);
        } else {
            style.left(0, Unit.PX);
        }
        style.endStyle();
        imageHolder.html(getSortIcon(isSortAscending));
        imageHolder.endDiv();
        // Create the header wrapper.
        headerContainer = outerDiv.startDiv();
    }
    // Build the header.
    renderHeader(headerContainer, context, header);
    // Close the elements used for the sort icon.
    if (isSorted) {
        // headerContainer.
        headerContainer.endDiv();
        // outerDiv
        headerContainer.endDiv();
    }
}
Also used : DivBuilder(org.gwtproject.dom.builder.shared.DivBuilder) StylesBuilder(org.gwtproject.dom.builder.shared.StylesBuilder)

Example 2 with DivBuilder

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

DivBuilder (org.gwtproject.dom.builder.shared.DivBuilder)2 Context (org.gwtproject.cell.client.Cell.Context)1 StylesBuilder (org.gwtproject.dom.builder.shared.StylesBuilder)1 TableCellBuilder (org.gwtproject.dom.builder.shared.TableCellBuilder)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