Revision: 8443
Author: gwt.mirror...@gmail.com
Date: Thu Jul 29 11:09:15 2010
Log: Re-introduces UiBinder parser for AbsolutePanel, now backward
compatible. Restores work introduced at r8430, rolled back at r8432.

Patch by konstantin.scheg...@gmail.com
Review by rj...@google.com

http://gwt-code-reviews.appspot.com/715802

Review by: robertvaw...@google.com
http://code.google.com/p/google-web-toolkit/source/detail?r=8443

Added:
/trunk/user/src/com/google/gwt/uibinder/elementparsers/AbsolutePanelParser.java /trunk/user/test/com/google/gwt/uibinder/elementparsers/AbsolutePanelParserTest.java
Modified:
 /trunk/user/src/com/google/gwt/uibinder/rebind/UiBinderWriter.java
 /trunk/user/src/com/google/gwt/user/client/ui/AbsolutePanel.java
 /trunk/user/src/com/google/gwt/user/client/ui/LayoutPanel.java
 /trunk/user/test/com/google/gwt/uibinder/UiBinderJreSuite.java
 /trunk/user/test/com/google/gwt/uibinder/rebind/DesignTimeUtilsTest.java
 /trunk/user/test/com/google/gwt/uibinder/test/UiJavaResources.java
 /trunk/user/test/com/google/gwt/uibinder/test/client/UiBinderTest.java
 /trunk/user/test/com/google/gwt/uibinder/test/client/WidgetBasedUi.java
 /trunk/user/test/com/google/gwt/uibinder/test/client/WidgetBasedUi.ui.xml

