java.lang.Object | ||||
↳ | com.google.gwt.user.client.ui.UIObject | |||
↳ | com.google.gwt.user.client.ui.Widget | |||
↳ | com.google.gwt.user.client.ui.Composite | |||
↳ | com.google.gwt.user.client.ui.SuggestBox |
A SuggestBox
is a text box or text area which displays a
pre-configured set of selections that match the user's input.
Each SuggestBox
is associated with a single SuggestOracle
.
The SuggestOracle
is used to provide a set of selections given a
specific query string.
By default, the SuggestBox
uses a MultiWordSuggestOracle
as
its oracle. Below we show how a MultiWordSuggestOracle
can be
configured:
MultiWordSuggestOracle oracle = new MultiWordSuggestOracle(); oracle.add("Cat"); oracle.add("Dog"); oracle.add("Horse"); oracle.add("Canary"); SuggestBox box = new SuggestBox(oracle);Using the example above, if the user types "C" into the text widget, the oracle will configure the suggestions with the "Cat" and "Canary" suggestions. Specifically, whenever the user types a key into the text widget, the value is submitted to the
MultiWordSuggestOracle
.
Note that there is no method to retrieve the "currently selected suggestion"
in a SuggestBox, because there are points in time where the currently
selected suggestion is not defined. For example, if the user types in some
text that does not match any of the SuggestBox's suggestions, then the
SuggestBox will not have a currently selected suggestion. It is more useful
to know when a suggestion has been chosen from the SuggestBox's list of
suggestions. A SuggestBox fires SuggestionEvents
whenever a suggestion is chosen, and handlers for these events can be added
using the addValueChangeHandler(ValueChangeHandler)
method.
Nested Classes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
SuggestBox.DefaultSuggestionDisplay |
The default implementation of |
||||||||||
SuggestBox.SuggestionCallback | The callback used when a user selects a SuggestOracle.Suggestion . |
||||||||||
SuggestBox.SuggestionDisplay | Used to display suggestions to the user. |
[Expand]
Inherited Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
com.google.gwt.user.client.ui.UIObject
|
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Constructor for
SuggestBox . | |||||||||||
Constructor for
SuggestBox . | |||||||||||
Constructor for
SuggestBox . | |||||||||||
Constructor for
SuggestBox . |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
This method is deprecated.
use
getTextBox() ().addChangeHandler instead
| |||||||||||
This method is deprecated.
use
getTextBox() ().addClickHandler instead
| |||||||||||
This method is deprecated.
use
addSelectionHandler(SelectionHandler instead.
| |||||||||||
This method is deprecated.
use
getTextBox() ().addFocusHandler/addBlurHandler()
instead
| |||||||||||
Adds a
KeyDownEvent handler. | |||||||||||
Adds a
KeyPressEvent handler. | |||||||||||
Adds a
KeyUpEvent handler. | |||||||||||
This method is deprecated.
Use
addKeyDownHandler(KeyDownHandler) , addKeyUpHandler(KeyUpHandler) and
addKeyPressHandler(KeyPressHandler) instead
| |||||||||||
Returns a
TakesValueEditor backed by the DateBox. | |||||||||||
Gets the limit for the number of suggestions that should be displayed for
this box.
| |||||||||||
Gets the suggest box's
SuggestOracle . | |||||||||||
Get the
SuggestBox.SuggestionDisplay used to display suggestions. | |||||||||||
Gets the widget's position in the tab index.
| |||||||||||
Gets this object's text.
| |||||||||||
Get the text box associated with this suggest box.
| |||||||||||
Gets this object's value.
| |||||||||||
This method is deprecated.
use
hideSuggestions() instead
| |||||||||||
This method is deprecated.
use
isAnimationEnabled()
instead
| |||||||||||
Returns whether or not the first suggestion will be automatically selected.
| |||||||||||
This method is deprecated.
use
isSuggestionListShowing()
| |||||||||||
This method is deprecated.
Use the
removeHandler() method on the
object returned by getTextBox() ().addChangeHandler
instead
| |||||||||||
This method is deprecated.
Use the
removeHandler() method on the
object returned by getTextBox() ().addClickHandler
instead
| |||||||||||
This method is deprecated.
Use the
removeHandler() method no the
object returned by addSelectionHandler(SelectionHandler instead
| |||||||||||
This method is deprecated.
Use the
removeHandler() method on the
object returned by getTextBox() ().addFocusListener
instead
| |||||||||||
This method is deprecated.
Use the
removeHandler() method on the
object returned by getTextBox() ().add*Handler instead
| |||||||||||
Sets the widget's 'access key'.
| |||||||||||
This method is deprecated.
use
setAnimationEnabled(boolean)
instead
| |||||||||||
Turns on or off the behavior that automatically selects the first suggested
item.
| |||||||||||
Explicitly focus/unfocus this widget.
| |||||||||||
Sets the limit to the number of suggestions the oracle should provide.
| |||||||||||
This method is deprecated.
use
setPopupStyleName(String)
instead
| |||||||||||
Sets the widget's position in the tab index.
| |||||||||||
Sets this object's text.
| |||||||||||
Show the current list of suggestions.
| |||||||||||
Creates a
SuggestBox widget that wraps an existing <input
type='text'> element. |
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Called when the user sets the id using the
ensureDebugId(String)
method. |
Constructor for SuggestBox
. Creates a
MultiWordSuggestOracle
and TextBox
to use with this
SuggestBox
.
Constructor for SuggestBox
. Creates a TextBox
to use with
this SuggestBox
.
oracle | the oracle for this SuggestBox
|
---|
Constructor for SuggestBox
. The text box will be removed from it's
current location and wrapped by the SuggestBox
.
oracle | supplies suggestions based upon the current contents of the text widget |
---|---|
box | the text widget |
Constructor for SuggestBox
. The text box will be removed from it's
current location and wrapped by the SuggestBox
.
oracle | supplies suggestions based upon the current contents of the text widget |
---|---|
box | the text widget |
suggestDisplay | the class used to display suggestions |
This method is deprecated.
use getTextBox()
().addChangeHandler instead
Adds a listener to receive change events on the SuggestBox's text box. The source Widget for these events will be the SuggestBox.
listener | the listener interface to add |
---|
This method is deprecated.
use getTextBox()
().addClickHandler instead
Adds a listener to receive click events on the SuggestBox's text box. The source Widget for these events will be the SuggestBox.
listener | the listener interface to add |
---|
This method is deprecated.
use addSelectionHandler(SelectionHandler
instead.
Adds an event to this handler.
handler | the handler to add |
---|
This method is deprecated.
use getTextBox()
().addFocusHandler/addBlurHandler()
instead
Adds a listener to receive focus events on the SuggestBox's text box. The source Widget for these events will be the SuggestBox.
listener | the listener interface to add |
---|
Adds a KeyDownEvent
handler.
handler | the key down handler |
---|
HandlerRegistration
used to remove this handler
Adds a KeyPressEvent
handler.
handler | the key press handler |
---|
HandlerRegistration
used to remove this handler
Adds a KeyUpEvent
handler.
handler | the key up handler |
---|
HandlerRegistration
used to remove this handler
This method is deprecated.
Use addKeyDownHandler(KeyDownHandler)
, addKeyUpHandler(KeyUpHandler)
and
addKeyPressHandler(KeyPressHandler)
instead
Adds a listener interface to receive keyboard events.
listener | the listener interface to add |
---|
Returns a TakesValueEditor
backed by the DateBox.
Editor
of type E
Gets the limit for the number of suggestions that should be displayed for
this box. It is up to the current SuggestOracle
to enforce this
limit.
Gets the suggest box's SuggestOracle
.
SuggestOracle
Get the SuggestBox.SuggestionDisplay
used to display suggestions.
Gets the widget's position in the tab index.
Get the text box associated with this suggest box.
This method is deprecated.
use hideSuggestions()
instead
Hide current suggestions in the SuggestBox.DefaultSuggestionDisplay
. Note that
this method is a no-op unless the SuggestBox.DefaultSuggestionDisplay
is used.
This method is deprecated.
use isAnimationEnabled()
instead
Check whether or not the SuggestBox.DefaultSuggestionDisplay
has animations
enabled. Note that this method only has a meaningful return value when the
SuggestBox.DefaultSuggestionDisplay
is used.
Returns whether or not the first suggestion will be automatically selected. This behavior is on by default.
This method is deprecated.
use isSuggestionListShowing()
Check if the SuggestBox.DefaultSuggestionDisplay
is showing. Note that this
method only has a meaningful return value when the
SuggestBox.DefaultSuggestionDisplay
is used.
This method is deprecated.
Use the removeHandler()
method on the
object returned by getTextBox()
().addChangeHandler
instead
Removes a previously added listener interface.
listener | the listener interface to remove |
---|
This method is deprecated.
Use the removeHandler()
method on the
object returned by getTextBox()
().addClickHandler
instead
Removes a previously added listener interface.
listener | the listener interface to remove |
---|
This method is deprecated.
Use the removeHandler()
method no the
object returned by addSelectionHandler(SelectionHandler
instead
Removes a previously added handler interface.
handler | the handler to remove |
---|
This method is deprecated.
Use the removeHandler()
method on the
object returned by getTextBox()
().addFocusListener
instead
Removes a previously added listener interface.
listener | the listener interface to remove |
---|
This method is deprecated.
Use the removeHandler()
method on the
object returned by getTextBox()
().add*Handler instead
Removes a previously added listener interface.
listener | the listener interface to remove |
---|
Sets the widget's 'access key'. This key is used (in conjunction with a browser-specific modifier key) to automatically focus the widget.
key | the widget's access key |
---|
This method is deprecated.
use
setAnimationEnabled(boolean)
instead
Enable or disable animations in the SuggestBox.DefaultSuggestionDisplay
. Note
that this method is a no-op unless the SuggestBox.DefaultSuggestionDisplay
is
used.
enable | true to enable, false to disable |
---|
Turns on or off the behavior that automatically selects the first suggested item. This behavior is on by default.
selectsFirstItem | Whether or not to automatically select the first suggestion |
---|
Explicitly focus/unfocus this widget. Only one widget can have focus at a time, and the widget that does will receive all keyboard events.
focused | whether this widget should take focus or release it |
---|
Sets the limit to the number of suggestions the oracle should provide. It is up to the oracle to enforce this limit.
limit | the limit to the number of suggestions provided |
---|
This method is deprecated.
use setPopupStyleName(String)
instead
Sets the style name of the suggestion popup in the
SuggestBox.DefaultSuggestionDisplay
. Note that this method is a no-op unless
the SuggestBox.DefaultSuggestionDisplay
is used.
style | the new primary style name |
---|
Sets the widget's position in the tab index. If more than one widget has
the same tab index, each such widget will receive focus in an arbitrary
order. Setting the tab index to -1
will cause this widget to
be removed from the tab order.
index | the widget's tab index |
---|
Show the current list of suggestions.
Creates a SuggestBox
widget that wraps an existing <input
type='text'> element.
This element must already be attached to the document. If the element is
removed from the document, you must call
detachNow(Widget)
.
oracle | the suggest box oracle to use |
---|---|
element | the element to be wrapped |
Called when the user sets the id using the ensureDebugId(String)
method. Subclasses of UIObject
can override this method to add IDs
to their sub elements. If a subclass does override this method, it should
list the IDs (relative to the base ID), that will be applied to each sub
Element
with a short description. For example:
<inherits name="com.google.gwt.user.Debug"/>
baseID | the base ID used by the main element |
---|