Revision: 8485
Author: [email protected]
Date: Thu Aug 5 05:32:03 2010
Log: Allowing DefaultSuggestionDisplay to stay open even when empty (no
suggestions).
Review at http://gwt-code-reviews.appspot.com/698803
Review by: [email protected]
http://code.google.com/p/google-web-toolkit/source/detail?r=8485
Modified:
/trunk/user/src/com/google/gwt/user/client/ui/SuggestBox.java
=======================================
--- /trunk/user/src/com/google/gwt/user/client/ui/SuggestBox.java Mon Mar
29 09:42:22 2010
+++ /trunk/user/src/com/google/gwt/user/client/ui/SuggestBox.java Thu Aug
5 05:32:03 2010
@@ -276,6 +276,14 @@
* partner.
*/
private SuggestBox lastSuggestBox = null;
+
+ /**
+ * Sub-classes making use of {...@link decorateSuggestionList} to add
+ * elements to the suggestion popup _may_ want those elements to show
even
+ * when there are 0 suggestions. An example would be showing a "No
+ * matches" message.
+ */
+ private boolean hideWhenEmpty = true;
/**
* Construct a new {...@link DefaultSuggestionDisplay}.
@@ -294,6 +302,16 @@
public boolean isAnimationEnabled() {
return suggestionPopup.isAnimationEnabled();
}
+
+ /**
+ * Check whether or not the suggestion list is hidden when there are no
+ * suggestions to display.
+ *
+ * @return true if hidden when empty, false if not
+ */
+ public boolean isSuggestionListHiddenWhenEmpty() {
+ return hideWhenEmpty;
+ }
/**
* Check whether or not the list of suggestions is being shown.
@@ -318,6 +336,16 @@
suggestionPopup.setStyleName(style);
}
+ /**
+ * Set whether or not the suggestion list should be hidden when there
are
+ * no suggestions to display. Defaults to true.
+ *
+ * @param hideWhenEmpty true to hide when empty, false not to
+ */
+ public void setSuggestionListHiddenWhenEmpty(boolean hideWhenEmpty) {
+ this.hideWhenEmpty = hideWhenEmpty;
+ }
+
/**
* Create the PopupPanel that will hold the list of suggestions.
*
@@ -412,7 +440,8 @@
boolean isDisplayStringHTML, boolean isAutoSelectEnabled,
final SuggestionCallback callback) {
// Hide the popup if there are no suggestions to display.
- if (suggestions == null || suggestions.size() == 0) {
+ boolean anySuggestions = (suggestions != null && suggestions.size()
0);
+ if (!anySuggestions && hideWhenEmpty) {
hideSuggestions();
return;
}
@@ -438,7 +467,7 @@
suggestionMenu.addItem(menuItem);
}
- if (isAutoSelectEnabled) {
+ if (isAutoSelectEnabled && anySuggestions) {
// Select the first item in the suggestion menu.
suggestionMenu.selectItem(0);
}
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors