Revision: 9258
Author: sbruba...@google.com
Date: Fri Nov 19 05:49:25 2010
Log: Cherry picking cl/18250153 from trunk into release branch for issue
5518
http://code.google.com/p/google-web-toolkit/source/detail?r=9258
Added:
/releases/2.1/user/src/com/google/gwt/uibinder/elementparsers/HasAlignmentParser.java
/releases/2.1/user/test/com/google/gwt/uibinder/elementparsers/HasAlignmentParserTest.java
Modified:
/releases/2.1/user/src/com/google/gwt/uibinder/rebind/UiBinderWriter.java
/releases/2.1/user/test/com/google/gwt/uibinder/test/client/UiBinderTest.java
/releases/2.1/user/test/com/google/gwt/uibinder/test/client/WidgetBasedUi.java
/releases/2.1/user/test/com/google/gwt/uibinder/test/client/WidgetBasedUi.ui.xml
=======================================
--- /dev/null
+++
/releases/2.1/user/src/com/google/gwt/uibinder/elementparsers/HasAlignmentParser.java
Fri Nov 19 05:49:25 2010
@@ -0,0 +1,64 @@
+/*
+ * 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;
+import
com.google.gwt.user.client.ui.HasHorizontalAlignment.HorizontalAlignmentConstant;
+import
com.google.gwt.user.client.ui.HasVerticalAlignment.VerticalAlignmentConstant;
+
+/**
+ * Parses widgets that inherit from
+ * {...@link com.google.gwt.user.client.ui.HasAlignment}.
+ * This class is needed to resolve the parse order of alignment attributes
for
+ * these classes.
+ * <p>
+ *
+ * See
{...@link "http://code.google.com/p/google-web-toolkit/issues/detail?id=5518"}
+ * for issue details.
+ */
+
+public class HasAlignmentParser implements ElementParser {
+ public void parse(XMLElement elem, String fieldName, JClassType type,
+ UiBinderWriter writer) throws UnableToCompleteException {
+
+ // Get fully qualified class name for horizontal alignment
+ JClassType hAlignConstantType = writer.getOracle().findType(
+ HorizontalAlignmentConstant.class.getCanonicalName());
+ // Get horizontal alignment value
+ String horizontalAlignment = elem.consumeAttributeWithDefault(
+ "horizontalAlignment", null, hAlignConstantType);
+ // Set horizontal alignment if not null
+ if (horizontalAlignment != null) {
+ writer.addStatement("%s.setHorizontalAlignment(%s);", fieldName,
+ horizontalAlignment);
+ }
+
+ // Get fully qualified class name for vertical alignment
+ JClassType vAlignConstantType = writer.getOracle().findType(
+ VerticalAlignmentConstant.class.getCanonicalName());
+ // Get vertical alignment value
+ String verticalAlignment = elem.consumeAttributeWithDefault(
+ "verticalAlignment", null, vAlignConstantType);
+ // Set vertical alignment if not null
+ if (verticalAlignment != null) {
+ writer.addStatement("%s.setVerticalAlignment(%s);", fieldName,
+ verticalAlignment);
+ }
+ }
+}
=======================================
--- /dev/null
+++
/releases/2.1/user/test/com/google/gwt/uibinder/elementparsers/HasAlignmentParserTest.java
Fri Nov 19 05:49:25 2010
@@ -0,0 +1,98 @@
+/*
+ * 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 org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+
+import java.util.Iterator;
+
+/**
+ * A unit test. Guess what of.
+ */
+public class HasAlignmentParserTest extends TestCase {
+ private static final String PARSED_TYPE
= "com.google.gwt.user.client.ui.DockLayoutPanel";
+
+ private ElementParserTester tester;
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ tester = new ElementParserTester(PARSED_TYPE, new
HasAlignmentParser());
+ }
+
+ public void testInvalidVerticalAlignment() throws SAXException {
+ StringBuffer b = new StringBuffer();
+ b.append("<g:DockLayoutPanel verticalAlignment='FOO'>");
+ b.append("</g:DockLayoutPanel>");
+
+ try {
+ tester.parse(b.toString());
+ fail();
+ } catch (UnableToCompleteException e) {
+ assertTrue("Expect vertical alignment parse error",
+ tester.logger.died.contains("Cannot parse value: \"FOO\""));
+ }
+ }
+
+ public void testInvalidHorizontalAlignment() throws SAXException {
+ StringBuffer b = new StringBuffer();
+ b.append("<g:DockLayoutPanel horizontalAlignment='BAR'>");
+ b.append("</g:DockLayoutPanel>");
+
+ try {
+ tester.parse(b.toString());
+ fail();
+ } catch (UnableToCompleteException e) {
+ assertTrue("Expect horizontal alignment parse error",
+ tester.logger.died.contains("Cannot parse value: \"BAR\""));
+ }
+ }
+
+ public void testNoAlignmentArgs() throws UnableToCompleteException,
+ SAXParseException {
+ StringBuffer b = new StringBuffer();
+ b.append("<g:DockLayoutPanel>");
+ b.append("</g:DockLayoutPanel>");
+
+ tester.parse(b.toString());
+ assertTrue(tester.writer.statements.isEmpty());
+ }
+
+ public void testValidArgs() throws UnableToCompleteException,
+ SAXParseException {
+ StringBuffer b = new StringBuffer();
+ b.append("<g:DockLayoutPanel verticalAlignment='ALIGN_MIDDLE'
horizontalAlignment='ALIGN_LEFT'>");
+ b.append("</g:DockLayoutPanel>");
+
+ tester.parse(b.toString());
+
assertStatements("fieldName.setHorizontalAlignment(com.google.gwt.user.client.ui.HasHorizontalAlignment.ALIGN_LEFT);",
+
"fieldName.setVerticalAlignment(com.google.gwt.user.client.ui.HasVerticalAlignment.ALIGN_MIDDLE);");
+ }
+
+ 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);
+ }
+}
=======================================
---
/releases/2.1/user/src/com/google/gwt/uibinder/rebind/UiBinderWriter.java
Thu Oct 14 11:27:30 2010
+++
/releases/2.1/user/src/com/google/gwt/uibinder/rebind/UiBinderWriter.java
Fri Nov 19 05:49:25 2010
@@ -997,6 +997,7 @@
addWidgetParser("Image");
addWidgetParser("ListBox");
addWidgetParser("Grid");
+ addWidgetParser("HasAlignment");
}
/**
@@ -1092,8 +1093,15 @@
// TODO why can this be null?
if (fieldWriter != null) {
- fieldManager.lookup(fieldName).setInitializer(
- formatCode("owner.%1$s", fieldName));
+ String initializer;
+ if (designTime.isDesignTime()) {
+ String typeName =
ownerField.getType().getRawType().getQualifiedSourceName();
+ initializer = designTime.getProvidedField(typeName,
+ ownerField.getName());
+ } else {
+ initializer = formatCode("owner.%1$s", fieldName);
+ }
+ fieldManager.lookup(fieldName).setInitializer(initializer);
}
}
}
@@ -1207,3 +1215,4 @@
designTime.addDeclarations(w);
}
}
+
=======================================
---
/releases/2.1/user/test/com/google/gwt/uibinder/test/client/UiBinderTest.java
Sun Oct 3 08:42:48 2010
+++
/releases/2.1/user/test/com/google/gwt/uibinder/test/client/UiBinderTest.java
Fri Nov 19 05:49:25 2010
@@ -573,6 +573,23 @@
"<td>Lately, anyway.</td>");
}
+ public void testAlignmentAttributes() {
+ assertEquals(
+
widgetUi.myHorizontalPanel.getHorizontalAlignment().getTextAlignString(),
+ "left");
+ assertEquals(
+
widgetUi.myHorizontalPanel.getVerticalAlignment().getVerticalAlignString(),
+ "middle");
+
+ final String innerHtml =
+ widgetUi.myHorizontalPanel.getElement().getInnerHTML();
+ assertInOrder(innerHtml, "vertical-align: middle",
+ "a stackpanel");
+
+ final String innerHtml2 = innerHtml.replace("\"", "");
+ assertInOrder(innerHtml2, "align=left", "a stackpanel");
+ }
+
/**
* Assert that the expect strings are found in body, and in the order
given.
* WARNING: both body and expected are normalized to lower case, to get
around
=======================================
---
/releases/2.1/user/test/com/google/gwt/uibinder/test/client/WidgetBasedUi.java
Sun Oct 3 08:42:48 2010
+++
/releases/2.1/user/test/com/google/gwt/uibinder/test/client/WidgetBasedUi.java
Fri Nov 19 05:49:25 2010
@@ -38,6 +38,7 @@
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.HasHTML;
+import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.ListBox;
@@ -97,6 +98,7 @@
@UiField RadioButton myRadioAble;
@UiField RadioButton myRadioBaker;
@UiField StackPanel myStackPanel;
+ @UiField HorizontalPanel myHorizontalPanel;
@UiField Widget myStackPanelItem;
@UiField DisclosurePanel myDisclosurePanel;
@UiField Widget myDisclosurePanelItem;
=======================================
---
/releases/2.1/user/test/com/google/gwt/uibinder/test/client/WidgetBasedUi.ui.xml
Sun Oct 3 08:42:48 2010
+++
/releases/2.1/user/test/com/google/gwt/uibinder/test/client/WidgetBasedUi.ui.xml
Fri Nov 19 05:49:25 2010
@@ -303,7 +303,7 @@
<ui:attribute name="text" description="radio button name"/>
</demo:PointlessRadioButtonSubclass>
- <gwt:HorizontalPanel horizontalAlignment="ALIGN_LEFT">
+ <gwt:HorizontalPanel ui:field="myHorizontalPanel"
horizontalAlignment="ALIGN_LEFT" verticalAlignment="ALIGN_MIDDLE">
<gwt:Cell><gwt:HTMLPanel>
<p> ... a StackPanel ... </p>
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors