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

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

Introduction

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

Prototype

void endStyle();

Source Link

Document

End the current style attribute.

Usage

From source file:com.google.gwt.examples.dom.builder.ElementBuilderFactoryNonChainingExample.java

License:Apache License

@Override
public void onModuleLoad() {
    /*/*from   w  ww . j ava 2  s.  c o  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);
}

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

protected final void updatedRenderSortableHeader(ElementBuilderBase<?> out, Context context, Header<?> header,
        boolean isSorted, boolean isSortAscending) {
    ElementBuilderBase<?> headerContainer = out;

    // Wrap the header in a sort icon if sorted.
    boolean isSortedAndNotFooter = isSorted && !footer;
    if (isSortedAndNotFooter) {
        // 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 ? getTable().getResources().sortAscending().getWidth() + 6
                : getTable().getResources().sortDescending().getWidth() + 6;
        int halfHeight = isSortAscending
                ? (int) Math.round(getTable().getResources().sortAscending().getHeight() / 2.0)
                : (int) Math.round(getTable().getResources().sortDescending().getHeight() / 2.0);
        DivBuilder outerDiv = out.startDiv();
        StylesBuilder style = outerDiv.style().position(Position.RELATIVE).trustedProperty("zoom", "1");
        if (posRight) {
            style.paddingRight(iconWidth, Unit.PX);
        } else {//from   w  w  w  .j  a  va  2 s .c o m
            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(getSortingIcon(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 (isSortedAndNotFooter) {
        headerContainer.endDiv(); // headerContainer.
        headerContainer.endDiv(); // outerDiv
    }
}