Author: [EMAIL PROTECTED]
Date: Mon Oct 27 13:50:30 2008
New Revision: 3873

Modified:
    releases/1.6/user/src/com/google/gwt/user/client/ui/SuggestBox.java

Log:
Address issue 2330 by adding new property, selectsFirstItem, to turn off  
autoselect of first item. Does not change default behavior.

Modified:  
releases/1.6/user/src/com/google/gwt/user/client/ui/SuggestBox.java
==============================================================================
--- releases/1.6/user/src/com/google/gwt/user/client/ui/SuggestBox.java  
(original)
+++ releases/1.6/user/src/com/google/gwt/user/client/ui/SuggestBox.java Mon  
Oct 27 13:50:30 2008
@@ -15,6 +15,7 @@
   */
  package com.google.gwt.user.client.ui;

+import com.google.gwt.i18n.client.LocaleInfo;
  import com.google.gwt.user.client.Command;
  import com.google.gwt.user.client.DOM;
  import com.google.gwt.user.client.Window;
@@ -23,7 +24,6 @@
  import com.google.gwt.user.client.ui.SuggestOracle.Request;
  import com.google.gwt.user.client.ui.SuggestOracle.Response;
  import com.google.gwt.user.client.ui.SuggestOracle.Suggestion;
-import com.google.gwt.i18n.client.LocaleInfo;

  import java.util.ArrayList;
  import java.util.Collection;
@@ -370,6 +370,7 @@
    private static final String STYLENAME_DEFAULT = "gwt-SuggestBox";

    private int limit = 20;
+  private boolean selectsFirstItem = false;
    private SuggestOracle oracle;
    private String currentText;
    private final SuggestionMenu suggestionMenu;
@@ -500,6 +501,16 @@
    }

    /**
+   * Returns whether or not the first suggestion will be automatically
+   * selected. This behavior is off by default.
+   *
+   * @return true if the first suggestion will be automatically selected
+   */
+  public boolean getSelectsFirstItem() {
+    return selectsFirstItem;
+  }
+
+  /**
     * Gets the suggest box's [EMAIL PROTECTED]  
com.google.gwt.user.client.ui.SuggestOracle}.
     *
     * @return the [EMAIL PROTECTED] SuggestOracle}
@@ -582,7 +593,18 @@
    public void setPopupStyleName(String style) {
      suggestionPopup.setStyleName(style);
    }
-
+
+  /**
+   * Turns on or off the behavior that automatically selects the first  
suggested
+   * item. It defaults to off.
+   *
+   * @param selectsFirstItem Whether or not to automatically select the  
first
+   *          suggested
+   */
+  public void setSelectsFirstItem(boolean selectsFirstItem) {
+    this.selectsFirstItem = selectsFirstItem;
+  }
+
    public void setTabIndex(int index) {
      box.setTabIndex(index);
    }
@@ -638,8 +660,10 @@
          suggestionMenu.addItem(menuItem);
        }

-      // Select the first item in the suggestion menu.
-      suggestionMenu.selectItem(0);
+      if (selectsFirstItem) {
+        // Select the first item in the suggestion menu.
+        suggestionMenu.selectItem(0);
+      }

        suggestionPopup.showAlignedPopup();
        suggestionPopup.setAnimationEnabled(isAnimationEnabled);
@@ -665,7 +689,11 @@
                break;
              case KeyboardListener.KEY_ENTER:
              case KeyboardListener.KEY_TAB:
-              suggestionMenu.doSelectedItemAction();
+              if (suggestionMenu.getSelectedItemIndex() < 0) {
+                suggestionPopup.hide();
+              } else {
+                suggestionMenu.doSelectedItemAction();
+              }
                break;
            }
          }

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

Reply via email to