Added documentation to HTMLTable.addTableListener() to explain that getCellForEvent() can return null.  We also check for null in the mail sample.

Patch by: jlabanca
Review by: ecc (desk)



git-svn-id: https://google-web-toolkit.googlecode.com/svn/releases/1.6@4625 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/samples/mail/src/com/google/gwt/sample/mail/client/MailList.java b/samples/mail/src/com/google/gwt/sample/mail/client/MailList.java
index 92f8330..43fa86a 100644
--- a/samples/mail/src/com/google/gwt/sample/mail/client/MailList.java
+++ b/samples/mail/src/com/google/gwt/sample/mail/client/MailList.java
@@ -21,6 +21,7 @@
 import com.google.gwt.user.client.ui.FlexTable;
 import com.google.gwt.user.client.ui.HTML;
 import com.google.gwt.user.client.ui.HorizontalPanel;
+import com.google.gwt.user.client.ui.HTMLTable.Cell;
 
 /**
  * A composite that displays a list of emails that can be selected.
@@ -91,9 +92,12 @@
       }
     } else if (sender == table) {
       // Select the row that was clicked (-1 to account for header row).
-      int row = table.getCellForEvent(event).getRowIndex();
-      if (row > 0) {
-        selectRow(row - 1);
+      Cell cell = table.getCellForEvent(event);
+      if (cell != null) {
+        int row = cell.getRowIndex();
+        if (row > 0) {
+          selectRow(row - 1);
+        }
       }
     }
   }
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 f5efad3..41066ff 100644
--- a/user/src/com/google/gwt/user/client/ui/HTMLTable.java
+++ b/user/src/com/google/gwt/user/client/ui/HTMLTable.java
@@ -700,7 +700,7 @@
    * @param listener listener to add
    * @deprecated add a click handler instead and use
    *             {@link HTMLTable#getCellForEvent(ClickEvent)} to get the cell
-   *             information
+   *             information (remember to check for a null return value)
    */
   @Deprecated
   public void addTableListener(TableListener listener) {
@@ -748,7 +748,8 @@
 
   /**
    * Given a click event, return the Cell that was clicked, or null if the event
-   * did not hit this table.
+   * did not hit this table.  The cell can also be null if the click event does
+   * not occur on a specific cell.
    * 
    * @param event A click event of indeterminate origin
    * @return The appropriate cell, or null
diff --git a/user/src/com/google/gwt/user/client/ui/ListenerWrapper.java b/user/src/com/google/gwt/user/client/ui/ListenerWrapper.java
index 2feaea5..a3a5435 100644
--- a/user/src/com/google/gwt/user/client/ui/ListenerWrapper.java
+++ b/user/src/com/google/gwt/user/client/ui/ListenerWrapper.java
@@ -464,14 +464,16 @@
     public void onMouseDown(MouseDownEvent event) {

       Widget source = getSource(event);

       Element elem = source.getElement();

-      getListener().onMouseDown(source, Event.getRelativeX(event.getNativeEvent(), elem),

+      getListener().onMouseDown(source,

+          Event.getRelativeX(event.getNativeEvent(), elem),

           Event.getRelativeY(event.getNativeEvent(), elem));

     }

 

     public void onMouseMove(MouseMoveEvent event) {

       Widget source = getSource(event);

       Element elem = source.getElement();

-      getListener().onMouseMove(source, Event.getRelativeX(event.getNativeEvent(), elem),

+      getListener().onMouseMove(source,

+          Event.getRelativeX(event.getNativeEvent(), elem),

           Event.getRelativeY(event.getNativeEvent(), elem));

     }

 

@@ -486,7 +488,8 @@
     public void onMouseUp(MouseUpEvent event) {

       Widget source = getSource(event);

       Element elem = source.getElement();

-      getListener().onMouseUp(source, Event.getRelativeX(event.getNativeEvent(), elem),

+      getListener().onMouseUp(source,

+          Event.getRelativeX(event.getNativeEvent(), elem),

           Event.getRelativeY(event.getNativeEvent(), elem));

     }

   }

@@ -709,8 +712,10 @@
     public void onClick(ClickEvent event) {

       HTMLTable table = (HTMLTable) event.getSource();

       HTMLTable.Cell cell = table.getCellForEvent(event);

-      getListener().onCellClicked(table, cell.getRowIndex(),

-          cell.getCellIndex());

+      if (cell != null) {

+        getListener().onCellClicked(table, cell.getRowIndex(),

+            cell.getCellIndex());

+      }

     }

   }