Revision: 9513
Author: [email protected]
Date: Fri Jan  7 10:19:06 2011
Log: Adding support for setting column widths in CellTable, and for allowing CellTable to use fixed table-layout for more precise control over column widths. I also updated the CellTable example in Showcase and the DynaTableRf sample with the new feature so that columns do not resize when paging.
https://groups.google.com/group/google-web-toolkit-contributors/browse_thread/thread/46bd604e11091025/f8eb6326b0892417?lnk=raot#f8eb6326b0892417

Review at http://gwt-code-reviews.appspot.com/1263801

Review by: [email protected]
http://code.google.com/p/google-web-toolkit/source/detail?r=9513

Modified:
/trunk/samples/dynatablerf/src/com/google/gwt/sample/dynatablerf/client/widgets/SummaryWidget.java /trunk/samples/dynatablerf/src/com/google/gwt/sample/dynatablerf/client/widgets/SummaryWidget.ui.xml /trunk/samples/showcase/src/com/google/gwt/sample/showcase/client/ContentWidget.java /trunk/samples/showcase/src/com/google/gwt/sample/showcase/client/ContentWidgetView.java /trunk/samples/showcase/src/com/google/gwt/sample/showcase/client/ContentWidgetView.ui.xml /trunk/samples/showcase/src/com/google/gwt/sample/showcase/client/ShowcaseShell.java /trunk/samples/showcase/src/com/google/gwt/sample/showcase/client/ShowcaseShell.ui.xml /trunk/samples/showcase/src/com/google/gwt/sample/showcase/client/content/cell/CwCellTable.java /trunk/samples/showcase/src/com/google/gwt/sample/showcase/client/content/cell/CwCellTable.ui.xml
 /trunk/user/src/com/google/gwt/dom/client/Style.java
 /trunk/user/src/com/google/gwt/user/cellview/client/CellTable.css
 /trunk/user/src/com/google/gwt/user/cellview/client/CellTable.java
 /trunk/user/src/com/google/gwt/user/cellview/client/CellTableBasic.css
 /trunk/user/test/com/google/gwt/dom/client/StyleTest.java
 /trunk/user/test/com/google/gwt/user/cellview/client/CellTableTest.java

=======================================
--- /trunk/samples/dynatablerf/src/com/google/gwt/sample/dynatablerf/client/widgets/SummaryWidget.java Thu Oct 14 08:15:26 2010 +++ /trunk/samples/dynatablerf/src/com/google/gwt/sample/dynatablerf/client/widgets/SummaryWidget.java Fri Jan 7 10:19:06 2011
@@ -62,7 +62,6 @@
   }

   interface Style extends CssResource {
-    String thirty();
   }

   interface TableResources extends CellTable.Resources {
@@ -106,9 +105,6 @@
   @UiField
   DockLayoutPanel dock;

-  @UiField
-  Style style;
-
   @UiField(provided = true)
   SimplePager pager = new SimplePager();

@@ -135,11 +131,13 @@
dock.getWidgetContainerElement(table).getStyle().setProperty("overflowY",
         "visible");

-    table.addColumn(new NameColumn(), "Name");
-    table.addColumn(new DescriptionColumn(), "Description");
+    Column<PersonProxy, String> nameColumn = new NameColumn();
+    table.addColumn(nameColumn, "Name");
+    table.setColumnWidth(nameColumn, "25ex");
+ Column<PersonProxy, String> descriptionColumn = new DescriptionColumn();
+    table.addColumn(descriptionColumn, "Description");
+    table.setColumnWidth(descriptionColumn, "40ex");
     table.addColumn(new ScheduleColumn(), "Schedule");
-    table.addColumnStyleName(0, style.thirty());
-    table.addColumnStyleName(1, style.thirty());
     table.setRowCount(numRows, false);
     table.setSelectionModel(selectionModel);
     table.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.DISABLED);
=======================================
--- /trunk/samples/dynatablerf/src/com/google/gwt/sample/dynatablerf/client/widgets/SummaryWidget.ui.xml Wed Oct 13 06:04:39 2010 +++ /trunk/samples/dynatablerf/src/com/google/gwt/sample/dynatablerf/client/widgets/SummaryWidget.ui.xml Fri Jan 7 10:19:06 2011
@@ -5,13 +5,10 @@
       .displayInline {
        display: inline;
       }
