Example usage for com.google.gwt.dom.builder.shared StylesBuilder trustedBackgroundColor

List of usage examples for com.google.gwt.dom.builder.shared StylesBuilder trustedBackgroundColor

Introduction

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

Prototype

StylesBuilder trustedBackgroundColor(String value);

Source Link

Document

Sets the "background-color" style property to the specified color string.

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 w  w  w .  j  av  a 2 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:com.google.gwt.examples.dom.builder.ElementBuilderFactoryNonChainingExample.java

License:Apache License

@Override
public void onModuleLoad() {
    /*/*www .  j  a  v  a  2s  .co m*/
     * Create a builder for the outermost element. The initial state of the
     * builder is a started element ready for attributes (eg. "<div").
     */
    DivBuilder divBuilder = ElementBuilderFactory.get().createDivBuilder();

    // Add attributes to the div.
    divBuilder.id("myId");
    divBuilder.title("This is a div");

    // Add style properties to the div.
    StylesBuilder divStyle = divBuilder.style();
    divStyle.trustedBackgroundColor("red");
    divStyle.endStyle();

    // Append a child select element to the div.
    SelectBuilder selectBuilder = divBuilder.startSelect();

    // Append three options to the select element.
    for (int i = 0; i < 3; i++) {
        OptionBuilder optionBuilder = selectBuilder.startOption();
        optionBuilder.value("value" + i);
        optionBuilder.text("Option " + i);
        optionBuilder.endOption();
    }

    /*
     * End the select and div elements. Note that ending the remaining elements
     * before calling asElement() below is optional, but a good practice. If we
     * did not call endOption() above, we would append each option element to
     * the preceeding option element, which is not what we want.
     * 
     * In general, you must pay close attention to ensure that you close
     * elements correctly.
     */
    selectBuilder.endSelect();
    divBuilder.endDiv();

    // Get the element out of the builder.
    Element div = divBuilder.finish();

    // Attach the element to the page.
    Document.get().getBody().appendChild(div);
}