Class GridSingleSelect<T>
- java.lang.Object
-
- com.vaadin.ui.components.grid.GridSingleSelect<T>
-
- Type Parameters:
T- the bean type of grid
- All Implemented Interfaces:
HasValue<T>,SingleSelect<T>,Serializable
public class GridSingleSelect<T> extends Object implements SingleSelect<T>
Wrapper class to wrap Grid into a SingleSelect. This class also provides useful access to API of SingleSelectionModel.- Since:
- 8.6.0
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.vaadin.data.HasValue
HasValue.ValueChangeEvent<V>, HasValue.ValueChangeListener<V>
-
-
Constructor Summary
Constructors Constructor Description GridSingleSelect(Grid<T> grid)Constructs a SingleSelect wrapper for given Grid.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description RegistrationaddSelectionListener(SelectionListener<T> listener)Adds a generic listener to this selection model, accepting both single and multiselection events.RegistrationaddSingleSelectionListener(SingleSelectionListener<T> listener)Adds a single selection listener that is called when the value of this select is changed either by the user or programmatically.RegistrationaddValueChangeListener(HasValue.ValueChangeListener<T> listener)Adds a value change listener.voiddeselect(T item)Selects the given item.voiddeselectAll()Deselects all currently selected items, if any.Optional<T>getFirstSelectedItem()Get first selected data item.Optional<T>getSelectedItem()Returns the currently selected item, or an empty optional if no item is selected.Set<T>getSelectedItems()Returns a singleton set of the currently selected item or an empty set if no item is selected.TgetValue()Returns the current value of this object.booleanisDeselectAllowed()Gets whether it's allowed to deselect the selected row through the UI.booleanisReadOnly()Returns whether thisHasValueis in read-only mode or not.booleanisRequiredIndicatorVisible()Checks whether the required indicator is visible.booleanisSelected(T item)Returns whether the given item is currently selected.booleanisUserSelectionAllowed()Checks if the user is allowed to change the selection.voidselect(T item)Selects the given item.voidsetDeselectAllowed(boolean deselectAllowed)Sets whether it's allowed to deselect the selected row through the UI.voidsetReadOnly(boolean readOnly)Sets the read-only mode of thisHasValueto given mode.voidsetRequiredIndicatorVisible(boolean requiredIndicatorVisible)Sets the required indicator visible or not.voidsetSelectedItem(T item)Sets the current selection to the given item, or clears selection if givennull.voidsetUserSelectionAllowed(boolean allowed)Sets whether the user is allowed to change the selection.voidsetValue(T value)Sets the value of this object.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.vaadin.data.HasValue
clear, getDefaultValidator, getEmptyValue, getOptionalValue, isEmpty
-
-
-
-
Method Detail
-
setDeselectAllowed
public void setDeselectAllowed(boolean deselectAllowed)
Sets whether it's allowed to deselect the selected row through the UI. Deselection is allowed by default.- Parameters:
deselectAllowed-trueif the selected row can be deselected without selecting another row instead; otherwisefalse.
-
isDeselectAllowed
public boolean isDeselectAllowed()
Gets whether it's allowed to deselect the selected row through the UI.- Returns:
trueif deselection is allowed; otherwisefalse
-
addSingleSelectionListener
public Registration addSingleSelectionListener(SingleSelectionListener<T> listener)
Adds a single selection listener that is called when the value of this select is changed either by the user or programmatically.- Parameters:
listener- the value change listener, notnull- Returns:
- a registration for the listener
-
getSelectedItem
public Optional<T> getSelectedItem()
Returns the currently selected item, or an empty optional if no item is selected.- Returns:
- an optional of the selected item if any, an empty optional otherwise
-
setSelectedItem
public void setSelectedItem(T item)
Sets the current selection to the given item, or clears selection if givennull.- Parameters:
item- the item to select ornullto clear selection
-
setUserSelectionAllowed
public void setUserSelectionAllowed(boolean allowed)
Sets whether the user is allowed to change the selection.The check is done only for the client side actions. It doesn't affect selection requests sent from the server side.
- Parameters:
allowed-trueif the user is allowed to change the selection,falseotherwise
-
isUserSelectionAllowed
public boolean isUserSelectionAllowed()
Checks if the user is allowed to change the selection.The check is done only for the client side actions. It doesn't affect selection requests sent from the server side.
- Returns:
trueif the user is allowed to change the selection,falseotherwise
-
getSelectedItems
public Set<T> getSelectedItems()
Returns a singleton set of the currently selected item or an empty set if no item is selected.- Returns:
- a singleton set of the selected item if any, an empty set otherwise
- See Also:
getSelectedItem()
-
getFirstSelectedItem
public Optional<T> getFirstSelectedItem()
Get first selected data item.- Returns:
- the first selected item.
-
deselect
public void deselect(T item)
Selects the given item. Depending on the implementation, may cause other items to be deselected. If the item is already selected, does nothing.- Parameters:
item- the item to select, not null
-
deselectAll
public void deselectAll()
Deselects all currently selected items, if any.
-
addSelectionListener
public Registration addSelectionListener(SelectionListener<T> listener)
Adds a generic listener to this selection model, accepting both single and multiselection events.Use
addSingleSelectionListener(SingleSelectionListener)for more specific single selection event.- Parameters:
listener- the listener to add- Returns:
- a registration handle for removing the listener
- See Also:
addSingleSelectionListener(SingleSelectionListener)
-
isSelected
public boolean isSelected(T item)
Returns whether the given item is currently selected.- Parameters:
item- the item to check, not null- Returns:
trueif the item is selected,falseotherwise
-
select
public void select(T item)
Selects the given item. If another item was already selected, that item is deselected.- Parameters:
item- the item to select
-
setValue
public void setValue(T value)
Description copied from interface:HasValueSets the value of this object. If the new value is not equal togetValue(), fires a value change event. May throwIllegalArgumentExceptionif the value is not acceptable.Implementation note: the implementing class should document whether null values are accepted or not.
-
getValue
public T getValue()
Description copied from interface:HasValueReturns the current value of this object.Implementation note: the implementing class should document whether null values may be returned or not.
-
addValueChangeListener
public Registration addValueChangeListener(HasValue.ValueChangeListener<T> listener)
Description copied from interface:HasValueAdds a value change listener. The listener is called when the value of thisHasValueis changed either by the user or programmatically.- Specified by:
addValueChangeListenerin interfaceHasValue<T>- Parameters:
listener- the value change listener, not null- Returns:
- a registration for the listener
-
setRequiredIndicatorVisible
public void setRequiredIndicatorVisible(boolean requiredIndicatorVisible)
Description copied from interface:HasValueSets the required indicator visible or not.If set visible, it is visually indicated in the user interface.
- Specified by:
setRequiredIndicatorVisiblein interfaceHasValue<T>- Parameters:
requiredIndicatorVisible-trueto make the required indicator visible,falseif not
-
isRequiredIndicatorVisible
public boolean isRequiredIndicatorVisible()
Description copied from interface:HasValueChecks whether the required indicator is visible.- Specified by:
isRequiredIndicatorVisiblein interfaceHasValue<T>- Returns:
trueif visible,falseif not
-
setReadOnly
public void setReadOnly(boolean readOnly)
Description copied from interface:HasValueSets the read-only mode of thisHasValueto given mode. The user can't change the value when in read-only mode.A
HasValuewith a visual component in read-only mode typically looks visually different to signal to the user that the value cannot be edited.- Specified by:
setReadOnlyin interfaceHasValue<T>- Parameters:
readOnly- a boolean value specifying whether the component is put read-only mode or not
-
isReadOnly
public boolean isReadOnly()
Description copied from interface:HasValueReturns whether thisHasValueis in read-only mode or not.- Specified by:
isReadOnlyin interfaceHasValue<T>- Returns:
falseif the user can modify the value,trueif not.
-
-