-
-      .thirty {
-       width: 30%
-      }

       .table {
        width: 100%;
+       table-layout: fixed;
       }
     </ui:style>
   <g:DockLayoutPanel ui:field="dock" unit="EX">
=======================================
--- /trunk/samples/showcase/src/com/google/gwt/sample/showcase/client/ContentWidget.java Tue Oct 5 10:51:03 2010 +++ /trunk/samples/showcase/src/com/google/gwt/sample/showcase/client/ContentWidget.java Fri Jan 7 10:19:06 2011
@@ -267,6 +267,15 @@
           rc, ShowcaseConstants.DST_SOURCE_EXAMPLE + className + ".html");
     }
   }
+
+  /**
+   * Check if the widget should have margins.
+   *
+   * @return true to use margins, false to flush against edges
+   */
+  public boolean hasMargins() {
+    return true;
+  }

   /**
    * Returns true if this widget has a style section.
@@ -302,7 +311,7 @@
    */
   @Override
   protected final Widget createWidget() {
-    view = new ContentWidgetView();
+    view = new ContentWidgetView(hasMargins());
     view.setName(getName());
     view.setDescription(getDescription());
     return view;
=======================================
--- /trunk/samples/showcase/src/com/google/gwt/sample/showcase/client/ContentWidgetView.java Mon Sep 13 12:31:36 2010 +++ /trunk/samples/showcase/src/com/google/gwt/sample/showcase/client/ContentWidgetView.java Fri Jan 7 10:19:06 2011
@@ -17,6 +17,7 @@

 import com.google.gwt.core.client.GWT;
 import com.google.gwt.dom.client.Element;
+import com.google.gwt.dom.client.Style.Unit;
 import com.google.gwt.uibinder.client.UiBinder;
 import com.google.gwt.uibinder.client.UiField;
 import com.google.gwt.user.client.ui.Composite;
@@ -44,8 +45,12 @@
   @UiField
   Element nameElem;

-  public ContentWidgetView() {
+  public ContentWidgetView(boolean hasMargins) {
     initWidget(uiBinder.createAndBindUi(this));
+    if (hasMargins) {
+      examplePanel.getElement().getStyle().setMarginLeft(10.0, Unit.PX);
+      examplePanel.getElement().getStyle().setMarginRight(10.0, Unit.PX);
+    }
   }

   public void setDescription(String html) {
=======================================
--- /trunk/samples/showcase/src/com/google/gwt/sample/showcase/client/ContentWidgetView.ui.xml Mon Sep 13 12:31:36 2010 +++ /trunk/samples/showcase/src/com/google/gwt/sample/showcase/client/ContentWidgetView.ui.xml Fri Jan 7 10:19:06 2011
@@ -8,13 +8,14 @@
       color: #4B4A4A;
       font-size: 17pt;
       font-weight: bold;
+      margin: 0px 10px;
     }

     .description {
       color: #4B4A4A;
       padding: 10px 0px;
       border-bottom: 1px solid #6F7277;
-      margin-bottom: 12px;
+      margin: 0px 10px 12px 10px;
     }
   </ui:style>

=======================================
--- /trunk/samples/showcase/src/com/google/gwt/sample/showcase/client/ShowcaseShell.java Wed Jan 5 11:56:03 2011 +++ /trunk/samples/showcase/src/com/google/gwt/sample/showcase/client/ShowcaseShell.java Fri Jan 7 10:19:06 2011
@@ -16,6 +16,7 @@
 package com.google.gwt.sample.showcase.client;

 import com.google.gwt.core.client.GWT;
+import com.google.gwt.dom.client.Style.Unit;
 import com.google.gwt.dom.client.TableCellElement;
 import com.google.gwt.dom.client.TableElement;
 import com.google.gwt.dom.client.Style.Display;
@@ -186,6 +187,8 @@
     initWidget(uiBinder.createAndBindUi(this));
     initializeLocaleBox();
     contentSource.getElement().getStyle().setBackgroundColor("#eee");
+    contentSource.getElement().getStyle().setMarginLeft(10.0, Unit.PX);
+    contentSource.getElement().getStyle().setMarginRight(10.0, Unit.PX);
     contentSource.getElement().getStyle().setProperty(
         "border", "1px solid #c3c3c3");
contentSource.getElement().getStyle().setProperty("padding", "10px 2px");
=======================================
--- /trunk/samples/showcase/src/com/google/gwt/sample/showcase/client/ShowcaseShell.ui.xml Mon Sep 13 12:31:36 2010 +++ /trunk/samples/showcase/src/com/google/gwt/sample/showcase/client/ShowcaseShell.ui.xml Fri Jan 7 10:19:06 2011
@@ -109,7 +109,7 @@
     }

     .contentPanel {
-      padding: 10px;
+      padding: 10px 0px;
     }
   </ui:style>

=======================================
--- /trunk/samples/showcase/src/com/google/gwt/sample/showcase/client/content/cell/CwCellTable.java Wed Jan 5 04:42:33 2011 +++ /trunk/samples/showcase/src/com/google/gwt/sample/showcase/client/content/cell/CwCellTable.java Fri Jan 7 10:19:06 2011
@@ -22,6 +22,7 @@
 import com.google.gwt.cell.client.TextCell;
 import com.google.gwt.core.client.GWT;
 import com.google.gwt.core.client.RunAsyncCallback;
+import com.google.gwt.dom.client.Style.Unit;
 import com.google.gwt.i18n.client.Constants;
 import com.google.gwt.safehtml.shared.SafeHtmlUtils;
 import com.google.gwt.sample.showcase.client.ContentWidget;
@@ -108,6 +109,11 @@
         false, "ContactDatabase.java", "CwCellTable.ui.xml");
     this.constants = constants;
   }
