T
- the bean type of gridpublic class GridSingleSelect<T> extends Object implements SingleSelect<T>
HasValue.ValueChangeEvent<V>, HasValue.ValueChangeListener<V>
Constructor and Description |
---|
GridSingleSelect(Grid<T> grid)
Constructs a SingleSelect wrapper for given Grid.
|
Modifier and Type | Method and 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.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
clear, getDefaultValidator, getEmptyValue, getOptionalValue, isEmpty
public void setDeselectAllowed(boolean deselectAllowed)
deselectAllowed
- true
if the selected row can be deselected
without selecting another row instead; otherwise
false
.public boolean isDeselectAllowed()
true
if deselection is allowed; otherwise
false
public Registration addSingleSelectionListener(SingleSelectionListener<T> listener)
listener
- the value change listener, not null
public Optional<T> getSelectedItem()
public void setSelectedItem(T item)
null
.item
- the item to select or null
to clear selectionpublic void setUserSelectionAllowed(boolean allowed)
The check is done only for the client side actions. It doesn't affect selection requests sent from the server side.
allowed
- true
if the user is allowed to change the
selection, false
otherwisepublic boolean isUserSelectionAllowed()
The check is done only for the client side actions. It doesn't affect selection requests sent from the server side.
true
if the user is allowed to change the selection,
false
otherwisepublic Set<T> getSelectedItems()
getSelectedItem()
public Optional<T> getFirstSelectedItem()
public void deselect(T item)
item
- the item to select, not nullpublic void deselectAll()
public Registration addSelectionListener(SelectionListener<T> listener)
Use addSingleSelectionListener(SingleSelectionListener)
for more
specific single selection event.
listener
- the listener to addaddSingleSelectionListener(SingleSelectionListener)
public boolean isSelected(T item)
item
- the item to check, not nulltrue
if the item is selected, false
otherwisepublic void select(T item)
item
- the item to selectpublic void setValue(T value)
HasValue
getValue()
, fires a value change event. May throw
IllegalArgumentException
if the value is not acceptable.
Implementation note: the implementing class should document whether null values are accepted or not.
public T getValue()
HasValue
Implementation note: the implementing class should document whether null values may be returned or not.
public Registration addValueChangeListener(HasValue.ValueChangeListener<T> listener)
HasValue
HasValue
is changed either by the user or programmatically.addValueChangeListener
in interface HasValue<T>
listener
- the value change listener, not nullpublic void setRequiredIndicatorVisible(boolean requiredIndicatorVisible)
HasValue
If set visible, it is visually indicated in the user interface.
setRequiredIndicatorVisible
in interface HasValue<T>
requiredIndicatorVisible
- true
to make the required indicator visible,
false
if notpublic boolean isRequiredIndicatorVisible()
HasValue
isRequiredIndicatorVisible
in interface HasValue<T>
true
if visible, false
if notpublic void setReadOnly(boolean readOnly)
HasValue
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.
setReadOnly
in interface HasValue<T>
readOnly
- a boolean value specifying whether the component is put
read-only mode or notpublic boolean isReadOnly()
HasValue
HasValue
is in read-only mode or not.isReadOnly
in interface HasValue<T>
false
if the user can modify the value, true
if
not.Copyright © 2023 Vaadin Ltd. All rights reserved.