Example usage for com.google.gwt.dom.builder.shared TableCellBuilder endTH

List of usage examples for com.google.gwt.dom.builder.shared TableCellBuilder endTH

Introduction

In this page you can find the example usage for com.google.gwt.dom.builder.shared TableCellBuilder endTH.

Prototype

void endTH();

Source Link

Document

End the current element.

Usage

From source file:com.bearsoft.gwt.ui.widgets.grid.builders.ThemedHeaderOrFooterBuilder.java

protected void buildNodes(List<HeaderNode<T>> aHeaders,
        Map<Column<T, ?>, ColumnSortList.ColumnSortInfo> sortedColumns) {
    // AbstractCellTable<T> table = getTable();
    List<HeaderNode<T>> children = new ArrayList<>();
    boolean isFooter = isBuildingFooter();
    // Get the common style names.
    String className = isBuildingFooter() ? ThemedGridResources.instance.cellTableStyle().cellTableFooter()
            : ThemedGridResources.instance.cellTableStyle().cellTableHeader();
    String sortableStyle = ThemedGridResources.instance.cellTableStyle().cellTableSortableHeader();
    String sortedAscStyle = ThemedGridResources.instance.cellTableStyle().cellTableSortedHeaderAscending();
    String sortedDescStyle = ThemedGridResources.instance.cellTableStyle().cellTableSortedHeaderDescending();
    TableRowBuilder tr = startRow();/*from  ww  w.  j a v a2 s  .  c  o  m*/
    // Loop through all column header nodes.
    for (int i = 0; i < aHeaders.size(); i++) {
        HeaderNode<T> headerNode = aHeaders.get(i);
        children.addAll(headerNode.getChildren());
        Header<?> headerOrFooter = headerNode.getHeader();
        Column<T, ?> column = null;
        if (headerOrFooter instanceof HasColumn<?>)
            column = ((HasColumn<T>) headerOrFooter).getColumn();
        boolean isSortable = !isFooter && column != null && column.isSortable();
        ColumnSortList.ColumnSortInfo sortedInfo = sortedColumns.get(column);
        boolean isSorted = sortedInfo != null;
        StringBuilder classesBuilder = new StringBuilder(className);
        boolean isSortAscending = isSortable && sortedInfo != null ? sortedInfo.isAscending() : false;
        if (isSortable) {
            if (classesBuilder.length() > 0) {
                classesBuilder.append(" ");
            }
            classesBuilder.append(sortableStyle);
            if (isSorted) {
                if (classesBuilder.length() > 0) {
                    classesBuilder.append(" ");
                }
                classesBuilder.append(isSortAscending ? sortedAscStyle : sortedDescStyle);
            }
        }
        // Render the header or footer.
        TableCellBuilder th = tr.startTH();
        if (headerNode.getDepthRemainder() > 0)
            th.rowSpan(headerNode.getDepthRemainder() + 1);
        if (headerNode.getLeavesCount() > 1)
            th.colSpan(headerNode.getLeavesCount());
        th.className(classesBuilder.toString());
        StylesBuilder thStyles = th.style();
        if (headerNode.getBackground() != null) {
            thStyles.trustedBackgroundColor(headerNode.getBackground().toStyled());
        }
        if (headerNode.getForeground() != null) {
            thStyles.trustedColor(headerNode.getForeground().toStyled());
        }
        if (headerNode.getFont() != null) {
            thStyles.trustedProperty("font-family", headerNode.getFont().getFamily());
            thStyles.fontSize(headerNode.getFont().getSize(), Style.Unit.PX);
            thStyles.fontStyle(headerNode.getFont().isItalic() ? FontStyle.ITALIC : FontStyle.NORMAL);
            thStyles.fontWeight(headerNode.getFont().isBold() ? FontWeight.BOLD : FontWeight.NORMAL);
        }
        if (headerOrFooter != null) {
            appendExtraStyles(headerOrFooter, classesBuilder);
            if (column != null) {
                enableColumnHandlers(th, column);
            }
            // Build the header.
            Cell.Context context = new Cell.Context(0, i, headerOrFooter.getKey());
            // Add div element with aria button role
            if (isSortable) {
                // TODO: Figure out aria-label and translation
                // of label text
                th.attribute("role", "button");
                th.tabIndex(-1);
            }
            renderSortableHeader(th, context, headerOrFooter, isSorted, isSortAscending);
        }
        th.endTH();
    }
    // End the row.
    tr.endTR();
    if (!children.isEmpty()) {
        buildNodes(children, sortedColumns);
    }
}