+
+  @Override
+  public boolean hasMargins() {
+    return false;
+  }

   /**
    * Initialize this example.
@@ -122,6 +128,7 @@
     // change.
     cellTable = new CellTable<ContactInfo>(
         ContactDatabase.ContactInfo.KEY_PROVIDER);
+    cellTable.setWidth("100%", true);

// Attach a column sort handler to the ListDataProvider to sort the list.
     ListHandler<ContactInfo> sortHandler = new ListHandler<ContactInfo>(
@@ -185,6 +192,7 @@
       }
     };
cellTable.addColumn(checkColumn, SafeHtmlUtils.fromSafeConstant("<br/>"));
+    cellTable.setColumnWidth(checkColumn, 40, Unit.PX);

     // First name.
Column<ContactInfo, String> firstNameColumn = new Column<ContactInfo, String>(
@@ -208,6 +216,7 @@
         ContactDatabase.get().refreshDisplays();
       }
     });
+    cellTable.setColumnWidth(firstNameColumn, 20, Unit.PCT);

     // Last name.
Column<ContactInfo, String> lastNameColumn = new Column<ContactInfo, String>(
@@ -231,6 +240,7 @@
         ContactDatabase.get().refreshDisplays();
       }
     });
+    cellTable.setColumnWidth(lastNameColumn, 20, Unit.PCT);

     // Category.
     final Category[] categories = ContactDatabase.get().queryCategories();
@@ -257,6 +267,7 @@
         ContactDatabase.get().refreshDisplays();
       }
     });
+    cellTable.setColumnWidth(categoryColumn, 130, Unit.PX);

     // Address.
Column<ContactInfo, String> addressColumn = new Column<ContactInfo, String>(
@@ -273,5 +284,6 @@
       }
     });
cellTable.addColumn(addressColumn, constants.cwCellTableColumnAddress());
+    cellTable.setColumnWidth(addressColumn, 60, Unit.PCT);
   }
 }
=======================================
--- /trunk/samples/showcase/src/com/google/gwt/sample/showcase/client/content/cell/CwCellTable.ui.xml Wed Oct 13 06:04:39 2010 +++ /trunk/samples/showcase/src/com/google/gwt/sample/showcase/client/content/cell/CwCellTable.ui.xml Fri Jan 7 10:19:06 2011
@@ -6,14 +6,14 @@

   <ui:style>
     .cellTable {
-      width: 600px;
-      border: 1px solid #ccc;
+      border-bottom: 1px solid #ccc;
       text-align: left;
+      margin-bottom: 4px;
     }
   </ui:style>

   <g:HTMLPanel>
-    <table>
+    <table cellspacing='0' cellpadding='0' style='width:100%;'>
       <tr>
         <td
           valign='top'>
=======================================
--- /trunk/user/src/com/google/gwt/dom/client/Style.java Mon Nov 15 15:07:03 2010 +++ /trunk/user/src/com/google/gwt/dom/client/Style.java Fri Jan 7 10:19:06 2011
@@ -481,6 +481,25 @@
     };
     public abstract String getCssName();
   }
+
+  /**
+   * Enum for the table-layout property.
+   */
+  public enum TableLayout implements HasCssName {
+    AUTO {
+      @Override
+      public String getCssName() {
+        return TABLE_LAYOUT_AUTO;
+      }
+    },
+    FIXED {
+      @Override
+      public String getCssName() {
+        return TABLE_LAYOUT_FIXED;
+      }
+    };
+    public abstract String getCssName();
+  }

   /**
    * Enum for the text-decoration property.
@@ -687,6 +706,10 @@
   private static final String STYLE_BACKGROUND_IMAGE = "backgroundImage";
   private static final String STYLE_BACKGROUND_COLOR = "backgroundColor";
   private static final String STYLE_VERTICAL_ALIGN = "verticalAlign";
+  private static final String STYLE_TABLE_LAYOUT = "tableLayout";
+
+  private static final String TABLE_LAYOUT_AUTO = "auto";
+  private static final String TABLE_LAYOUT_FIXED = "fixed";

private static final String TEXT_DECORATION_LINE_THROUGH = "line-through";
   private static final String TEXT_DECORATION_OVERLINE = "overline";
@@ -948,6 +971,13 @@
   public final void clearRight() {
      clearProperty(STYLE_RIGHT);
    }
+
+  /**
+   * Clear the table-layout css property.
+   */
+  public final void clearTableLayout() {
+    clearProperty(STYLE_TABLE_LAYOUT);
+  }

   /**
    * Clears the text-decoration CSS property.
@@ -1208,6 +1238,13 @@
   public final String getRight() {
     return getProperty(STYLE_RIGHT);
   }
+
+  /**
+   * Gets the table-layout property.
+   */
+  public final String getTableLayout() {
+    return getProperty(STYLE_TABLE_LAYOUT);
+  }

   /**
    * Gets the text-decoration CSS property.
@@ -1499,6 +1536,13 @@
   public final void setRight(double value, Unit unit) {
     setProperty(STYLE_RIGHT, value, unit);
   }
+
+  /**
+   * Set the table-layout CSS property.
+   */
+  public final void setTableLayout(TableLayout value) {
+    setProperty(STYLE_TABLE_LAYOUT, value.getCssName());
+  }

   /**
    * Sets the text-decoration CSS property.
=======================================
--- /trunk/user/src/com/google/gwt/user/cellview/client/CellTable.css Wed Jan 5 04:42:33 2011 +++ /trunk/user/src/com/google/gwt/user/cellview/client/CellTable.css Fri Jan 7 10:19:06 2011
@@ -32,6 +32,7 @@
   text-align: left;
   color: #4b4a4a;
   text-shadow: #ddf 1px 1px 0;
+  overflow: hidden;
 }

 .cellTableHeader {
@@ -40,10 +41,12 @@
   text-align: left;
   color: #4b4a4a;
   text-shadow: #ddf 1px 1px 0;
+  overflow: hidden;
 }

 .cellTableCell {
   padding: 2px 15px;
+  overflow: hidden;
 }

 .cellTableFirstColumnFooter {
=======================================
--- /trunk/user/src/com/google/gwt/user/cellview/client/CellTable.java Wed Jan 5 04:42:33 2011 +++ /trunk/user/src/com/google/gwt/user/cellview/client/CellTable.java Fri Jan 7 10:19:06 2011
@@ -26,6 +26,8 @@
 import com.google.gwt.dom.client.EventTarget;
 import com.google.gwt.dom.client.NodeList;
 import com.google.gwt.dom.client.Style.Display;
+import com.google.gwt.dom.client.Style.TableLayout;
+import com.google.gwt.dom.client.Style.Unit;
 import com.google.gwt.dom.client.TableCellElement;
 import com.google.gwt.dom.client.TableColElement;
 import com.google.gwt.dom.client.TableElement;
@@ -55,8 +57,10 @@
 import com.google.gwt.view.client.SelectionModel;

 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
+import java.util.Map;
 import java.util.Set;

 /**
@@ -478,11 +482,11 @@
     return DEFAULT_RESOURCES;
   }

+  final TableColElement colgroup;
   private boolean cellIsEditing;

-  private final TableColElement colgroup;
-
   private final List<Column<T, ?>> columns = new ArrayList<Column<T, ?>>();
+ private final Map<Column<T, ?>, String> columnWidths = new HashMap<Column<T, ?>, String>();

   /**
    * Indicates that at least one column depends on selection.
@@ -733,6 +737,16 @@
   public void addColumnStyleName(int index, String styleName) {
     ensureTableColElement(index).addClassName(styleName);
   }
+
+  /**
+   * Clear the width of the specified {...@link Column}.
+   *
+   * @param column the column
+   */
+  public void clearColumnWidth(Column<T, ?> column) {
+    columnWidths.remove(column);
+    refreshColumnWidths();
+  }

   /**
    * Return the height of the table body.
@@ -770,7 +784,7 @@
    * @param column the column to search for
    * @return the index of the column, or -1 if not found
    */