=======================================
--- /dev/null
+++ /trunk/user/src/com/google/gwt/uibinder/elementparsers/AbsolutePanelParser.java Thu Jul 29 11:09:15 2010
@@ -0,0 +1,71 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.google.gwt.uibinder.elementparsers;
+
+import com.google.gwt.core.ext.UnableToCompleteException;
+import com.google.gwt.core.ext.typeinfo.JClassType;
+import com.google.gwt.uibinder.rebind.UiBinderWriter;
+import com.google.gwt.uibinder.rebind.XMLElement;
+
+/**
+ * Parses {...@link com.google.gwt.user.client.ui.AbsolutePanel AbsolutePanel}
+ * widgets.
+ */
+public class AbsolutePanelParser implements ElementParser {
+
+  private static final String AT = "at";
+
+  public void parse(XMLElement elem, String fieldName, JClassType type,
+      UiBinderWriter writer) throws UnableToCompleteException {
+
+    // Parse children.
+    for (XMLElement child : elem.consumeChildElements()) {
+      // Parse position element.
+      if (isPositionElement(elem, child)) {
+        // Parse position.
+        String left = child.consumeRequiredIntAttribute("left");
+        String top = child.consumeRequiredIntAttribute("top");
+        // Add child widget.
+        XMLElement widgetElem = child.consumeSingleChildElement();
+        String widgetFieldName = writer.parseElementToField(widgetElem);
+        writer.addStatement("%1$s.add(%2$s, %3$s, %4$s);", fieldName,
+            widgetFieldName, left, top);
+        continue;
+      }
+
+      // Parse Widget.
+      if (writer.isWidgetElement(child)) {
+        String widgetFieldName = writer.parseElementToField(child);
+        writer.addStatement("%1$s.add(%2$s);", fieldName, widgetFieldName);
+        continue;
+      }
+
+      // die
+      writer.die(child, "Expecting only <%s:%s> or widget children in %s",
+          elem.getPrefix(), AT, elem);
+    }
+  }
+
+  private boolean isPositionElement(XMLElement parent, XMLElement child) {
+    if (!parent.getNamespaceUri().equals(child.getNamespaceUri())) {
+      return false;
+    }
+    if (!AT.equals(child.getLocalName())) {
+      return false;
+    }
+    return true;
+  }
+}
=======================================
--- /dev/null
+++ /trunk/user/test/com/google/gwt/uibinder/elementparsers/AbsolutePanelParserTest.java Thu Jul 29 11:09:15 2010
@@ -0,0 +1,118 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.google.gwt.uibinder.elementparsers;
+
+import com.google.gwt.core.ext.UnableToCompleteException;
+
+import junit.framework.TestCase;
+
+import java.util.Iterator;
+
+/**
+ * Test for {...@link AbsolutePanelParser}.
+ */
+public class AbsolutePanelParserTest extends TestCase {
+
+ private static final String PARSED_TYPE = "com.google.gwt.user.client.ui.AbsolutePanel";
+
+  private ElementParserTester tester;
+
+  @Override
+  public void setUp() throws Exception {
+    super.setUp();
+ tester = new ElementParserTester(PARSED_TYPE, new AbsolutePanelParser());
+  }
+
+  public void testBadChild() throws Exception {
+    checkBadLine("<span/>", "Expecting only <g:at> or widget children");
+  }
+
+  public void testBadPosition_leftNo() throws Exception {
+    checkBadPosition("top='0'", "Missing required attribute \"left\"");
+  }
+
+  public void testBadPosition_left() throws Exception {
+ checkBadPosition("left='bad' top='0'", "Cannot parse attribute \"left\"");
+  }
+
+  public void testBadPosition_topNo() throws Exception {
+    checkBadPosition("left='0'", "Missing required attribute \"top\"");
+  }
+
+  public void testBadPosition_top() throws Exception {
+ checkBadPosition("left='0' top='bad'", "Cannot parse attribute \"top\"");
+  }
+
+  public void testBad_noWidget() throws Exception {
+    checkBadLine("<g:at left='1' top='2'/>",
+        "Element must have a single child element");
+  }
+
+  public void testBad_moreThanOneWidget() throws Exception {
+    checkBadLine("<g:at left='1' top='2'>"
+        + "<g:Button id='1'/><g:Button id='2'/></g:at>",
+        "Element may only contain a single child element");
+  }
+
+  private void checkBadLine(String badLine, String expectedDied)
+      throws Exception {
+    StringBuffer b = new StringBuffer();
+    b.append("<g:AbsolutePanel>");
+    b.append("  " + badLine);
+    b.append("</g:AbsolutePanel>");
+
+    try {
+      tester.parse(b.toString());
+      fail();
+    } catch (UnableToCompleteException e) {
+      String died = tester.logger.died;
+      assertTrue(died, died.contains(expectedDied));
+    }
+  }
+
+ private void checkBadPosition(String positionAttributes, String expectedDied)
+      throws Exception {
+    String badLine = "<g:at " + positionAttributes + "><g:Button/></g:at>";
+    checkBadLine(badLine, expectedDied);
+  }
+
+  public void testGood() throws Exception {
+    StringBuffer b = new StringBuffer();
+    b.append("<g:AbsolutePanel>");
+    b.append("  <g:at left='1' top='2'>");
+    b.append("    <g:Button/>");
+    b.append("  </g:at>");
+    b.append("  <g:TextBox/>");
+    b.append("  <g:at left='10' top='20'>");
+    b.append("    <g:Label/>");
+    b.append("  </g:at>");
+    b.append("</g:AbsolutePanel>");
+
+    tester.parse(b.toString());
+
+    assertStatements("fieldName.add(<g:Button>, 1, 2);",
+ "fieldName.add(<g:TextBox>);", "fieldName.add(<g:Label>, 10, 20);");
+  }
+
+  private void assertStatements(String... expected) {
+    Iterator<String> i = tester.writer.statements.iterator();
+    for (String e : expected) {
+      assertEquals(e, i.next());
+    }
+    assertFalse(i.hasNext());
+    assertNull(tester.logger.died);
+  }
+}
=======================================
--- /trunk/user/src/com/google/gwt/uibinder/rebind/UiBinderWriter.java Wed Jul 28 13:10:14 2010 +++ /trunk/user/src/com/google/gwt/uibinder/rebind/UiBinderWriter.java Thu Jul 29 11:09:15 2010
@@ -974,6 +974,7 @@
     addWidgetParser("HasHTML");
     addWidgetParser("HasWidgets");
     addWidgetParser("HTMLPanel");