From source file:org.activityinfo.ui.client.component.table.InstanceTableHeaderBuilder.java

License:Open Source License

private void buildColumnRow(int row, int columnCount) {

    final TableRowBuilder tr = startRow();
    setTrWidth(tr, row);/*from ww w.  j  av  a 2  s.  c o m*/

    for (int columnIndex = 0; columnIndex < columnCount; columnIndex++) {
        final FieldColumn column = (FieldColumn) getTable().getColumn(columnIndex);

        TableCellBuilder th = tr.startTH().className(InstanceTableStyle.INSTANCE.headerHover());
        setTdWidth(th, row, columnIndex);
        enableColumnHandlers(th, column);

        Cell.Context context = new Cell.Context(row, columnIndex, null);
        renderHeader(th, context, getTable().getHeader(columnIndex));

        th.endTH();
    }
    tr.endTR();
}

From source file:org.activityinfo.ui.client.component.table.InstanceTableHeaderBuilder.java

License:Open Source License

private void buildActionRow(int row, int columnCount) {
    AbstractCellTable.Style style = getTable().getResources().style();

    TableRowBuilder tr = startRow();//  w ww.j a va2 s . c o m
    setTrWidth(tr, row);

    TableCellBuilder th = tr.startTH().colSpan(columnCount).className(style.header());
    setTdWidth(th, row, 0);

    final SafeHtmlBuilder sb = new SafeHtmlBuilder();
    sb.append(SafeHtmlUtils.fromString(table.getRootFormClass().getLabel()));
    sb.append(SafeHtmlUtils.fromTrustedString("&nbsp;"));
    for (TableHeaderAction buttonAction : table.getHeaderActions()) {
        final ButtonActionCell cell = new ButtonActionCell(buttonAction);
        cell.render(new Cell.Context(row, 0, table), "", sb);
        sb.append(SafeHtmlUtils.fromTrustedString("&nbsp;"));
    }
    th.html(sb.toSafeHtml());

    th.endTH();
    tr.endTR();
}

From source file:org.kaaproject.avro.ui.gwt.client.widget.grid.StringFilterHeaderBuilder.java

License:Apache License

@SuppressWarnings("unchecked")
@Override//from  w  w  w .jav a2  s  .  c om
protected boolean buildHeaderOrFooterImpl() {
    boolean result = super.buildHeaderOrFooterImpl();
    AbstractCellTable<T> table = getTable();
    Header<?> prevHeader = getHeader(0);
    Style style = table.getResources().style();
    StringBuilder classesBuilder = new StringBuilder(style.header());
    classesBuilder.append(" ").append(Utils.avroUiStyle.fieldWidget());

    TableRowBuilder tr = startRow();
    for (int i = 0; i < table.getColumnCount(); i++) {
        appendExtraStyles(prevHeader, classesBuilder);
        TableCellBuilder th = tr.startTH().className(classesBuilder.toString());
        Column<T, ?> column = table.getColumn(i);
        Header<?> header = null;
        if (column instanceof FiltrableStringColumn) {
            StringFilterHeader filterHeader = new StringFilterHeader(grid, (FiltrableStringColumn<T>) column,
                    new Integer(i));

            Set<String> headerEvents = filterHeader.getCell().getConsumedEvents();
            Set<String> consumedEvents = new HashSet<String>();
            if (headerEvents != null) {
                consumedEvents.addAll(headerEvents);
            }
            sinkEvents(table, consumedEvents);
            header = filterHeader;
        } else {
            header = new SafeHtmlHeader(SafeHtmlUtils.fromSafeConstant(""));
        }
        Context context = new Context(0, 0, header.getKey());
        renderHeader(th, context, header);

        th.endTH();
    }
    tr.endTR();
    return result;
}

From source file:org.roda.wui.common.client.widgets.wcag.AccessibleHeaderOrFooterBuilder.java

