Deprecate panels that have LayoutPanel alternatives.
Fix NPE in TabPanelParser.

Review by jgw, bobv

git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@6524 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/src/com/google/gwt/uibinder/parsers/CellPanelParser.java b/user/src/com/google/gwt/uibinder/parsers/CellPanelParser.java
index 67d8ca2..665ead2 100644
--- a/user/src/com/google/gwt/uibinder/parsers/CellPanelParser.java
+++ b/user/src/com/google/gwt/uibinder/parsers/CellPanelParser.java
@@ -1,12 +1,12 @@
 /*
  * Copyright 2007 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
@@ -31,51 +31,50 @@
   private static final String HEIGHT_ATTR = "height";
   private static final String CELL_TAG = "Cell";
 
-  private static HorizontalAlignmentConstantParser halignParser =
-      new HorizontalAlignmentConstantParser();
-  private static VerticalAlignmentConstantParser valignParser =
-      new VerticalAlignmentConstantParser();
-  private static StringAttributeParser stringParser =
-      new StringAttributeParser();
+  private static HorizontalAlignmentConstantParser halignParser = new HorizontalAlignmentConstantParser();
+  private static VerticalAlignmentConstantParser valignParser = new VerticalAlignmentConstantParser();
+  private static StringAttributeParser stringParser = new StringAttributeParser();
 
   /**
    * Parses the alignment and size attributes common to all CellPanels.
-   *
+   * 
    * This is exposed publicly because there is a DockPanelParser that overrides
    * the default behavior, but still needs to parse these attributes.
-   *
+   * 
    * @throws UnableToCompleteException
    */
-  public static void parseCellAttributes(XMLElement cellElem, String fieldName,
-      String childFieldName, UiBinderWriter writer) throws UnableToCompleteException {
+  static void parseCellAttributes(XMLElement cellElem, String fieldName,
+      String childFieldName, UiBinderWriter writer)
+      throws UnableToCompleteException {
+
     // Parse horizontal and vertical alignment attributes.
     if (cellElem.hasAttribute(HALIGN_ATTR)) {
-      String value =
-          halignParser.parse(cellElem.consumeAttribute(HALIGN_ATTR), writer);
-      writer.addStatement("%1$s.setCellHorizontalAlignment(%2$s, %3$s);", fieldName,
-          childFieldName, value);
+      String value = halignParser.parse(cellElem.consumeAttribute(HALIGN_ATTR),
+          writer);
+      writer.addStatement("%1$s.setCellHorizontalAlignment(%2$s, %3$s);",
+          fieldName, childFieldName, value);
     }
 
     if (cellElem.hasAttribute(VALIGN_ATTR)) {
-      String value =
-          valignParser.parse(cellElem.consumeAttribute(VALIGN_ATTR), writer);
-      writer.addStatement("%1$s.setCellVerticalAlignment(%2$s, %3$s);", fieldName,
-          childFieldName, value);
+      String value = valignParser.parse(cellElem.consumeAttribute(VALIGN_ATTR),
+          writer);
+      writer.addStatement("%1$s.setCellVerticalAlignment(%2$s, %3$s);",
+          fieldName, childFieldName, value);
     }
 
     // Parse width and height attributes.
     if (cellElem.hasAttribute(WIDTH_ATTR)) {
-      String value =
-          stringParser.parse(cellElem.consumeAttribute(WIDTH_ATTR), writer);
-      writer.addStatement("%1$s.setCellWidth(%2$s, %3$s);", fieldName, childFieldName,
-          value);
+      String value = stringParser.parse(cellElem.consumeAttribute(WIDTH_ATTR),
+          writer);
+      writer.addStatement("%1$s.setCellWidth(%2$s, %3$s);", fieldName,
+          childFieldName, value);
     }
 
     if (cellElem.hasAttribute(HEIGHT_ATTR)) {
-      String value =
-          stringParser.parse(cellElem.consumeAttribute(HEIGHT_ATTR), writer);
-      writer.addStatement("%1$s.setCellHeight(%2$s, %3$s);", fieldName, childFieldName,
-          value);
+      String value = stringParser.parse(cellElem.consumeAttribute(HEIGHT_ATTR),
+          writer);
+      writer.addStatement("%1$s.setCellHeight(%2$s, %3$s);", fieldName,
+          childFieldName, value);
     }
   }
 
@@ -84,7 +83,8 @@
     for (XMLElement child : elem.consumeChildElements()) {
       String ns = child.getNamespaceUri();
       String tagName = child.getLocalName();
-      if (ns.equals(elem.getNamespaceUri()) && tagName.equals(CELL_TAG)) {
+
+      if (ns.equals(elem.getNamespaceUri()) && localTagNameIsCell(tagName)) {
         // It's a cell element, so parse its single child as a widget.
         XMLElement widget = child.consumeSingleChildElement();
         String childFieldName = writer.parseElementToField(widget);
@@ -99,4 +99,9 @@
       }
     }
   }
+
+  private boolean localTagNameIsCell(String tagName) {
+    // Older templates had this as "Cell", but now we prefer "cell"
+    return tagName.equals(CELL_TAG) || tagName.equals(CELL_TAG.toLowerCase());
+  }
 }
