com.vaadin.ui.components.grid.
Class GridSingleSelect<T>
- java.lang.Object
-
- com.vaadin.ui.components.grid.GridSingleSelect<T>
-
Type Parameters:
T
- the bean type of gridAll 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:
-
-
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 Modifier and Type Method Description Registration
addSelectionListener(SelectionListener<T> listener)
Adds a generic listener to this selection model, accepting both single and multiselection events.
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.
Registration
addValueChangeListener(HasValue.ValueChangeListener<T> listener)
Adds a value change listener.
void
deselect(T item)
Selects the given item.
void
deselectAll()
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.
T
getValue()
Returns the current value of this object.
boolean
isDeselectAllowed()
Gets whether it's allowed to deselect the selected row through the UI.
boolean
isReadOnly()
Returns whether this
HasValue
is in read-only mode or not.boolean
isRequiredIndicatorVisible()
Checks whether the required indicator is visible.
boolean
isSelected(T item)
Returns whether the given item is currently selected.
boolean
isUserSelectionAllowed()
Checks if the user is allowed to change the selection.
void
select(T item)
Selects the given item.
void
setDeselectAllowed(boolean deselectAllowed)
Sets whether it's allowed to deselect the selected row through the UI.
void
setReadOnly(boolean readOnly)
Sets the read-only mode of this
HasValue
to given mode.void
setRequiredIndicatorVisible(boolean requiredIndicatorVisible)
Sets the required indicator visible or not.
void
setSelectedItem(T item)
Sets the current selection to the given item, or clears selection if given
null
.void
setUserSelectionAllowed(boolean allowed)
Sets whether the user is allowed to change the selection.
void
setValue(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
-true
if 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:
true
if 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 given
null
.Parameters:
item
- the item to select ornull
to 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
-true
if the user is allowed to change the selection,false
otherwise
-
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:
true
if the user is allowed to change the selection,false
otherwise
-
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:
-
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 addReturns:
a registration handle for removing the listener
See Also:
-
isSelected
public boolean isSelected(T item)
Returns whether the given item is currently selected.
Parameters:
item
- the item to check, not nullReturns:
true
if the item is selected,false
otherwise
-
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:
HasValue
Sets the value of this object. If the new value is not equal to
getValue()
, fires a value change event. May throwIllegalArgumentException
if 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:
HasValue
Returns 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:
HasValue
Adds a value change listener. The listener is called when the value of this
HasValue
is changed either by the user or programmatically.Specified by:
addValueChangeListener
in interfaceHasValue<T>
Parameters:
listener
- the value change listener, not nullReturns:
a registration for the listener
-
setRequiredIndicatorVisible
public void setRequiredIndicatorVisible(boolean requiredIndicatorVisible)
Description copied from interface:
HasValue
Sets the required indicator visible or not.
If set visible, it is visually indicated in the user interface.
Specified by:
setRequiredIndicatorVisible
in interfaceHasValue<T>
Parameters:
requiredIndicatorVisible
-true
to make the required indicator visible,false
if not
-
isRequiredIndicatorVisible
public boolean isRequiredIndicatorVisible()
Description copied from interface:
HasValue
Checks whether the required indicator is visible.
Specified by:
isRequiredIndicatorVisible
in interfaceHasValue<T>
Returns:
true
if visible,false
if not
-
setReadOnly
public void setReadOnly(boolean readOnly)
Description copied from interface:
HasValue
Sets the read-only mode of this
HasValue
to given mode. The user can't change the value when in read-only mode.A
HasValue
with a visual component in read-only mode typically looks visually different to signal to the user that the value cannot be edited.Specified by:
setReadOnly
in 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:
HasValue
Returns whether this
HasValue
is in read-only mode or not.Specified by:
isReadOnly
in interfaceHasValue<T>
Returns:
false
if the user can modify the value,true
if not.
-
-