Package com.google.gwt.user.client.ui
Class MultiWordSuggestOracle
java.lang.Object
com.google.gwt.user.client.ui.SuggestOracle
com.google.gwt.user.client.ui.MultiWordSuggestOracle
The default
SuggestOracle
. The default
oracle returns potential suggestions based on breaking the query into
separate words and looking for matches. It also modifies the returned text to
show which prefix matched the query term. The matching is case insensitive.
All suggestions are sorted before being passed into a response.
Example Table
All Suggestions | Query string | Matching Suggestions |
John Smith, Joe Brown, Jane Doe, Jane Smith, Bob Jones | Jo | John Smith, Joe Brown, Bob Jones |
John Smith, Joe Brown, Jane Doe, Jane Smith, Bob Jones | Smith | John Smith, Jane Smith |
Georgia, New York, California | g | Georgia |
-
Nested Class Summary
Nested classes/interfaces inherited from class com.google.gwt.user.client.ui.SuggestOracle
SuggestOracle.Callback, SuggestOracle.Request, SuggestOracle.Response, SuggestOracle.Suggestion
-
Constructor Summary
ConstructorDescriptionConstructor forMultiWordSuggestOracle
.MultiWordSuggestOracle
(String whitespaceChars) Constructor forMultiWordSuggestOracle
which takes in a set of whitespace chars that filter its input. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a suggestion to the oracle.final void
addAll
(Collection<String> collection) Adds all suggestions specified.void
clear()
Removes all of the suggestions from the oracle.createSuggestion
(String replacementString, String displayString) Creates the suggestion based on the given replacement and display strings.boolean
ShouldSuggestOracle.Suggestion
display strings be treated as HTML? If true, this all suggestions' display strings will be interpreted as HTML, otherwise as text.void
requestDefaultSuggestions
(SuggestOracle.Request request, SuggestOracle.Callback callback) Generate aSuggestOracle.Response
based on a default request.void
requestSuggestions
(SuggestOracle.Request request, SuggestOracle.Callback callback) Generate aSuggestOracle.Response
based on a specificSuggestOracle.Request
.void
setComparator
(Comparator<String> comparator) Sets the comparator used for sorting candidates from search.void
setDefaultSuggestions
(Collection<SuggestOracle.Suggestion> suggestionList) Sets the default suggestion collection.final void
setDefaultSuggestionsFromText
(Collection<String> suggestionList) A convenience method to set default suggestions using plain text strings.final void
setSuggestAllMatchingWords
(boolean suggestAllMatchingWords) Sets the flag on whether to suggest all matching words.
-
Constructor Details
-
MultiWordSuggestOracle
public MultiWordSuggestOracle()Constructor forMultiWordSuggestOracle
. This uses a space as the whitespace character.- See Also:
-
MultiWordSuggestOracle
Constructor forMultiWordSuggestOracle
which takes in a set of whitespace chars that filter its input.Example: If
".,"
is passed in as whitespace, then the string "foo.bar" would match the queries "foo", "bar", "foo.bar", "foo...bar", and "foo, bar". If the empty string is used, then all characters are used in matching. For example, the query "bar" would match "bar", but not "foo bar".- Parameters:
whitespaceChars
- the characters to treat as word separators
-
-
Method Details
-
add
Adds a suggestion to the oracle. Each suggestion must be plain text.- Parameters:
suggestion
- the suggestion
-
addAll
Adds all suggestions specified. Each suggestion must be plain text.- Parameters:
collection
- the collection
-
clear
public void clear()Removes all of the suggestions from the oracle. -
isDisplayStringHTML
public boolean isDisplayStringHTML()Description copied from class:SuggestOracle
ShouldSuggestOracle.Suggestion
display strings be treated as HTML? If true, this all suggestions' display strings will be interpreted as HTML, otherwise as text.- Overrides:
isDisplayStringHTML
in classSuggestOracle
- Returns:
- by default, returns false
-
requestDefaultSuggestions
public void requestDefaultSuggestions(SuggestOracle.Request request, SuggestOracle.Callback callback) Description copied from class:SuggestOracle
Generate aSuggestOracle.Response
based on a default request. The request query must be null as it represents the results the oracle should return based on no query string.After the
SuggestOracle.Response
is created, it is passed intoSuggestOracle.Callback.onSuggestionsReady(com.google.gwt.user.client.ui.SuggestOracle.Request, com.google.gwt.user.client.ui.SuggestOracle.Response)
.- Overrides:
requestDefaultSuggestions
in classSuggestOracle
- Parameters:
request
- the requestcallback
- the callback to use for the response
-
requestSuggestions
Description copied from class:SuggestOracle
Generate aSuggestOracle.Response
based on a specificSuggestOracle.Request
. After theSuggestOracle.Response
is created, it is passed intoSuggestOracle.Callback.onSuggestionsReady(com.google.gwt.user.client.ui.SuggestOracle.Request, com.google.gwt.user.client.ui.SuggestOracle.Response)
.- Specified by:
requestSuggestions
in classSuggestOracle
- Parameters:
request
- the requestcallback
- the callback to use for the response
-
setComparator
Sets the comparator used for sorting candidates from search.- Parameters:
comparator
- the comparator to use.
-
setDefaultSuggestions
Sets the default suggestion collection.- Parameters:
suggestionList
- the default list of suggestions
-
setDefaultSuggestionsFromText
A convenience method to set default suggestions using plain text strings. Note to use this method each default suggestion must be plain text.- Parameters:
suggestionList
- the default list of suggestions
-
setSuggestAllMatchingWords
public final void setSuggestAllMatchingWords(boolean suggestAllMatchingWords) Sets the flag on whether to suggest all matching words. With words 'Mobile', 'MOBILE', 'mobile', 'MoBILE', typing 'm' will only build one suggestion for 'MoBILE' ifsuggestAllMatchingWords
isfalse
. However, it will build suggestions for all four words ifsuggestAllMatchingWords
istrue
.- Parameters:
suggestAllMatchingWords
- true to return all formatted suggestions per normalized candidate, false to return the last formatted suggestions per normalized candidate.
-
createSuggestion
protected MultiWordSuggestOracle.MultiWordSuggestion createSuggestion(String replacementString, String displayString) Creates the suggestion based on the given replacement and display strings.- Parameters:
replacementString
- the string to enter into the SuggestBox's text box if the suggestion is chosendisplayString
- the display string- Returns:
- the suggestion created
-