diff --git a/user/src/com/google/gwt/uibinder/parsers/DockPanelParser.java b/user/src/com/google/gwt/uibinder/parsers/DockPanelParser.java
index 49d30d5..45b7dea 100644
--- a/user/src/com/google/gwt/uibinder/parsers/DockPanelParser.java
+++ b/user/src/com/google/gwt/uibinder/parsers/DockPanelParser.java
@@ -43,6 +43,9 @@
 
   public void parse(XMLElement elem, String fieldName, JClassType type,
       UiBinderWriter writer) throws UnableToCompleteException {
+    writer.warn(
+        "%1$s:%2$s is deprecated. Use the %1$s:DockLayoutPanel instead.",
+        elem.getPrefix(), elem.getLocalName());
     // Parse children.
     for (XMLElement child : elem.consumeChildElements()) {
       // DockPanel can only contain Dock elements.
diff --git a/user/src/com/google/gwt/uibinder/parsers/StackPanelParser.java b/user/src/com/google/gwt/uibinder/parsers/StackPanelParser.java
index aa35ac8..2897280 100644
--- a/user/src/com/google/gwt/uibinder/parsers/StackPanelParser.java
+++ b/user/src/com/google/gwt/uibinder/parsers/StackPanelParser.java
@@ -29,6 +29,9 @@
 
   public void parse(XMLElement elem, String fieldName, JClassType type,
       UiBinderWriter writer) throws UnableToCompleteException {
+    writer.warn(
+        "%1$s:%2$s is deprecated. Use the %1$s:StackLayoutPanel instead.",
+        elem.getPrefix(), elem.getLocalName());
     // Parse children.
     for (XMLElement child : elem.consumeChildElements()) {
 
diff --git a/user/src/com/google/gwt/uibinder/parsers/TabPanelParser.java b/user/src/com/google/gwt/uibinder/parsers/TabPanelParser.java
index 099c112..728d184 100644
--- a/user/src/com/google/gwt/uibinder/parsers/TabPanelParser.java
+++ b/user/src/com/google/gwt/uibinder/parsers/TabPanelParser.java
@@ -1,12 +1,12 @@
 /*
  * Copyright 2007 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
@@ -30,6 +30,9 @@
 
   public void parse(XMLElement elem, String fieldName, JClassType type,
       UiBinderWriter writer) throws UnableToCompleteException {
+    writer.warn(
+        "%1$s:%2$s is deprecated. Use the %1$s:TabLayoutPanel instead.",
+        elem.getPrefix(), elem.getLocalName());
     // Parse children.
     for (XMLElement child : elem.consumeChildElements()) {
       // TabPanel can only contain Tab elements.
@@ -54,17 +57,21 @@
       String childFieldName = null;
       for (XMLElement tabChild : child.consumeChildElements()) {
         if (tabChild.getLocalName().equals(TAG_TABHTML)) {
-          HtmlInterpreter interpreter =
-            HtmlInterpreter.newInterpreterForUiObject(writer, fieldName);
+          HtmlInterpreter interpreter = HtmlInterpreter.newInterpreterForUiObject(
+              writer, fieldName);
           tabHTML = tabChild.consumeInnerHtml(interpreter);
         } else {
           if (childFieldName != null) {
-            writer.die("gwt:Tab may only have a single child widget");
+            writer.die("%s may only have a single child widget", child);
           }
           childFieldName = writer.parseElementToField(tabChild);
         }
       }
 
+      if (childFieldName == null) {
+        writer.die("%s must have a child widget", child);
+      }
+
       if (tabHTML != null) {
         writer.addStatement("%1$s.add(%2$s, \"%3$s\", true);", fieldName,
             childFieldName, tabHTML);
diff --git a/user/src/com/google/gwt/uibinder/sample/client/WidgetBasedUi.ui.xml b/user/src/com/google/gwt/uibinder/sample/client/WidgetBasedUi.ui.xml
index b828a9c..3f3cc0c 100644
--- a/user/src/com/google/gwt/uibinder/sample/client/WidgetBasedUi.ui.xml
+++ b/user/src/com/google/gwt/uibinder/sample/client/WidgetBasedUi.ui.xml
@@ -278,6 +278,8 @@
         <ui:attribute name="text" description="radio button name"/>
       </demo:PointlessRadioButtonSubclass>
       
+	<gwt:HorizontalPanel>
+	  <gwt:Cell><gwt:HTMLPanel>
       <p> ... a StackPanel ... </p>
       
       <gwt:StackPanel stylePrimaryName="myStyle" width="280px" ui:field='myStackPanel'>
@@ -296,6 +298,21 @@
         </gwt:HTMLPanel>
         <gwt:Label text="Stack Three Text"  gwt:StackPanel-text="Stack Three" />
       </gwt:StackPanel>
+      </gwt:HTMLPanel></gwt:Cell>
+      
+      <gwt:cell><gwt:HTMLPanel>
+        <p> ... a TabPanel </p>
+      
+        <gwt:TabPanel>
+          <gwt:Tab text='Able'><gwt:Label>Able Widget</gwt:Label></gwt:Tab>
+          <gwt:Tab><gwt:TabHTML><b>B</b>aker</gwt:TabHTML>
+            <gwt:Label>Baker widget</gwt:Label>
+          </gwt:Tab>
+        </gwt:TabPanel>
+      </gwt:HTMLPanel></gwt:cell>
+      
+      </gwt:HorizontalPanel>
+      
       
       <p> ... a DisclosurePanel with a text header ... </p>