-  public int getColumnIndex(Column<T,?> column) {
+  public int getColumnIndex(Column<T, ?> column) {
     return columns.indexOf(column);
   }

@@ -942,6 +956,12 @@
     insertColumn(beforeIndex, col, new SafeHtmlHeader(headerHtml),
         new SafeHtmlHeader(footerHtml));
   }
+
+  @Override
+  public void redraw() {
+    refreshColumnWidths();
+    super.redraw();
+  }

   /**
    * Redraw the table's footers.
@@ -1018,6 +1038,32 @@
     }
     ensureTableColElement(index).removeClassName(styleName);
   }
+
+  /**
+ * Set the width of a {...@link Column}. The layout behavior depends on whether
+   * or not the table is using fixed layout.
+   *
+   * @param column the column
+   * @param width the width of the column
+   * @see #setTableLayoutFixed(boolean)
+   */
+  public void setColumnWidth(Column<T, ?> column, String width) {
+    columnWidths.put(column, width);
+    refreshColumnWidths();
+  }
+
+  /**
+ * Set the width of a {...@link Column}. The layout behavior depends on whether
+   * or not the table is using fixed layout.
+   *
+   * @param column the column
+   * @param width the width of the column
+   * @param unit the {...@link Unit} of measurement
+   * @see #setTableLayoutFixed(boolean)
+   */
+ public void setColumnWidth(Column<T, ?> column, double width, Unit unit) {
+    setColumnWidth(column, width + unit.getType());
+  }

   /**
* Sets the object used to determine how a row is styled; the change will take
@@ -1028,6 +1074,62 @@
   public void setRowStyles(RowStyles<T> rowStyles) {
     this.rowStyles = rowStyles;
   }
+
+  /**
+   * <p>
+   * Enable or disable fixed table layout.
+   * </p>
+   *
+   * <p>
+   * <h1>Fixed Table Layout</h1>
+ * When using the fixed table layout, cell contents are truncated as needed,
+   * which allows you to set the exact width of columns and the table. The
+ * default column width is 0 (invisible). In order to see all columns, you + * must set the width of the table (recommended 100%), or set the width of
+   * every column in the table. The following conditions are true for fixed
+   * layout tables:
+   * <ul>
+   * <li>
+ * If the widths of <b>all</b> columns are set, the width becomes a weight and
+   * the columns are resized proportionally.</li>
+   * <li>If the widths of <b>some</b> columns are set using absolute values
+ * (PX), those columns are fixed and the remaining width is divided evenly + * over the other columns. If there is no remaining width, the other columns
+   * will not be visible.</li>
+ * <li>If the width of some columns are set in absolute values (PX) and others + * are set in relative values (PCT), the absolute columns will be fixed and + * the remaining width is divided proportionally over the PCT columns. This
+   * allows users to define how the remaining width is allocated.</li>
+   * </ul>
+   * </p>
+   *
+   * @param isFixed true to use fixed table layout, false not to
+ * @see <a href="http://www.w3.org/TR/CSS2/tables.html#width-layout";>W3C HTML
+   *      Specification</a>
+   */
+  public void setTableLayoutFixed(boolean isFixed) {
+    if (isFixed) {
+      table.getStyle().setTableLayout(TableLayout.FIXED);
+    } else {
+      table.getStyle().clearTableLayout();
+    }
+  }
+
+  /**
+ * Set the width of the width and specify whether or not it should use fixed
+   * table layout. See {...@link #setTableLayoutFixed(boolean)} for more
+   * information about fixed layout tables.
+   *
+   * @param width the width of the table
+   * @param isFixedLayout true to use fixed width layout, false not to
+   * @see #setTableLayoutFixed(boolean)
+ * @see <a href="http://www.w3.org/TR/CSS2/tables.html#width-layout";>W3C HTML
+   *      Specification</a>
+   */
+  public final void setWidth(String width, boolean isFixedLayout) {
+    super.setWidth(width);
+    setTableLayoutFixed(isFixedLayout);
+  }

   @Override
   protected Element convertToElements(SafeHtml html) {
@@ -1752,6 +1854,29 @@
     Set<String> consumedEvents = column.getCell().getConsumedEvents();
     return consumedEvents != null && consumedEvents.size() > 0;
   }