@Override
protected boolean buildHeaderOrFooterImpl() {
    AbstractCellTable<T> table = getTable();
    boolean isFooter = isBuildingFooter();

    // Early exit if there aren't any columns to render.
    int columnCount = table.getColumnCount();
    if (columnCount == 0) {
        // Nothing to render
        return false;
    }// ww  w  .j a v a2 s. c  o m

    // Early exit if there aren't any headers in the columns to render.
    boolean hasHeader = false;
    for (int i = 0; i < columnCount; i++) {
        if (getHeader(i) != null) {
            hasHeader = true;
            break;
        }
    }
    if (!hasHeader) {
        return false;
    }

    // Get information about the sorted column.
    ColumnSortList sortList = table.getColumnSortList();
    ColumnSortInfo sortedInfo = (sortList.size() == 0) ? null : sortList.get(0);
    Column<?, ?> sortedColumn = (sortedInfo == null) ? null : sortedInfo.getColumn();
    boolean isSortAscending = (sortedInfo == null) ? false : sortedInfo.isAscending();

    // Get the common style names.
    Style style = getTable().getResources().style();
    String className = isBuildingFooter() ? style.footer() : style.header();
    String sortableStyle = " " + style.sortableHeader();
    String sortedStyle = " "
            + (isSortAscending ? style.sortedHeaderAscending() : style.sortedHeaderDescending());

    // Setup the first column.
    Header<?> prevHeader = getHeader(0);
    Column<T, ?> column = getTable().getColumn(0);
    int prevColspan = 1;
    boolean isSortable = false;
    boolean isSorted = false;
    StringBuilder classesBuilder = new StringBuilder(className);
    classesBuilder.append(" " + (isFooter ? style.firstColumnFooter() : style.firstColumnHeader()));
    if (!isFooter && column.isSortable()) {
        isSortable = true;
        isSorted = (column == sortedColumn);
    }

    // Loop through all column headers.
    TableRowBuilder tr = startRow();
    int curColumn;
    for (curColumn = 1; curColumn < columnCount; curColumn++) {
        Header<?> header = getHeader(curColumn);

        if (header != prevHeader) {
            // The header has changed, so append the previous one.
            if (isSortable) {
                classesBuilder.append(sortableStyle);
            }
            if (isSorted) {
                classesBuilder.append(sortedStyle);
            }
            appendExtraStyles(prevHeader, classesBuilder);

            // Render the header.
            TableCellBuilder th = tr.startTH().colSpan(prevColspan).className(classesBuilder.toString());
            enableColumnHandlers(th, column);
            if (prevHeader != null) {
                // Build the header.
                Context context = new Context(0, curColumn - prevColspan, prevHeader.getKey());
                // Add div element with aria button role
                if (isSortable) {
                    // TODO: Figure out aria-label and translation of label text
                    th.attribute("role", "button");
                    th.tabIndex(-1);
                }
                updatedRenderSortableHeader(th, context, prevHeader, isSorted, isSortAscending);
            }
            th.endTH();

            // Reset the previous header.
            prevHeader = header;
            prevColspan = 1;
            classesBuilder = new StringBuilder(className);
            isSortable = false;
            isSorted = false;
        } else {
            // Increment the colspan if the headers == each other.
            prevColspan++;
        }

        // Update the sorted state.
        column = table.getColumn(curColumn);
        if (!isFooter && column.isSortable()) {
            isSortable = true;
            isSorted = (column == sortedColumn);
        }
    }

    // Append the last header.
    if (isSortable) {
        classesBuilder.append(sortableStyle);
    }
    if (isSorted) {
        classesBuilder.append(sortedStyle);
    }

    // The first and last columns could be the same column.
    classesBuilder.append(" ").append(isFooter ? style.lastColumnFooter() : style.lastColumnHeader());
    appendExtraStyles(prevHeader, classesBuilder);

    // Render the last header.
    TableCellBuilder th = tr.startTH().colSpan(prevColspan).className(classesBuilder.toString());
    enableColumnHandlers(th, column);
    if (prevHeader != null) {
        Context context = new Context(0, curColumn - prevColspan, prevHeader.getKey());
        updatedRenderSortableHeader(th, context, prevHeader, isSorted, isSortAscending);
    }
    th.endTH();

    // End the row.
    tr.endTR();

    return true;
}