gwt /
gwt /
b6482ed5bdd2103ca81ad98bfc63f01b23a27baa Adding all supported element builders to the ElementBuilder API. This is a follow-on change for r10412, which introduced the core ElementBuilder libraries.
For each Element type, we introduce five new files:
1. The builder interface (ex. AnchorBuilder)
2. The HTML based implementation (ex. HtmlAnchorBuilder)
3. The DOM based implementation (ex. DomAnchorBuilder)
4. The JRE test that tests the HTML based implementation (ex. HtmlAnchorBuilderTest)
5. The GWT test that tests both the HTML and DOM based implementations (ex. GwtAnchorBuilderTest)
I generated the files using a script that looks for setters in the Element JSO and converts them to builder methods by dropping the "set" prefix from the setter. Setter methods that take booleans do not take an argument in the builder because you cannot unset the attribute. For example, InputElement#setDisabled(boolean) became InputBuilder#disabled(), and adds the "disabled" attribute to the element. The script generated all five files mentioned above for each Element JSO. I then manually reviewed them and made some modifications for exceptions, such as HtmlStylesBuilder.cssSrc(String), which actually inlines the text instead of setting an attribute. Some Elements do not support setting inner text of html (ex. StyleBuilder), so they throw an UnsupportedOperationException. Other elements forbid a closing tag (ex. BRBuilder and HRBuilder), so they also throw UnsupportedOperationExceptions if you try to set inner text or html.
There are some changes to existing files. The ElementBuilderFactory classes now have createXXX methods for each element (ex. createAnchorElement()), and ElementBuilderBase has an associated startXXX method (ex. startAnchor()). All of the Element JSOs have package protected static TAG names (ex. AnchorElement.TAG). We use the tags in the HTML based implementation, so I made all of the static Strings public (a few of the newer ones were already public). In some cases, there is one builder class that represents multiple element types. For example, HeadingBuilder builds "h1", "h2", "h3"... For these, we have the one HeadingBuilder (just like we have one HeadingElement), but we have startH1(), startH2(), startH3() method for convenience.
We now handle elements that forbid end tags by self closing the start tag ("<area />" versus "<area></area>"). Elements that forbid the end tag throw an UnsupportedOperationException if you try to set inner html/text, or append a child element. Some builders also override text(String)/html(String) if they forbid text or html, but still allow en end tag.
Test cases have also been simplified. Each ElementBuilder used to have three tests: one JRE test, one GWT test for the HTML implementation, and one GWT test for the DOM version. In addition, the latter two had to override two package protected methods. Now, there are only two versions: the JRE version and the GWT version. The GWT version only overrides getModuleName(), and the base test class iterates over both ElementBuilderFactory implementations. This makes it easier to add new builders and reduces the number of files significantly.
Review at http://gwt-code-reviews.appspot.com/1463812
Review by: rchandia@google.com
git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@10433 8db76d5a-ed1c-0410-87a9-c151d255dfc7
311 files changed