+
+  private void refreshColumnWidths() {
+    int columnCount = getColumnCount();
+    for (int i = 0; i < columnCount; i++) {
+      Column<T, ?> column = columns.get(i);
+      String width = columnWidths.get(column);
+      if (width == null) {
+        ensureTableColElement(i).getStyle().clearWidth();
+      } else {
+        ensureTableColElement(i).getStyle().setProperty("width", width);
+      }
+    }
+
+    /*
+ * Set the width to zero for all col elements that appear after the last + * column. Clearing the width would cause it to take up the remaining width
+     * in a fixed layout table.
+     */
+    int colCount = colgroup.getChildCount();
+    for (int i = columnCount; i < colCount; i++) {
+      ensureTableColElement(i).getStyle().setWidth(0.0, Unit.PX);
+    }
+  }

private <C> boolean resetFocusOnCellImpl(int row, int col, Column<T, C> column) {
     Element parent = getKeyboardSelectedElement();
=======================================
--- /trunk/user/src/com/google/gwt/user/cellview/client/CellTableBasic.css Wed Jan 5 04:42:33 2011 +++ /trunk/user/src/com/google/gwt/user/cellview/client/CellTableBasic.css Fri Jan 7 10:19:06 2011
@@ -34,7 +34,8 @@
   padding: 0px 10px;
   text-align: left;
   color: #4b4a4a;
-  text-shadow: #ddf 1px 1px 0
+  text-shadow: #ddf 1px 1px 0;
+  overflow: hidden;
 }

 @sprite .cellTableHeader {
@@ -47,10 +48,12 @@
   text-align: left;
   color: #4b4a4a;
   text-shadow: #ddf 1px 1px 0;
+  overflow: hidden;
 }

 .cellTableCell {
   padding: 4px 10px;
+  overflow: hidden;
 }

 .cellTableFirstColumnFooter {
=======================================
--- /trunk/user/test/com/google/gwt/dom/client/StyleTest.java Wed Jan 5 14:37:41 2011 +++ /trunk/user/test/com/google/gwt/dom/client/StyleTest.java Fri Jan 7 10:19:06 2011
@@ -33,6 +33,7 @@
 import com.google.gwt.dom.client.Style.ListStyleType;
 import com.google.gwt.dom.client.Style.Overflow;
 import com.google.gwt.dom.client.Style.Position;
+import com.google.gwt.dom.client.Style.TableLayout;
 import com.google.gwt.dom.client.Style.TextDecoration;
 import com.google.gwt.dom.client.Style.VerticalAlign;
 import com.google.gwt.dom.client.Style.Visibility;
@@ -198,6 +199,16 @@
     style.setPosition(Position.FIXED);
     assertEquals(Position.FIXED, style.getPosition());
   }