+    addWidgetParser("AbsolutePanel");
     addWidgetParser("DockPanel");
     addWidgetParser("StackPanel");
     addWidgetParser("DisclosurePanel");
=======================================
--- /trunk/user/src/com/google/gwt/user/client/ui/AbsolutePanel.java Wed Jul 28 13:10:14 2010 +++ /trunk/user/src/com/google/gwt/user/client/ui/AbsolutePanel.java Thu Jul 29 11:09:15 2010
@@ -33,6 +33,26 @@
* "owns" the positioning of the widget. Any existing positioning attributes on
  * the widget may be modified by the panel.
  * </p>
+ *
+ * <h3>Use in UiBinder Templates</h3>
+ * <p>
+ * AbsolutePanel elements in {...@link com.google.gwt.uibinder.client.UiBinder
+ * UiBinder} templates lay out their children with absolute position, using
+ * &lt;g:at> elements. Each at element should have <code>left</code> and
+ * <code>top</code> attributes in pixels. They also can contain
+ * widget children directly, with no position specified.
+ *
+ * <p>
+ * For example:
+ *
+ * <pre>
+ * &lt;g:AbsolutePanel>
+ *   &lt;g:at left='10' top='20'>
+ *     &lt;g:Label>Lorem ipsum...&lt;/g:Label>
+ *   &lt;/g:at>
+ *   &lt;g:Label>...dolores est.&lt;/g:Label>
+ * &lt;/g:AbsolutePanel>
+ * </pre>
  */
 public class AbsolutePanel extends ComplexPanel implements InsertPanel {

@@ -179,7 +199,7 @@

   protected void setWidgetPositionImpl(Widget w, int left, int top) {
     Element h = w.getElement();
-    if ((left == -1) && (top == -1)) {
+    if (left == -1 && top == -1) {
       changeToStaticPositioning(h);
     } else {
       DOM.setStyleAttribute(h, "position", "absolute");
=======================================
--- /trunk/user/src/com/google/gwt/user/client/ui/LayoutPanel.java Wed Jul 28 13:10:14 2010 +++ /trunk/user/src/com/google/gwt/user/client/ui/LayoutPanel.java Thu Jul 29 11:09:15 2010
@@ -50,7 +50,7 @@
  *
  * <p>
* Precisely zero or two constraints are required for each axis (horizontal and - * vertial). Specifying no constraints implies that the child should fill that + * vertical). Specifying no constraints implies that the child should fill that
  * axis completely.
  *
  * <p>
=======================================
--- /trunk/user/test/com/google/gwt/uibinder/UiBinderJreSuite.java Wed Jul 28 13:10:14 2010 +++ /trunk/user/test/com/google/gwt/uibinder/UiBinderJreSuite.java Thu Jul 29 11:09:15 2010
@@ -25,6 +25,7 @@
 import com.google.gwt.uibinder.attributeparsers.StringAttributeParserTest;
import com.google.gwt.uibinder.attributeparsers.TextAlignConstantParserTest; import com.google.gwt.uibinder.attributeparsers.VerticalAlignmentConstantParserTest;
+import com.google.gwt.uibinder.elementparsers.AbsolutePanelParserTest;
 import com.google.gwt.uibinder.elementparsers.DialogBoxParserTest;
 import com.google.gwt.uibinder.elementparsers.DockLayoutPanelParserTest;
 import com.google.gwt.uibinder.elementparsers.GridParserTest;
@@ -81,6 +82,7 @@
     suite.addTestSuite(TextAlignConstantParserTest.class);

     // elementparsers
+    suite.addTestSuite(AbsolutePanelParserTest.class);
     suite.addTestSuite(DialogBoxParserTest.class);
     suite.addTestSuite(DockLayoutPanelParserTest.class);
     suite.addTestSuite(GridParserTest.class);
=======================================
--- /trunk/user/test/com/google/gwt/uibinder/rebind/DesignTimeUtilsTest.java Wed Jul 28 13:10:14 2010 +++ /trunk/user/test/com/google/gwt/uibinder/rebind/DesignTimeUtilsTest.java Thu Jul 29 11:09:15 2010
@@ -38,11 +38,6 @@
   private final DesignTimeUtils stub = DesignTimeUtilsStub.EMPTY;
   private final DesignTimeUtilsImpl impl = new DesignTimeUtilsImpl();

- ////////////////////////////////////////////////////////////////////////////
-  //
-  // addDeclarations()
-  //
- ///////////////////////////////////////////////////////////////////////////
   /**
    * Test for {...@link DesignTimeUtils#addDeclarations(IndentedWriter)}.
    */
@@ -76,11 +71,6 @@
     assertTrue(subString, content.contains(subString));
   }

- ////////////////////////////////////////////////////////////////////////////
-  //
-  // getImplName()
-  //
- ///////////////////////////////////////////////////////////////////////////
   /**
    * Test for {...@link DesignTimeUtils#getImplName(String)}.
    */
@@ -105,11 +95,6 @@
     assertTrue(Math.abs(delta) < 1000 * 3600);
   }

- ////////////////////////////////////////////////////////////////////////////
-  //
-  // Path
-  //
- ///////////////////////////////////////////////////////////////////////////
   /**
    * Test for {...@link DesignTimeUtils#getPath(Element)} and related methods.
    */
@@ -137,11 +122,6 @@
     assertEquals("0/1/0", impl.getPath(subSecond));
   }

