@JavaScript(value="vaadin://addons/autocompletetextfield/dist/AutocompleteTextFieldExtension.min.js") @StyleSheet(value="vaadin://addons/autocompletetextfield/dist/AutocompleteTextFieldExtension.css") public class AutocompleteTextFieldExtension extends com.vaadin.server.AbstractJavaScriptExtension implements AutocompleteEvents.SelectNotifier
AbstractTextField
with autocomplete (aka word completion)
functionality.
Uses a modified version of autoComplete originally developed by Simon Steinberger
autoComplete
is released under the MIT License.
com.vaadin.server.ClientConnector.AttachEvent, com.vaadin.server.ClientConnector.AttachListener, com.vaadin.server.ClientConnector.ConnectorErrorEvent, com.vaadin.server.ClientConnector.DetachEvent, com.vaadin.server.ClientConnector.DetachListener
Modifier and Type | Field and Description |
---|---|
protected AutocompleteSuggestionProvider |
suggestionProvider
The suggestion provider queried for suggestions.
|
Constructor and Description |
---|
AutocompleteTextFieldExtension()
Construct a new
AutocompleteTextFieldExtension . |
AutocompleteTextFieldExtension(com.vaadin.ui.AbstractTextField target)
Construct a new
AutocompleteTextFieldExtension and extends the
given AbstractTextField . |
Modifier and Type | Method and Description |
---|---|
void |
addMenuStyleName(String styleName)
Adds one or more style names to the dropdown menu container.
|
com.vaadin.shared.Registration |
addSelectListener(AutocompleteEvents.SelectListener listener)
Adds a
AutocompleteEvents.SelectListener to this component. |
void |
extend(com.vaadin.ui.AbstractTextField target)
Extends the given textfield.
|
protected void |
fireSelectEvent(AutocompleteSuggestion suggestion) |
protected void |
fireSelectEvent(String key) |
int |
getDelay()
Gets the delay in milliseconds between when a keystroke occurs and when a
search is performed.
|
String |
getMenuStyleName()
Gets all user-defined CSS style names of the dropdown menu container.
|
int |
getMinChars()
Gets the minimum number of characters (>=1) a user must type before a
search is performed.
|
com.vaadin.ui.AbstractTextField |
getParent() |
ScrollBehavior |
getScrollBehavior()
Gets the
ScrollBehavior that is used when the user scrolls the
page while the suggestion box is open. |
protected AutocompleteTextFieldExtensionState |
getState() |
protected AutocompleteTextFieldExtensionState |
getState(boolean markAsDirty) |
Class<? extends AutocompleteTextFieldExtensionState> |
getStateType() |
int |
getSuggestionLimit()
Gets the maximum number of suggestions that are allowed.
|
AutocompleteSuggestionProvider |
getSuggestionProvider()
Gets the active
AutocompleteSuggestionProvider . |
protected Class<? extends com.vaadin.ui.AbstractTextField> |
getSupportedParentType() |
boolean |
isItemAsHtml()
Checks whether items are rendered as HTML.
|
boolean |
isTypeSearch()
Gets if the fields type is
"search" . |
protected Set<AutocompleteSuggestion> |
querySuggestions(AutocompleteQuery query)
Executes the given
AutocompleteQuery and makes sure the result is
within the boundries of the AutocompleteQuery 's limit. |
protected Set<AutocompleteSuggestion> |
querySuggestions(String term)
Creates an
AutocompleteQuery from the given search term and the
internal suggestionLimit and executes it. |
void |
removeMenuStyleName(String styleName)
Removes one or more style names from the dropdown menu container.
|
void |
setDelay(int delay)
Sets the delay in milliseconds between when a keystroke occurs and when a
search is performed.
|
void |
setItemAsHtml(boolean itemAsHtml)
Sets whether the items are rendered as HTML.
|
void |
setMinChars(int minChars)
Sets the minimum number of characters (>=1) a user must type before a
search is performed.
|
void |
setScrollBehavior(ScrollBehavior scrollBehavior)
Sets the
ScrollBehavior that is used when the user scrolls the
page while the suggestion box is open. |
void |
setSuggestionLimit(int suggestionLimit)
Sets the maximum number of suggestions that are allowed.
|
void |
setSuggestionProvider(AutocompleteSuggestionProvider suggestionProvider)
Sets the active
AutocompleteSuggestionProvider . |
void |
setTypeSearch(boolean typeSearch)
Sets if the fields type is
"search" . |
protected elemental.json.JsonValue |
suggestionsToJson(Set<AutocompleteSuggestion> suggestions)
Converts the given
AutocompleteSuggestion into a
JsonValue representation because JsonCodec can't handle
it itself. |
AutocompleteTextFieldExtension |
withDelay(int delay)
Sets the delay in milliseconds between when a keystroke occurs and when a
search is performed.
|
AutocompleteTextFieldExtension |
withItemAsHtml(boolean itemAsHtml)
Sets whether the items are rendered as HTML.
|
AutocompleteTextFieldExtension |
withMenuStyleName(String... styleNames)
Adds one or more style names to the dropdown menu container.
|
AutocompleteTextFieldExtension |
withMinChars(int minChars)
Sets the minimum number of characters (>=1) a user must type before a
search is performed.
|
AutocompleteTextFieldExtension |
withScrollBehavior(ScrollBehavior scrollBehavior)
Sets the
ScrollBehavior that is used when the user scrolls the
page while the suggestion box is open. |
AutocompleteTextFieldExtension |
withSearch(boolean typeSearch)
Sets if the fields type is
"search" . |
AutocompleteEvents.SelectNotifier |
withSelectListener(AutocompleteEvents.SelectListener listener)
Adds a
AutocompleteEvents.SelectListener to this component. |
AutocompleteTextFieldExtension |
withSuggestionLimit(int suggestionLimit)
Sets the maximum number of suggestions that are allowed.
|
AutocompleteTextFieldExtension |
withSuggestionProvider(AutocompleteSuggestionProvider suggestionProvider)
Sets the active
AutocompleteSuggestionProvider . |
addFunction, callFunction, registerRpc
addAttachListener, addDetachListener, addExtension, addListener, addListener, addListener, addMethodInvocationToQueue, attach, beforeClientResponse, createState, detach, encodeState, equals, fireEvent, getAllChildrenIterable, getConnectorId, getErrorHandler, getExtensions, getListeners, getResource, getRpcManager, getRpcProxy, getSession, getUI, handleConnectorRequest, hashCode, hasListeners, isAttached, isConnectorEnabled, isThis, markAsDirty, markAsDirtyRecursive, registerRpc, removeAttachListener, removeDetachListener, removeExtension, removeListener, removeListener, removeListener, removeListener, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandler, setResource, updateDiffstate
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
addAttachListener, addDetachListener, attach, beforeClientResponse, detach, encodeState, getErrorHandler, getExtensions, getRpcManager, getUI, handleConnectorRequest, isAttached, isConnectorEnabled, markAsDirty, markAsDirtyRecursive, removeAttachListener, removeDetachListener, removeExtension, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandler
protected AutocompleteSuggestionProvider suggestionProvider
public AutocompleteTextFieldExtension()
AutocompleteTextFieldExtension
.public AutocompleteTextFieldExtension(com.vaadin.ui.AbstractTextField target)
AutocompleteTextFieldExtension
and extends the
given AbstractTextField
.target
- The textfield to extend.public void extend(com.vaadin.ui.AbstractTextField target)
target
- The textfield to extend.public com.vaadin.ui.AbstractTextField getParent()
getParent
in interface com.vaadin.server.ClientConnector
getParent
in interface com.vaadin.shared.Connector
getParent
in class com.vaadin.server.AbstractExtension
protected Class<? extends com.vaadin.ui.AbstractTextField> getSupportedParentType()
getSupportedParentType
in class com.vaadin.server.AbstractExtension
protected AutocompleteTextFieldExtensionState getState()
getState
in class com.vaadin.server.AbstractJavaScriptExtension
protected AutocompleteTextFieldExtensionState getState(boolean markAsDirty)
getState
in class com.vaadin.server.AbstractJavaScriptExtension
public Class<? extends AutocompleteTextFieldExtensionState> getStateType()
getStateType
in interface com.vaadin.server.ClientConnector
getStateType
in class com.vaadin.server.AbstractClientConnector
protected Set<AutocompleteSuggestion> querySuggestions(String term)
AutocompleteQuery
from the given search term and the
internal suggestionLimit
and executes it.
Returns a Set
of AutocompleteSuggestion
s with a
predictable iteration order.term
- The search term.Set
of AutocompleteSuggestion
s with a
predictable iteration order.protected Set<AutocompleteSuggestion> querySuggestions(AutocompleteQuery query)
AutocompleteQuery
and makes sure the result is
within the boundries of the AutocompleteQuery
's limit.
Returns a Set
of AutocompleteSuggestion
s with a
predictable iteration order.
query
- The Query.Set
of AutocompleteSuggestion
s with a
predictable iteration order.protected elemental.json.JsonValue suggestionsToJson(Set<AutocompleteSuggestion> suggestions)
AutocompleteSuggestion
into a
JsonValue
representation because JsonCodec
can't handle
it itself.suggestions
- Suggestions.JsonValue
representation.public AutocompleteSuggestionProvider getSuggestionProvider()
AutocompleteSuggestionProvider
.AutocompleteSuggestionProvider
.public void setSuggestionProvider(AutocompleteSuggestionProvider suggestionProvider)
AutocompleteSuggestionProvider
.suggestionProvider
- The active
AutocompleteSuggestionProvider
.public AutocompleteTextFieldExtension withSuggestionProvider(AutocompleteSuggestionProvider suggestionProvider)
AutocompleteSuggestionProvider
.suggestionProvider
- The active
AutocompleteSuggestionProvider
.setSuggestionProvider(eu.maxschuster.vaadin.autocompletetextfield.AutocompleteSuggestionProvider)
public int getSuggestionLimit()
If the active AutocompleteSuggestionProvider
returns more
suggestions than allowed, the excess suggestions will be ignored!
If limit <= 0
the suggestions won't be limited.
public void setSuggestionLimit(int suggestionLimit)
If the active AutocompleteSuggestionProvider
returns more
suggestions than allowed, the excess suggestions will be ignored!
If limit <= 0 the suggestions won't be limited.
suggestionLimit
- Maximum number of suggestions.public AutocompleteTextFieldExtension withSuggestionLimit(int suggestionLimit)
If the active AutocompleteSuggestionProvider
returns more
suggestions than allowed, the excess suggestions will be ignored!
If limit <= 0 the suggestions won't be limited.
suggestionLimit
- Maximum number of suggestions.setSuggestionLimit(int)
public boolean isItemAsHtml()
The default is false, i.e. to render that caption as plain text.
public void setItemAsHtml(boolean itemAsHtml)
If set to true, the items are rendered in the browser as HTML and the developer is responsible for ensuring no harmful HTML is used. If set to false, the caption is rendered in the browser as plain text.
The default is false, i.e. to render that caption as plain text.
itemAsHtml
- true if the items are rendered as HTML, false if
rendered as plain text.public AutocompleteTextFieldExtension withItemAsHtml(boolean itemAsHtml)
If set to true, the items are rendered in the browser as HTML and the developer is responsible for ensuring no harmful HTML is used. If set to false, the caption is rendered in the browser as plain text.
The default is false, i.e. to render that caption as plain text.
itemAsHtml
- true if the items are rendered as HTML, false if
rendered as plain text.setItemAsHtml(boolean)
public int getMinChars()
public void setMinChars(int minChars)
minChars
- Minimum number of characters.public AutocompleteTextFieldExtension withMinChars(int minChars)
minChars
- Minimum number of characters.setMinChars(int)
public int getDelay()
public void setDelay(int delay)
delay
- Search delay in milliseconds.public AutocompleteTextFieldExtension withDelay(int delay)
delay
- Search delay in milliseconds.setDelay(int)
public String getMenuStyleName()
public void addMenuStyleName(String styleName)
styleName
- The new style to be added to the dropdown menu
container.public AutocompleteTextFieldExtension withMenuStyleName(String... styleNames)
styleNames
- The new styles to be added to the dropdown menu
container.addMenuStyleName(java.lang.String)
public void removeMenuStyleName(String styleName)
styleName
- The style name or style names to be removed.public ScrollBehavior getScrollBehavior()
ScrollBehavior
that is used when the user scrolls the
page while the suggestion box is open.ScrollBehavior
.public void setScrollBehavior(ScrollBehavior scrollBehavior)
ScrollBehavior
that is used when the user scrolls the
page while the suggestion box is open.scrollBehavior
- The ScrollBehavior
.public AutocompleteTextFieldExtension withScrollBehavior(ScrollBehavior scrollBehavior)
ScrollBehavior
that is used when the user scrolls the
page while the suggestion box is open.scrollBehavior
- The ScrollBehavior
.setScrollBehavior(eu.maxschuster.vaadin.autocompletetextfield.shared.ScrollBehavior)
public boolean isTypeSearch()
"search"
.true
the fields type is "search"
.public void setTypeSearch(boolean typeSearch)
"search"
.typeSearch
- true
will change this fields type to
"search"
.public AutocompleteTextFieldExtension withSearch(boolean typeSearch)
"search"
.typeSearch
- true
will change this fields type to
"search"
.setTypeSearch(boolean)
protected void fireSelectEvent(String key) throws NoSuchElementException
NoSuchElementException
protected void fireSelectEvent(AutocompleteSuggestion suggestion)
public com.vaadin.shared.Registration addSelectListener(AutocompleteEvents.SelectListener listener)
AutocompleteEvents.SelectNotifier
AutocompleteEvents.SelectListener
to this component.addSelectListener
in interface AutocompleteEvents.SelectNotifier
listener
- A AutocompleteEvents.SelectListener
that should be added to this
component.public AutocompleteEvents.SelectNotifier withSelectListener(AutocompleteEvents.SelectListener listener)
AutocompleteEvents.SelectNotifier
AutocompleteEvents.SelectListener
to this component.
Keep in mind that you can not remove a listener added by this method
as it does not return a registration. If you later have to remove the
listener please use
AutocompleteEvents.SelectNotifier.addSelectListener(eu.maxschuster.vaadin.autocompletetextfield.AutocompleteEvents.SelectListener)
withSelectListener
in interface AutocompleteEvents.SelectNotifier
listener
- A AutocompleteEvents.SelectListener
that should be added to this
component.AutocompleteEvents.SelectNotifier.addSelectListener(eu.maxschuster.vaadin.autocompletetextfield.AutocompleteEvents.SelectListener)
Copyright © 2017 Max Schuster. All Rights Reserved.