+
+  public void testTableLayout() {
+    TableElement table = Document.get().createTableElement();
+    Style style = table.getStyle();
+
+    style.setTableLayout(TableLayout.AUTO);
+    assertEquals(TableLayout.AUTO, style.getTableLayout());
+    style.setTableLayout(TableLayout.FIXED);
+    assertEquals(TableLayout.FIXED, style.getTableLayout());
+  }

   public void testTextDecoration() {
     DivElement div = Document.get().createDivElement();
=======================================
--- /trunk/user/test/com/google/gwt/user/cellview/client/CellTableTest.java Wed Jan 5 04:42:33 2011 +++ /trunk/user/test/com/google/gwt/user/cellview/client/CellTableTest.java Fri Jan 7 10:19:06 2011
@@ -20,11 +20,13 @@
 import com.google.gwt.cell.client.TextCell;
 import com.google.gwt.core.client.GWT;
 import com.google.gwt.dom.client.Document;
+import com.google.gwt.dom.client.Element;
 import com.google.gwt.dom.client.NativeEvent;
 import com.google.gwt.dom.client.TableCellElement;
 import com.google.gwt.dom.client.TableElement;
 import com.google.gwt.dom.client.TableRowElement;
 import com.google.gwt.dom.client.TableSectionElement;
+import com.google.gwt.dom.client.Style.Unit;
 import com.google.gwt.safehtml.shared.SafeHtml;
 import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
 import com.google.gwt.user.cellview.client.CellTable.Resources;
@@ -382,6 +384,59 @@
     assertTrue(getHeaderElement(table, 2).getClassName().contains(
         styleLastColumn));
   }
