List of usage examples for com.google.gwt.dom.builder.shared ElementBuilderFactory get
public static ElementBuilderFactory get()
From source file:com.google.gwt.examples.dom.builder.ElementBuilderFactoryChainingExample.java
License:Apache License
@Override public void onModuleLoad() { /*/* www . j av a2 s . com*/ * 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); }
From source file:com.google.gwt.examples.dom.builder.ElementBuilderFactoryNonChainingExample.java
License:Apache License
@Override public void onModuleLoad() { /*/* w ww .j a v a 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); }