Revision: 9453
Author: [email protected]
Date: Thu Dec 16 06:19:53 2010
Log: Fixing a bug in CellTable and CellList where we get an index out of bounds exception if we try to access the keyboard selected element when keyboard selection is disabled.

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

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

Modified:
 /trunk/user/src/com/google/gwt/user/cellview/client/CellList.java
 /trunk/user/src/com/google/gwt/user/cellview/client/CellTable.java
/trunk/user/test/com/google/gwt/user/cellview/client/AbstractHasDataTestBase.java

=======================================
--- /trunk/user/src/com/google/gwt/user/cellview/client/CellList.java Wed Dec 1 05:40:20 2010 +++ /trunk/user/src/com/google/gwt/user/cellview/client/CellList.java Thu Dec 16 06:19:53 2010
@@ -340,7 +340,7 @@
   protected Element getKeyboardSelectedElement() {
     // Do not use getRowElement() because that will flush the presenter.
     int rowIndex = getKeyboardSelectedRow();
-    if (childContainer.getChildCount() > rowIndex) {
+    if (rowIndex >= 0 && childContainer.getChildCount() > rowIndex) {
       return childContainer.getChild(rowIndex).cast();
     }
     return null;
=======================================
--- /trunk/user/src/com/google/gwt/user/cellview/client/CellTable.java Fri Dec 10 06:42:34 2010 +++ /trunk/user/src/com/google/gwt/user/cellview/client/CellTable.java Thu Dec 16 06:19:53 2010
@@ -988,7 +988,7 @@
     // Do not use getRowElement() because that will flush the presenter.
     int rowIndex = getKeyboardSelectedRow();
     NodeList<TableRowElement> rows = tbody.getRows();
-    if (rowIndex < rows.getLength() && columns.size() > 0) {
+ if (rowIndex >= 0 && rowIndex < rows.getLength() && columns.size() > 0) {
       TableRowElement tr = rows.getItem(rowIndex);
       TableCellElement td = tr.getCells().getItem(keyboardSelectedColumn);
       return getCellParent(td);
=======================================
--- /trunk/user/test/com/google/gwt/user/cellview/client/AbstractHasDataTestBase.java Wed Dec 1 05:40:20 2010 +++ /trunk/user/test/com/google/gwt/user/cellview/client/AbstractHasDataTestBase.java Thu Dec 16 06:19:53 2010
@@ -25,6 +25,7 @@
 import com.google.gwt.regexp.shared.MatchResult;
 import com.google.gwt.regexp.shared.RegExp;
 import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
+import com.google.gwt.user.cellview.client.HasKeyboardSelectionPolicy.KeyboardSelectionPolicy;
 import com.google.gwt.user.client.Window;
 import com.google.gwt.view.client.ListDataProvider;
 import com.google.gwt.view.client.Range;
@@ -144,6 +145,21 @@
     assertEquals("test 11", items.get(1));
     assertEquals("test 12", items.get(2));
   }
+
+  /**
+   * Test that we don't get any errors when keyboard selection is disabled.
+   */
+  public void testKeyboardSelectionPolicyDisabled() {
+ AbstractHasData<String> display = createAbstractHasData(new TextCell());
+    display.setRowData(createData(0, 10));
+    display.getPresenter().flush();
+    display.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.DISABLED);
+
+    assertNull(display.getKeyboardSelectedElement());
+    display.resetFocusOnCell();
+    display.setAccessKey('a');
+    display.setTabIndex(1);
+  }

   public void testResetFocus() {
     IndexCell<String> cell = new IndexCell<String>();

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

Reply via email to