+
+  /**
+   * Test that removing a column sets its width to zero.
+   */
+  public void testRemoveColumnWithWidth() {
+    CellTable<String> table = createAbstractHasData(new TextCell());
+    Column<String, ?> column1 = table.getColumn(1);
+    table.setColumnWidth(column1, "100px");
+    Element col0 = table.colgroup.getFirstChildElement();
+    Element col1 = col0.getNextSiblingElement();
+    assertEquals("100px", col1.getStyle().getWidth().toLowerCase());
+
+    // Remove column 1.
+    table.removeColumn(column1);
+    assertEquals("0px", col1.getStyle().getWidth());
+  }
+
+  public void testSetColumnWidth() {
+    CellTable<String> table = createAbstractHasData(new TextCell());
+    Column<String, ?> column0 = table.getColumn(0);
+    Column<String, ?> column1 = table.getColumn(1);
+
+    // Set the width.
+    table.setColumnWidth(column1, "100px");
+    Element col0 = table.colgroup.getFirstChildElement();
+    Element col1 = col0.getNextSiblingElement();
+    assertEquals("", col0.getStyle().getWidth());
+    assertEquals("100px", col1.getStyle().getWidth().toLowerCase());
+
+    // Clear the width.
+    table.clearColumnWidth(column1);
+    assertEquals("", col0.getStyle().getWidth());
+    assertEquals("", col1.getStyle().getWidth());
+
+    // Set the width again.
+    table.setColumnWidth(column0, 30.1, Unit.PCT);
+    assertEquals("30.1%", col0.getStyle().getWidth().toLowerCase());
+    assertEquals("", col1.getStyle().getWidth());
+  }
+
+  public void testSetTableLayoutFixed() {
+    CellTable<String> table = createAbstractHasData(new TextCell());
+    assertNotSame("fixed",
+        table.getElement().getStyle().getTableLayout());
+
+    table.setTableLayoutFixed(true);
+    assertEquals("fixed",
+        table.getElement().getStyle().getTableLayout());
+
+    table.setTableLayoutFixed(false);
+    assertNotSame("fixed",
+        table.getElement().getStyle().getTableLayout());
+  }

   public void testSortableColumn() {
     CellTable<String> table = createAbstractHasData(new TextCell());

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

Reply via email to