- ////////////////////////////////////////////////////////////////////////////
-  //
-  // getTemplateContent()
-  //
- ///////////////////////////////////////////////////////////////////////////
   /**
    * Test for {...@link DesignTimeUtils#getTemplateContent(String)}.
    */
@@ -165,11 +145,6 @@
     }
   }

- ////////////////////////////////////////////////////////////////////////////
-  //
-  // handleUIObject()
-  //
- ///////////////////////////////////////////////////////////////////////////
   /**
    * Test for
* {...@link DesignTimeUtils#handleUIObject(IUiBinderWriterStatements, XMLElement, String)}
@@ -209,11 +184,6 @@
         statements.get(0));
   }

- ////////////////////////////////////////////////////////////////////////////
-  //
-  // putAttribute(String)
-  //
- ///////////////////////////////////////////////////////////////////////////
   /**
* Test for {...@link DesignTimeUtils#putAttribute(XMLElement, String, String)}
    * and {...@link DesignTimeUtils#writeAttributes(Statements)}.
@@ -257,11 +227,6 @@
     return statements;
   }

- ////////////////////////////////////////////////////////////////////////////
-  //
-  // putAttribute(String[])
-  //
- ///////////////////////////////////////////////////////////////////////////
   /**
* Test for {...@link DesignTimeUtils#putAttribute(XMLElement, String, String[])}
    * .
@@ -316,12 +281,6 @@
     }
     return statements;
   }
-
- ////////////////////////////////////////////////////////////////////////////
-  //
-  // Utilities
-  //
- ///////////////////////////////////////////////////////////////////////////

   /**
    * @return the only child {...@link Element} with given tag name.
@@ -340,11 +299,6 @@
     return new XMLElement(elem, null, null, null, null, designTime, null);
   }

- ////////////////////////////////////////////////////////////////////////////
-  //
-  // WriterStatements
-  //
- ///////////////////////////////////////////////////////////////////////////
   /**
* Implementation of {...@link IUiBinderWriterStatements} for simple statements.
    */
