Modifying DefaultHeaderCreator to support null sorting indicator images.  Until a recent change, CellTable would not throw any errors if the sort indicators in the Resources returned null, as long as the CellTable was never sorted.  However, DefaultHeaderCreator aggressively caches the height and width of the icons.  While this was never officially supported, its convenient behavior for people trying to reduce code size by removing the inlined image.

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


git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@10586 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/src/com/google/gwt/user/cellview/client/DefaultHeaderCreator.java b/user/src/com/google/gwt/user/cellview/client/DefaultHeaderCreator.java
index f746654..e2dc6e7 100644
--- a/user/src/com/google/gwt/user/cellview/client/DefaultHeaderCreator.java
+++ b/user/src/com/google/gwt/user/cellview/client/DefaultHeaderCreator.java
@@ -71,10 +71,20 @@
      */
     ImageResource asc = table.getResources().sortAscending();
     ImageResource desc = table.getResources().sortDescending();
-    sortAscIconWidth = asc.getWidth() + ICON_PADDING;
-    sortDescIconWidth = desc.getWidth() + ICON_PADDING;
-    sortAscIconHalfHeight = (int) Math.round(asc.getHeight() / 2.0);
-    sortDescIconHalfHeight = (int) Math.round(desc.getHeight() / 2.0);
+    if (asc != null) {
+      sortAscIconWidth = asc.getWidth() + ICON_PADDING;
+      sortAscIconHalfHeight = (int) Math.round(asc.getHeight() / 2.0);
+    } else {
+      sortAscIconWidth = 0;
+      sortAscIconHalfHeight = 0;
+    }
+    if (desc != null) {
+      sortDescIconWidth = desc.getWidth() + ICON_PADDING;
+      sortDescIconHalfHeight = (int) Math.round(desc.getHeight() / 2.0);
+    } else {
+      sortDescIconWidth = 0;
+      sortDescIconHalfHeight = 0;
+    }
   }
 
   @Override
diff --git a/user/test/com/google/gwt/user/cellview/client/CellTableTest.java b/user/test/com/google/gwt/user/cellview/client/CellTableTest.java
index caf004b..be3ca28 100644
--- a/user/test/com/google/gwt/user/cellview/client/CellTableTest.java
+++ b/user/test/com/google/gwt/user/cellview/client/CellTableTest.java
@@ -180,6 +180,56 @@
   }
 
   /**
+   * Using a null sort icon should not cause any errors if none of the columns
+   * are sortable.
+   */
+  public void testNullSortIcons() {
+    // Create a Resources instance that does not include sort images.
+    CellTable.Resources resources = new CellTable.Resources() {
+      private final CellTable.Resources defaultRes = GWT.create(CellTable.Resources.class);
+
+      @Override
+      public ImageResource cellTableFooterBackground() {
+        return defaultRes.cellTableFooterBackground();
+      }
+
+      @Override
+      public ImageResource cellTableHeaderBackground() {
+        return defaultRes.cellTableHeaderBackground();
+      }
+
+      @Override
+      public ImageResource cellTableLoading() {
+        return defaultRes.cellTableLoading();
+      }
+
+      @Override
+      public ImageResource cellTableSelectedBackground() {
+        return defaultRes.cellTableSelectedBackground();
+      }
+
+      @Override
+      public ImageResource cellTableSortAscending() {
+        return null;
+      }
+
+      @Override
+      public ImageResource cellTableSortDescending() {
+        return null;
+      }
+
+      @Override
+      public Style cellTableStyle() {
+        return defaultRes.cellTableStyle();
+      }
+    };
+
+    CellTable<String> table = new CellTable<String>(10, resources);
+    populateData(table);
+    table.getPresenter().flush();
+  }
+
+  /**
    * Test that removing a column sets its width to zero.
    */
   public void testRemoveColumnWithWidth() {