public class TokenField
extends com.vaadin.v7.ui.CustomField
implements com.vaadin.v7.data.Container.Editor
TokenField defaults to using CssLayout, but virtually any Layout can be used.
Can be customized in several ways by overriding certain methods. When the user select or enters a new token, the following happens:
setNewTokensAllowed(boolean)
), nothing happens - otherwiseonTokenInput(Object)
is called, by default it just callsaddToken(Object)
which will eventually cause a call toconfigureTokenButton(Object, Button)
setRememberNewTokens(boolean)
is on - this means previous method
calls can know whether or not the token is new by examining the container.onTokenInput(Object)
and onTokenClick(Object)
respectively.
In much the same way, #onTokenDelete()
is called when the user
presses delete or backspace when the input is empty, and can be customized.
The content of the input (ComboBox) can be bound to a Container datasource,
and filtering can be used. Note that the TokenField can select values that
are not present in the ComboBox.
The content of the input (ComboBox) can be bound to a Container datasource,
and filtering can be used. Note that the TokenField can select values that
are not present in the ComboBox.
The content of the input (ComboBox) can be bound to a Container datasource,
and filtering can be used. Note that the TokenField can select values that
are not present in the ComboBox.
The content of the input (ComboBox) can be bound to a Container datasource,
and filtering can be used. Note that the TokenField can select values that
are not present in the ComboBox.
The content of the input (ComboBox) can be bound to a Container datasource,
and filtering can be used. Note that the TokenField can select values that
are not present in the ComboBox.
The content of the input (ComboBox) can be bound to a Container datasource,
and filtering can be used. Note that the TokenField can select values that
are not present in the ComboBox.
The content of the input (ComboBox) can be bound to a Container datasource,
and filtering can be used. Note that the TokenField can select values that
are not present in the ComboBox.
The content of the input (ComboBox) can be bound to a Container datasource,
and filtering can be used. Note that the TokenField can select values that
are not present in the ComboBox.
Also note that if you use {@link #setTokenCaptionPropertyId(Object)} (to use
a specific property as token caption) AND allow new tokens to be input (
{@link #setNewTokensAllowed(boolean)}, you should probably use a custom
{@link NewItemHandler) ({@link #setNewTokenHandler(NewItemHandler)}) in
order to provide a sensible caption for the new token.
TokenField is a full-fledged field - it can be bound to a Property datasource, and supports buffering.
Note "token" and "tokenId" is often used interchangeably in the documentation
- usually the token is just a string that is the id as well. The term
Token as used in the method names is often interchangeable with the
term item seen elsewhere in the Vaadin API; e.g
{@link #setTokenCaption(Object, String)} works exactly as
{@link ComboBox#setItemCaption(Object, String)}, and tokenId
is
the same as itemId
.
Modifier and Type | Class and Description |
---|---|
static class |
TokenField.InsertPosition |
com.vaadin.v7.ui.AbstractField.FocusShortcut, com.vaadin.v7.ui.AbstractField.ReadOnlyStatusChangeEvent
com.vaadin.ui.HasComponents.ComponentAttachDetachNotifier, com.vaadin.ui.HasComponents.ComponentAttachEvent, com.vaadin.ui.HasComponents.ComponentAttachListener, com.vaadin.ui.HasComponents.ComponentDetachEvent, com.vaadin.ui.HasComponents.ComponentDetachListener
com.vaadin.ui.Component.ErrorEvent, com.vaadin.ui.Component.Event, com.vaadin.ui.Component.Focusable, com.vaadin.ui.Component.Listener
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
com.vaadin.server.Sizeable.Unit
com.vaadin.v7.ui.Field.ValueChangeEvent
com.vaadin.v7.data.Buffered.SourceException
com.vaadin.v7.data.Property.Editor, com.vaadin.v7.data.Property.ReadOnlyException, com.vaadin.v7.data.Property.ReadOnlyStatusChangeListener, com.vaadin.v7.data.Property.ReadOnlyStatusChangeNotifier, com.vaadin.v7.data.Property.Transactional<T>, com.vaadin.v7.data.Property.ValueChangeListener, com.vaadin.v7.data.Property.ValueChangeNotifier, com.vaadin.v7.data.Property.Viewer
Modifier and Type | Field and Description |
---|---|
protected LinkedHashMap<Object,com.vaadin.ui.Button> |
buttons
Maps the tokenId (itemId) to the token button
|
protected TokenComboBox |
cb
The ComboBox used for input - should probably not be touched.
|
protected TokenField.InsertPosition |
insertPosition
Current insert position
|
protected com.vaadin.ui.Layout |
layout
The layout currently in use
|
protected boolean |
rememberNewTokens |
static String |
STYLE_BUTTON_EMPHAZISED |
static String |
STYLE_TOKENFIELD |
static String |
STYLE_TOKENTEXTFIELD |
Constructor and Description |
---|
TokenField()
Create a new TokenField.
|
TokenField(com.vaadin.ui.Layout lo)
Create a new TokenField with the given layout.
|
TokenField(com.vaadin.ui.Layout lo,
TokenField.InsertPosition insertPosition)
Create a new TokenField with the given layout, and the specified token
insert position.
|
TokenField(String caption)
Create a new TokenField with a caption.
|
TokenField(String caption,
com.vaadin.ui.Layout lo)
Create a new TokenField with a caption and a given layout.
|
TokenField(String caption,
com.vaadin.ui.Layout lo,
TokenField.InsertPosition insertPosition)
Create a new TokenField with a caption, a given layout, and the specified
token insert position.
|
TokenField(String caption,
TokenField.InsertPosition insertPosition)
Create a new TokenField with a caption and a
TokenField.InsertPosition . |
Modifier and Type | Method and Description |
---|---|
void |
addToken(Object tokenId)
Adds a token if that token does not already exist.
|
protected void |
configureTokenButton(Object tokenId,
com.vaadin.ui.Button button)
Configures the token button.
|
void |
focus() |
com.vaadin.v7.data.Container |
getContainerDataSource()
Gets the Container data source currently used for the input box.
|
com.vaadin.v7.shared.ui.combobox.FilteringMode |
getFilteringMode()
Works as
ComboBox.getFilteringMode() . |
String |
getInputPrompt()
Gets the input prompt; works as
ComboBox.getInputPrompt() . |
com.vaadin.ui.Layout |
getLayout()
Gets the layout currently in use.
|
int |
getTabIndex() |
String |
getTokenCaption(Object tokenId)
Gets the caption for the given token; the caption can be based on a
property, just as in a ComboBox.
|
com.vaadin.v7.ui.AbstractSelect.ItemCaptionMode |
getTokenCaptionMode() |
Object |
getTokenCaptionPropertyId() |
com.vaadin.server.Resource |
getTokenIcon(Object tokenId) |
Object |
getTokenIconPropertyId() |
Collection |
getTokenIds()
Gets all tokenIds currently in the token container.
|
TokenField.InsertPosition |
getTokenInsertPosition()
Gets the current token
TokenField.InsertPosition .The token buttons are be placed at this position, relative to the input box. |
Class<?> |
getType() |
protected com.vaadin.ui.Component |
initContent() |
boolean |
isNewTokensAllowed()
Checks whether or not new tokens are allowed
|
boolean |
isRememberNewTokens()
If true, new tokens entered by the user are automatically added to the
container.
|
protected void |
onTokenClick(Object tokenId)
Called when the token button is clicked, which by default removes the
token by calling
removeToken(Object) . |
protected void |
onTokenDelete(Object tokenId)
Called with the last added token when the delete or backspace -key
(depending in insert position) is pressed in an empty input.
|
protected void |
onTokenInput(Object tokenId)
Called when the user is adding a new token via the UI; called after the
newItemHandler.
|
protected void |
rememberToken(String tokenId) |
void |
removeToken(Object tokenId)
Removes the given token.
|
void |
setContainerDataSource(com.vaadin.v7.data.Container c)
Sets the Container data source used for the input box.
|
void |
setFilteringMode(com.vaadin.v7.shared.ui.combobox.FilteringMode filteringMode)
Works as
ComboBox#setFilteringMode(int) . |
void |
setHeight(float height,
com.vaadin.server.Sizeable.Unit unit) |
void |
setInputHeight(float height,
com.vaadin.server.Sizeable.Unit unit) |
void |
setInputHeight(String height) |
void |
setInputPrompt(String inputPrompt)
Sets the input prompt; works as
ComboBox.setInputPrompt(String) . |
void |
setInputSizeFull() |
void |
setInputSizeUndefined() |
void |
setInputWidth(float width,
com.vaadin.server.Sizeable.Unit unit) |
void |
setInputWidth(String width) |
protected void |
setInternalValue(Object newValue) |
protected void |
setLayout(com.vaadin.ui.Layout newLayout)
Sets layout used for laying out the tokens and the input.
|
void |
setNewTokensAllowed(boolean allowNewTokens)
Sets whether or not tokens entered by the user that not present in the
container are allowed.
|
void |
setReadOnly(boolean readOnly) |
void |
setRememberNewTokens(boolean rememberNewTokens)
Provided new tokens are allowed (
setNewTokensAllowed(boolean) ),
this sets whether or not new tokens entered by the user are automatically
added to the container. |
void |
setSizeFull() |
void |
setSizeUndefined() |
void |
setTabIndex(int tabIndex) |
void |
setTokenCaption(Object tokenId,
String caption)
sets the caption for the given token.
|
void |
setTokenCaptionMode(com.vaadin.v7.ui.AbstractSelect.ItemCaptionMode mode) |
void |
setTokenCaptionPropertyId(Object propertyId) |
void |
setTokenIcon(Object tokenId,
com.vaadin.server.Resource icon) |
void |
setTokenIconPropertyId(Object propertyId) |
void |
setTokenInsertPosition(TokenField.InsertPosition insertPosition)
Sets the token
TokenField.InsertPosition .The token buttons will be placed at this position, relative to the input box. |
void |
setWidth(float width,
com.vaadin.server.Sizeable.Unit unit) |
attach, getContent, iterator, setFocusDelegate
addListener, addListener, addReadOnlyStatusChangeListener, addValidator, addValueChangeListener, beforeClientResponse, clear, commit, detach, discard, fireReadOnlyStatusChange, fireValueChange, getConversionError, getConversionError, getConvertedValue, getConverter, getCurrentBufferedSourceException, getCustomAttributes, getErrorMessage, getInternalValue, getModelType, getPropertyDataSource, getRequiredError, getState, getState, getValidators, getValue, isBuffered, isEmpty, isInvalidAllowed, isInvalidCommitted, isModified, isReadOnly, isRequired, isValid, isValidationVisible, readDesign, readOnlyStatusChange, removeAllValidators, removeListener, removeListener, removeReadOnlyStatusChangeListener, removeValidator, removeValueChangeListener, setBuffered, setConversionError, setConvertedValue, setConverter, setConverter, setCurrentBufferedSourceException, setInvalidAllowed, setInvalidCommitted, setLocale, setPropertyDataSource, setRequired, setRequiredError, setValidationVisible, setValue, setValue, setValue, shouldHideErrors, validate, validate, valueChange, writeDesign
getExplicitImmediateValue, isImmediate, setImmediate
addContextClickListener, addListener, addShortcutListener, addStyleName, findAncestor, fireComponentErrorEvent, fireComponentEvent, getActionManager, getCaption, getComponentError, getData, getDebugId, getDescription, getHeight, getHeightUnits, getIcon, getId, getLocale, getParent, getPrimaryStyleName, getStyleName, getWidth, getWidthUnits, isCaptionAsHtml, isConnectorEnabled, isEnabled, isOrHasAncestor, isRequiredIndicatorVisible, isResponsive, isVisible, removeContextClickListener, removeListener, removeShortcutListener, removeStyleName, setCaption, setCaptionAsHtml, setComponentError, setData, setDebugId, setDescription, setDescription, setEnabled, setHeight, setHeightUndefined, setIcon, setId, setParent, setPrimaryStyleName, setRequiredIndicatorVisible, setResponsive, setStyleName, setVisible, setWidth, setWidthUndefined
addAttachListener, addDetachListener, addExtension, addListener, addListener, addListener, addMethodInvocationToQueue, createState, encodeState, equals, fireEvent, getAllChildrenIterable, getConnectorId, getErrorHandler, getExtensions, getListeners, getResource, getRpcManager, getRpcProxy, getSession, getStateType, getUI, handleConnectorRequest, hashCode, hasListeners, isAttached, isThis, markAsDirty, markAsDirtyRecursive, registerRpc, registerRpc, removeAttachListener, removeDetachListener, removeExtension, removeListener, removeListener, removeListener, removeListener, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandler, setResource, updateDiffstate
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
addListener, addStyleName, addStyleNames, getCaption, getDescription, getIcon, getId, getLocale, getParent, getPrimaryStyleName, getStyleName, getUI, isEnabled, isVisible, readDesign, removeListener, removeStyleName, removeStyleNames, setCaption, setEnabled, setIcon, setId, setParent, setPrimaryStyleName, setStyleName, setStyleName, setVisible, writeDesign
addAttachListener, addDetachListener, beforeClientResponse, detach, encodeState, getErrorHandler, getExtensions, getRpcManager, getStateType, handleConnectorRequest, isAttached, isConnectorEnabled, markAsDirty, markAsDirtyRecursive, removeAttachListener, removeDetachListener, removeExtension, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandler
getHeight, getHeightUnits, getWidth, getWidthUnits, setHeight, setHeightUndefined, setWidth, setWidthUndefined
forEach, spliterator
public static final String STYLE_TOKENFIELD
public static final String STYLE_TOKENTEXTFIELD
public static final String STYLE_BUTTON_EMPHAZISED
protected com.vaadin.ui.Layout layout
protected TokenField.InsertPosition insertPosition
protected TokenComboBox cb
protected LinkedHashMap<Object,com.vaadin.ui.Button> buttons
protected boolean rememberNewTokens
public TokenField(String caption, TokenField.InsertPosition insertPosition)
TokenField.InsertPosition
.caption
- the desired captioninsertPosition
- the desired insert positionpublic TokenField(String caption)
caption
- the desired captionpublic TokenField()
public TokenField(String caption, com.vaadin.ui.Layout lo)
caption
- the desired captionlo
- the desired layoutpublic TokenField(String caption, com.vaadin.ui.Layout lo, TokenField.InsertPosition insertPosition)
caption
- the desired captionlo
- the desired layoutinsertPosition
- the desired token insert positionpublic TokenField(com.vaadin.ui.Layout lo, TokenField.InsertPosition insertPosition)
lo
- the desired layoutinsertPosition
- the desired token insert positionpublic TokenField(com.vaadin.ui.Layout lo)
lo
- the desired layoutprotected void rememberToken(String tokenId)
protected void setInternalValue(Object newValue)
setInternalValue
in class com.vaadin.v7.ui.AbstractField
protected void onTokenInput(Object tokenId)
addToken(Object)
which will add the token
if it's not a duplicate.tokenId
- the token id selected (or input)protected void onTokenClick(Object tokenId)
removeToken(Object)
. The behavior can be
customized, e.g present a confirmation dialog.tokenId
- the id of the token that was clickedprotected void onTokenDelete(Object tokenId)
onTokenClick(Object)
with the last added token, i.e
remove last. The behavior can be customized, e.g present a confirmation
dialog.public void addToken(Object tokenId)
Note that tokens are not automatically added to the token container. This
means you can add tokens without adding them to the container (that might
be bound to some data store), and without making them available to the
user in the suggestion dropdown.
This also means that when new tokens are disallowed (
setNewTokensAllowed(boolean)
) you can programmatically add
tokens that the user can not add him/herself.
Consider adding the token to the container before calling
addToken(Object)
if you're using a custom captions based on
container/item properties, or if you want the token to be available to
the user as a suggestion later.
tokenId
- the token to addpublic void removeToken(Object tokenId)
Note that the token is not removed from the container, so if it exists in the container, the token will still be available to the user.
tokenId
- the token to removeprotected void configureTokenButton(Object tokenId, com.vaadin.ui.Button button)
By default, the caption, icon, description, and style is set. Override to
customize.
Note that the default click-listener is added elsewhere and can not be
changed here.
tokenId
- the token this button pertains tobutton
- the button to be configuredpublic com.vaadin.ui.Layout getLayout()
protected void setLayout(com.vaadin.ui.Layout newLayout)
newLayout
- the layout to usepublic TokenField.InsertPosition getTokenInsertPosition()
TokenField.InsertPosition
.setTokenInsertPosition(InsertPosition)
,
TokenField.InsertPosition
public void setTokenInsertPosition(TokenField.InsertPosition insertPosition)
TokenField.InsertPosition
.public void setReadOnly(boolean readOnly)
setReadOnly
in interface com.vaadin.v7.data.Property
setReadOnly
in class com.vaadin.v7.ui.AbstractField
public void setContainerDataSource(com.vaadin.v7.data.Container c)
AbstractSelect.setContainerDataSource(Container)
.setContainerDataSource
in interface com.vaadin.v7.data.Container.Viewer
c
- the token container data sourceAbstractSelect.setContainerDataSource(Container)
public com.vaadin.v7.data.Container getContainerDataSource()
AbstractSelect.getContainerDataSource()
.getContainerDataSource
in interface com.vaadin.v7.data.Container.Viewer
AbstractSelect.getContainerDataSource()
public void setNewTokensAllowed(boolean allowNewTokens)
setRememberNewTokens(boolean)
is true, the new token will be
added to the container as well.allowNewTokens
- true to allow tokens that are not in the container#setNewTokenHandler(NewItemHandler)
public boolean isNewTokensAllowed()
setNewTokensAllowed(boolean)
public boolean isRememberNewTokens()
public void setRememberNewTokens(boolean rememberNewTokens)
setNewTokensAllowed(boolean)
),
this sets whether or not new tokens entered by the user are automatically
added to the container.rememberNewTokens
- true to add new tokens automaticallypublic void setFilteringMode(com.vaadin.v7.shared.ui.combobox.FilteringMode filteringMode)
ComboBox#setFilteringMode(int)
.filteringMode
- the desired filtering modeComboBox#setFilteringMode(int)
public com.vaadin.v7.shared.ui.combobox.FilteringMode getFilteringMode()
ComboBox.getFilteringMode()
.filteringMode
- the desired filtering modeComboBox.getFilteringMode()
public void focus()
focus
in interface com.vaadin.ui.Component.Focusable
focus
in class com.vaadin.v7.ui.CustomField
public String getInputPrompt()
ComboBox.getInputPrompt()
.ComboBox.getInputPrompt()
public String getTokenCaption(Object tokenId)
tokenId
- the id of the tokenpublic com.vaadin.v7.ui.AbstractSelect.ItemCaptionMode getTokenCaptionMode()
AbstractSelect.getItemCaptionMode()
public Object getTokenCaptionPropertyId()
AbstractSelect.getItemCaptionPropertyId()
public com.vaadin.server.Resource getTokenIcon(Object tokenId)
AbstractSelect.getItemIcon(Object)
public Object getTokenIconPropertyId()
AbstractSelect.getItemIconPropertyId()
public Collection getTokenIds()
public int getTabIndex()
getTabIndex
in interface com.vaadin.ui.Component.Focusable
getTabIndex
in class com.vaadin.v7.ui.CustomField
public void setHeight(float height, com.vaadin.server.Sizeable.Unit unit)
setHeight
in interface com.vaadin.server.Sizeable
setHeight
in class com.vaadin.v7.ui.CustomField
public void setWidth(float width, com.vaadin.server.Sizeable.Unit unit)
setWidth
in interface com.vaadin.server.Sizeable
setWidth
in class com.vaadin.v7.ui.CustomField
public void setSizeFull()
setSizeFull
in interface com.vaadin.server.Sizeable
setSizeFull
in class com.vaadin.ui.AbstractComponent
public void setSizeUndefined()
setSizeUndefined
in interface com.vaadin.server.Sizeable
setSizeUndefined
in class com.vaadin.ui.AbstractComponent
public void setInputHeight(String height)
public void setInputWidth(String width)
public void setInputHeight(float height, com.vaadin.server.Sizeable.Unit unit)
public void setInputWidth(float width, com.vaadin.server.Sizeable.Unit unit)
public void setInputSizeFull()
public void setInputSizeUndefined()
public void setInputPrompt(String inputPrompt)
ComboBox.setInputPrompt(String)
.ComboBox.setInputPrompt(String)
public void setTokenCaption(Object tokenId, String caption)
tokenId
- token whose caption to setcaption
- the desired captionAbstractSelect.setItemCaption(Object, String)
public void setTokenCaptionMode(com.vaadin.v7.ui.AbstractSelect.ItemCaptionMode mode)
mode
- ComboBox#setItemCaptionMode(int)
public void setTokenCaptionPropertyId(Object propertyId)
propertyId
- AbstractSelect.setItemCaptionPropertyId(Object)
public void setTokenIcon(Object tokenId, com.vaadin.server.Resource icon)
tokenId
- icon
- AbstractSelect.setItemIcon(Object, Resource)
public void setTokenIconPropertyId(Object propertyId)
propertyId
- AbstractSelect.setItemIconPropertyId(Object)
public void setTabIndex(int tabIndex)
setTabIndex
in interface com.vaadin.ui.Component.Focusable
setTabIndex
in class com.vaadin.v7.ui.CustomField
public Class<?> getType()
getType
in interface com.vaadin.v7.data.Property
getType
in class com.vaadin.v7.ui.AbstractField
protected com.vaadin.ui.Component initContent()
initContent
in class com.vaadin.v7.ui.CustomField
Copyright © 2020 Magnolia International Ltd.. All rights reserved.