=======================================
--- /trunk/user/test/com/google/gwt/uibinder/test/UiJavaResources.java Wed Jul 28 13:10:14 2010 +++ /trunk/user/test/com/google/gwt/uibinder/test/UiJavaResources.java Thu Jul 29 11:09:15 2010
@@ -29,6 +29,17 @@
  */
 public class UiJavaResources {

+ public static final MockJavaResource ABSOLUTE_PANEL = new MockJavaResource(
+      "com.google.gwt.user.client.ui.AbsolutePanel") {
+    @Override
+    protected CharSequence getContent() {
+      StringBuffer code = new StringBuffer();
+      code.append("package com.google.gwt.user.client.ui;\n");
+      code.append("public class AbsolutePanel extends Widget {\n");
+      code.append("}\n");
+      return code;
+    }
+  };
   public static final MockJavaResource BUTTON = new MockJavaResource(
       "com.google.gwt.user.client.ui.Button") {
     @Override
@@ -107,9 +118,9 @@
     }
   };
   public static final MockJavaResource GRID = new MockJavaResource(
-    "com.google.gwt.user.client.ui.Grid") {
-  @Override
-  protected CharSequence getContent() {
+      "com.google.gwt.user.client.ui.Grid") {
+    @Override
+    protected CharSequence getContent() {
       StringBuffer code = new StringBuffer();
       code.append("package com.google.gwt.user.client.ui;\n");
       code.append("public class Grid extends Widget {\n");
@@ -382,6 +393,7 @@
   public static Set<Resource> getUiResources() {
     Set<Resource> rtn = new HashSet<Resource>(
         Arrays.asList(JavaResourceBase.getStandardResources()));
+    rtn.add(ABSOLUTE_PANEL);
     rtn.add(BUTTON);
     rtn.add(CLICK_EVENT);
     rtn.add(CLICK_HANDLER);
=======================================
--- /trunk/user/test/com/google/gwt/uibinder/test/client/UiBinderTest.java Wed Jul 28 13:10:14 2010 +++ /trunk/user/test/com/google/gwt/uibinder/test/client/UiBinderTest.java Thu Jul 29 11:09:15 2010
@@ -26,6 +26,7 @@
 import com.google.gwt.resources.client.CssResource.NotStrict;
 import com.google.gwt.uibinder.test.client.EnumeratedLabel.Suffix;
 import com.google.gwt.user.client.DOM;
+import com.google.gwt.user.client.ui.AbsolutePanel;
 import com.google.gwt.user.client.ui.Button;
 import com.google.gwt.user.client.ui.DisclosurePanel;
 import com.google.gwt.user.client.ui.HTML;
@@ -65,12 +66,12 @@
     assertEquals("th", domUi.th1.getTagName().toLowerCase());
     assertEquals("th", domUi.th2.getTagName().toLowerCase());
   }
-
+
   public void testTableWithExplicitTbody() {
     assertEquals("tbody", domUi.tbody.getTagName().toLowerCase());
     assertEquals("th", domUi.th4.getTagName().toLowerCase());
   }
-
+
   public void testAutoboxingFieldRef() {
     FakeBundle fakeBundle = new FakeBundle();

@@ -84,7 +85,8 @@

     assertEquals(new Integer((int) fakeBundle.aDouble()),
         widgetUi.mismatchPrimitiveIntoObject.getObjectInteger());
- assertEquals((int) fakeBundle.aDouble(), widgetUi.allMismatchPrimitive.getRawInt());
+    assertEquals((int) fakeBundle.aDouble(),
+        widgetUi.allMismatchPrimitive.getRawInt());

     assertEquals(new Boolean(fakeBundle.aBoolean()),
         widgetUi.primitiveBooleanIntoObject.getObjectBoolean());
@@ -92,26 +94,28 @@
         widgetUi.objectBooleanIntoPrimitive.getRawBoolean());
     assertEquals(fakeBundle.aBooleanObject(),
         widgetUi.allObjectBoolean.getObjectBoolean());
- assertEquals(fakeBundle.aBoolean(), widgetUi.allPrimitiveBoolean.getRawBoolean());
+    assertEquals(fakeBundle.aBoolean(),
+        widgetUi.allPrimitiveBoolean.getRawBoolean());
   }

   public void testAccessToNonStandardElement() {
     Element elm = widgetUi.nonStandardElement;
     assertEquals("I", elm.getTagName());
   }
-
+
   public void testAddStyleNamesAndDebugId() {
     Label l = widgetUi.lblDebugId;
     assertEquals("gwt-debug-joe", l.getElement().getId());

     assertEquals("styleName", l.getStylePrimaryName());
-
+
WidgetBasedUiExternalResources resources = GWT.create(WidgetBasedUiExternalResources.class);
     assertTrue(l.getStyleName().contains("newStyle"));
     assertTrue(l.getStyleName().contains("anotherStyle"));
     assertTrue(l.getStyleName().contains("styleName-dependentStyle"));
assertTrue(l.getStyleName().contains("styleName-anotherDependentStyle")); - assertTrue(l.getStyleName().contains("styleName-" + resources.style().prettyText()));
+    assertTrue(l.getStyleName().contains(
+        "styleName-" + resources.style().prettyText()));
   }

   // TODO(rjrjr) The direction stuff in these tests really belongs in
@@ -131,7 +135,8 @@
     assertEquals(getCenter(), widgetUi.bundledLabel.getParent());
assertEquals(new FakeBundle().helloText(), widgetUi.bundledLabel.getText()); WidgetBasedUiExternalResources resources = GWT.create(WidgetBasedUiExternalResources.class); - assertEquals(resources.style().prettyText(), widgetUi.bundledLabel.getStyleName());
+    assertEquals(resources.style().prettyText(),
+        widgetUi.bundledLabel.getStyleName());

     Element pretty = DOM.getElementById("prettyPara");
     assertEquals(resources.style().prettyText(), pretty.getClassName());
@@ -141,7 +146,7 @@
     foo.setPojo(pojo);
     assertEquals(foo.getText(), widgetUi.theFoo.getText());
   }
-
+
   public void testBundleLegacyBeansText() {
     assertEquals(widgetUi.legacyValuesForBeans.helloText(),
         widgetUi.bundledLabelLegacy.getText());
@@ -162,7 +167,8 @@
     // TODO(rjrjr) More of a test of HTMLPanelParser

     Widget center = getCenter();
- assertEquals(com.google.gwt.user.client.ui.DockPanel.CENTER, root.getWidgetDirection(center));
+    assertEquals(com.google.gwt.user.client.ui.DockPanel.CENTER,
+        root.getWidgetDirection(center));
     assertEquals(HTMLPanel.class, center.getClass());
     String html = center.getElement().getInnerHTML();
     assertTrue(html.contains("main area"));
@@ -182,11 +188,11 @@
WidgetBasedUiExternalResources resources = GWT.create(WidgetBasedUiExternalResources.class); assertEquals(resources.style().tmText(), widgetUi.tmElement.getClassName());
   }
-
+
   public void testCustomButtonBody() {
     assertEquals("Hi mom", widgetUi.toggle.getText());
   }
-
+
   public void testCustomDialogBox() {
     assertEquals("Custom dialog am I", widgetUi.fooDialog.getText());
     Widget body = widgetUi.fooDialog.iterator().next();
@@ -235,16 +241,18 @@
assertEquals("They might show up in body text that has been marked for "
         + "translation: funny characters \\ \" \" ' ' & < > > { }", t);
   }
-
+
   public void testEmptyAttributesOkay() {
     assertEquals("", widgetUi.styleLess.getStyleName());
   }

   public void testMixOfWidgetsAndElementsInUiMsg() {
- assertEquals("single translatable message", widgetUi.mixedMessageWidget.getText()); - assertEquals("exciting and subtle", widgetUi.mixedMessageSpan.getInnerText());
-  }
-
+    assertEquals("single translatable message",
+        widgetUi.mixedMessageWidget.getText());
+    assertEquals("exciting and subtle",
+        widgetUi.mixedMessageSpan.getInnerText());
+  }
+
   public void testEnums() {
     Suffix expected = EnumeratedLabel.Suffix.tail;
     assertTrue("Should end with suffix \"" + expected + "\"",
@@ -261,7 +269,7 @@
         widgetUi.pushButton.getUpHoveringFace().getHTML().toLowerCase());
     // Can't test the images at all :-P
   }
