Reviewers: Lex, Description: Calling almost any method in ColumnFormatter with index n will remove all col elements at indexes larger than n. This is because ensureColumn(int n) calls resizeColumnGroup(), which resizes to the exact size n.
Fix: === resizeColumnGroupd() now takes a boolean to indicate that it should only grow, not shrink. Testing: ======= Added a unit test. Please review this at http://gwt-code-reviews.appspot.com/314803/show Affected files: user/src/com/google/gwt/user/client/ui/Grid.java user/src/com/google/gwt/user/client/ui/HTMLTable.java user/test/com/google/gwt/user/client/ui/GridTest.java Index: user/test/com/google/gwt/user/client/ui/GridTest.java =================================================================== --- user/test/com/google/gwt/user/client/ui/GridTest.java (revision 7902) +++ user/test/com/google/gwt/user/client/ui/GridTest.java (working copy) @@ -89,14 +89,18 @@ columns.removeStyleName(0, "c"); assertEquals("base b", columns.getStyleName(0)); - // Only one column should be created. + // All five cols should be created. Element e = DOM.getChild(r.getElement(), 0); - assertEquals(1, DOM.getChildCount(e)); + assertEquals(5, DOM.getChildCount(e)); columns.addStyleName(3, "a"); - // Now there shoud be three such columns . + // There should still be five columns. e = DOM.getChild(r.getElement(), 0); - assertEquals(4, DOM.getChildCount(e)); + assertEquals(5, DOM.getChildCount(e)); + + // Querying column 0 should not invalidate column 3. + assertEquals("base b", columns.getStyleName(0)); + assertEquals("a", columns.getStyleName(3)); } public void testColumnMessage() { Index: user/src/com/google/gwt/user/client/ui/Grid.java =================================================================== --- user/src/com/google/gwt/user/client/ui/Grid.java (revision 7902) +++ user/src/com/google/gwt/user/client/ui/Grid.java (working copy) @@ -200,7 +200,7 @@ numColumns = columns; // Update the size of the colgroup. - getColumnFormatter().resizeColumnGroup(columns); + getColumnFormatter().resizeColumnGroup(columns, false); } /** Index: user/src/com/google/gwt/user/client/ui/HTMLTable.java =================================================================== --- user/src/com/google/gwt/user/client/ui/HTMLTable.java (revision 7902) +++ user/src/com/google/gwt/user/client/ui/HTMLTable.java (working copy) @@ -482,8 +482,9 @@ * Resize the column group element. * * @param columns the number of columns + * @param growOnly true to only grow, false to shrink if needed */ - void resizeColumnGroup(int columns) { + void resizeColumnGroup(int columns, boolean growOnly) { // The colgroup should always have at least one element. See // prepareColumnGroup() for more details. columns = Math.max(columns, 1); @@ -493,7 +494,7 @@ for (int i = num; i < columns; i++) { columnGroup.appendChild(Document.get().createColElement()); } - } else if (num > columns) { + } else if (!growOnly && num > columns) { for (int i = num; i > columns; i--) { columnGroup.removeChild(columnGroup.getLastChild()); } @@ -503,7 +504,7 @@ private Element ensureColumn(int col) { prepareColumn(col); prepareColumnGroup(); - resizeColumnGroup(col + 1); + resizeColumnGroup(col + 1, true); return columnGroup.getChild(col).cast(); } -- http://groups.google.com/group/Google-Web-Toolkit-Contributors
