Description:
ColumnFormatter.setWidth changes the width of the wrong column
index in Mozilla, but works correctly for all other browsers.  The issue only
occurs when setColumnWidth is called after the HTMLTable widget is added to the
page.  It appears that Mozilla creates an internal reference to a colgroup if
none exists when the Element is added to the page, shifting the index of all
the columns by one.  This bug affects the FlexTable and Grid classes.

Fix:
I added a call to prepareColumnGroup in the setColumnFormatter method,
which guarantees that we create a col tag when the HTMLTable is instantiated
(before adding it to the page).  This also means that we have a col tag even
when we have no columns, but this does not appear to affect anything.

Issue: 1223
Patch by: jlabanca
Review by: jgw



git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@1283 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/src/com/google/gwt/user/client/ui/HTMLTable.java b/user/src/com/google/gwt/user/client/ui/HTMLTable.java
index f35ca86..ed37b33 100644
--- a/user/src/com/google/gwt/user/client/ui/HTMLTable.java
+++ b/user/src/com/google/gwt/user/client/ui/HTMLTable.java
@@ -304,7 +304,6 @@
      * @param col the column of the cell
      * @return the element
      */
-
     private native Element getCellElement(Element table, int row, int col) /*-{
       var out = table.rows[row].cells[col];
       return (out == null ? null : out);
@@ -415,11 +414,7 @@
 
     private Element ensureColumn(int col) {
       prepareColumn(col);
-
-      if (columnGroup == null) {
-        columnGroup = DOM.createElement("colgroup");
-        DOM.insertChild(getElement(), columnGroup, 0);
-      }
+      prepareColumnGroup();
 
       int num = DOM.getChildCount(columnGroup);
       if (num <= col) {
@@ -432,6 +427,20 @@
       }
       return DOM.getChild(columnGroup, col);
     }
+    
+    /**
+     * Prepare the colgroup tag for the first time, guarenteeing that it
+     * exists and has at least one col tag in it.  This method corrects
+     * a Mozilla issue where the col tag will affect the wrong column if
+     * a col tag doesn't exist when the element is attached to the page.
+     */
+    private void prepareColumnGroup() {
+      if (columnGroup == null) {
+        columnGroup = DOM.createElement("colgroup");
+        DOM.insertChild(tableElem, columnGroup, 0);
+        DOM.appendChild(columnGroup, DOM.createElement("col"));
+      }
+    }
   }
 
   /**
@@ -1343,6 +1352,7 @@
 
   protected void setColumnFormatter(ColumnFormatter formatter) {
     columnFormatter = formatter;
+    columnFormatter.prepareColumnGroup();
   }
 
   /**