-
+
   public void testProtectedDomTextMessageWithFunnyChars() {
     String t = widgetUi.funnyCharsProtectedMessageParagraph.getInnerText();
     assertEquals("Don't forget about protected untranslatable blocks: "
@@ -293,14 +301,14 @@
   public void testFieldInPlaceholderedElement() {
     assertEquals("named portions", widgetUi.spanInMsg.getInnerText());
   }
-
+
   public void testGrid() {
     assertTrue(widgetUi.fooGrid.getWidget(0, 0) instanceof Label);
     assertTrue(widgetUi.fooGrid.getWidget(0, 1) instanceof Button);
     assertEquals(2, widgetUi.fooGrid.getColumnCount());
     assertEquals(1, widgetUi.fooGrid.getRowCount());
   }
-
+
   public void testListBox() {
     assertEquals(2, widgetUi.fooListBox.getItemCount());
     assertEquals("bar", widgetUi.fooListBox.getItemText(0));
@@ -369,7 +377,8 @@
   @SuppressWarnings("deprecation")
   public void testNorth() {
     Widget north = root.getWidget(0);
- assertEquals(com.google.gwt.user.client.ui.DockPanel.NORTH, root.getWidgetDirection(north));
+    assertEquals(com.google.gwt.user.client.ui.DockPanel.NORTH,
+        root.getWidgetDirection(north));
     assertEquals(HTML.class, north.getClass());
     assertTrue(((HTML) north).getHTML().contains("Title area"));
   }
@@ -421,6 +430,38 @@
     assertNotNull("Widget exists", w);
     assertEquals("Panel contains widget", w, p.getContent());
   }
+
+  public void testAbsolutePanel() {
+    AbsolutePanel p = widgetUi.myAbsolutePanel;
+    assertNotNull("Panel exists", p);
+
+ assertEquals("Panel contains exactly 3 widgets", 3, p.getWidgetCount());
+    assertEquals("Panel contains expected itemA",
+        widgetUi.myAbsolutePanelItemA, p.getWidget(0));
+    assertEquals("Panel contains expected itemB",
+        widgetUi.myAbsolutePanelItemB, p.getWidget(1));
+    assertEquals("Panel contains expected itemC",
+        widgetUi.myAbsolutePanelItemC, p.getWidget(2));
+
+    /*
+ * The following fails on Safari 3, off by a few pixels. The coverage in + * AbsolutePanelParserTest and AbsolutePanelTest are enough to make up for
+     * the lack. Leaving this here as a warning to the next guy.
+     */
+//    {
+//      Widget w = widgetUi.myAbsolutePanelItemA;
+//      assertNotNull("Widget exists", w);
+//      assertEquals("Widget has left", 1, p.getWidgetLeft(w));
+//      assertEquals("Widget has top", 2, p.getWidgetTop(w));
+//    }
+//
+//    {
+//      Widget w = widgetUi.myAbsolutePanelItemC;
+//      assertNotNull("Widget exists", w);
+//      assertEquals("Widget has left", 10, p.getWidgetLeft(w));
+//      assertEquals("Widget has top", 20, p.getWidgetTop(w));
+//    }
+  }

   public void testStringAttributeIgnoresStaticSetter() {
     // Assumes setPopupText() is overloaded such that there is a static
@@ -437,7 +478,8 @@
   @SuppressWarnings("deprecation")
   public void testWest() {
     Widget west = root.getWidget(1);
- assertEquals(com.google.gwt.user.client.ui.DockPanel.WEST, root.getWidgetDirection(west));
+    assertEquals(com.google.gwt.user.client.ui.DockPanel.WEST,
+        root.getWidgetDirection(west));
     assertEquals(HTML.class, west.getClass());
     String html = ((HTML) west).getHTML();
     assertTrue(html.contains("side bar"));
@@ -463,7 +505,7 @@
     assertEquals(resource.getTop(), widget.getOriginTop());
     assertEquals(resource.getLeft(), widget.getOriginLeft());
   }
-
+
   public void testImageResourceInImageWidget() {
     ImageResource resource = widgetUi.prettyImage;
     Image widget = widgetUi.babyWidget;
@@ -471,7 +513,7 @@
     assertEquals(resource.getHeight(), widget.getOffsetHeight());
     assertEquals(resource.getTop(), widget.getOriginTop());
     assertEquals(resource.getLeft(), widget.getOriginLeft());
-
+
     assertEquals("expected alt text", widget.getAltText());
     assertEquals("expected style name", widget.getStyleName());
   }
@@ -480,7 +522,7 @@
     assertEquals(100, widgetUi.sideBarWidget.getOffsetWidth());
     assertEquals(150, widgetUi.sideBarWidget.getOffsetHeight());
   }
-
+
   public void testDataResource() {
     assertNotNull(widgetUi.heartCursorResource.getUrl());
   }
=======================================
--- /trunk/user/test/com/google/gwt/uibinder/test/client/WidgetBasedUi.java Wed Jul 28 13:10:14 2010 +++ /trunk/user/test/com/google/gwt/uibinder/test/client/WidgetBasedUi.java Thu Jul 29 11:09:15 2010
@@ -30,6 +30,7 @@
 import com.google.gwt.uibinder.client.UiBinder;
 import com.google.gwt.uibinder.client.UiFactory;
 import com.google.gwt.uibinder.client.UiField;
+import com.google.gwt.user.client.ui.AbsolutePanel;
 import com.google.gwt.user.client.ui.Button;
 import com.google.gwt.user.client.ui.Composite;
 import com.google.gwt.user.client.ui.DisclosurePanel;
@@ -162,6 +163,10 @@
   @UiField FooDialog fooDialog;
   @UiField ListBox fooListBox;
   @UiField Grid fooGrid;
+  @UiField AbsolutePanel myAbsolutePanel;
+  @UiField Widget myAbsolutePanelItemA;
+  @UiField Widget myAbsolutePanelItemB;
+  @UiField Widget myAbsolutePanelItemC;

   public WidgetBasedUi() {
     external.style().ensureInjected();
=======================================
--- /trunk/user/test/com/google/gwt/uibinder/test/client/WidgetBasedUi.ui.xml Wed Jul 28 13:10:14 2010 +++ /trunk/user/test/com/google/gwt/uibinder/test/client/WidgetBasedUi.ui.xml Thu Jul 29 11:09:15 2010
@@ -614,6 +614,16 @@
     </gwt:row>
   </gwt:Grid>

+  <gwt:AbsolutePanel ui:field='myAbsolutePanel'>
+    <gwt:at left='1' top='2'>
+      <gwt:Button ui:field='myAbsolutePanelItemA'/>
+    </gwt:at>
+    <gwt:Button ui:field='myAbsolutePanelItemB'/>
+    <gwt:at left='10' top='20'>
+      <gwt:Button ui:field='myAbsolutePanelItemC'/>
+    </gwt:at>
+  </gwt:AbsolutePanel>
+
    </gwt:HTMLPanel>
   </gwt:Dock>
 </gwt:DockPanel>

--
http://groups.google.com/group/Google-Web-Toolkit-Contributors

Reply via email to