Package com.google.gwt.dom.builder.shared

Examples of com.google.gwt.dom.builder.shared.DivBuilder


  public void onModuleLoad() {
    /*
     * 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);
  }
View Full Code Here


  public void onModuleLoad() {
    /*
     * 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();

    /*
     * Build the element.
     *
     * First, we set the element's id to "myId", then set its title to
     * "This is a div". Next, we set the background-color style property to
     * "red". Finally, we set some inner text to "Hello World!". When we are
     * finished, we end the div.
     *
     * When building elements, the order of methods matters. Attributes and
     * style properties must be added before setting inner html/text or
     * appending children. This is because the string implementation cannot
     * concatenate an attribute after child content has been added.
     *
     * Note that endStyle() takes the builder type that we want to return, which
     * must be the "parent" builder. endDiv() does not need the optional
     * argument because we are finished building the element.
     */
    divBuilder.id("myId").title("This is a div");
    divBuilder.style().trustedBackgroundColor("red").endStyle();
    divBuilder.text("Hello World!").endDiv();

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

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

    value = newValue;
    ValueChangeEvent.fireIfNotEqual(this, oldValue, newValue);
  }

  private ElementBuilderBase<?> build(ElementBuilderFactory factory) {
    DivBuilder builder = factory.createDivBuilder();
    builder.text(text).end();
    return builder;
  }
View Full Code Here

TOP

Related Classes of com.google.gwt.dom.builder.shared.DivBuilder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.