com.vaadin.ui.components.grid.

Class 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

    • Constructor Detail

      • GridSingleSelect

        public GridSingleSelect​(Grid<T> grid)

        Constructs a SingleSelect wrapper for given Grid.

        Parameters:

        grid - the grid to wrap

    • 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; otherwise false.

      • isDeselectAllowed

        public boolean isDeselectAllowed()

        Gets whether it's allowed to deselect the selected row through the UI.

        Returns:

        true if deselection is allowed; otherwise false

      • 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, not null

        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 or null 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:

        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.

      • isSelected

        public boolean isSelected​(T item)

        Returns whether the given item is currently selected.

        Parameters:

        item - the item to check, not null

        Returns:

        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 throw IllegalArgumentException if the value is not acceptable.

        Implementation note: the implementing class should document whether null values are accepted or not.

        Specified by:

        setValue in interface HasValue<T>

        Parameters:

        value - the new value

      • 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.

        Specified by:

        getValue in interface HasValue<T>

        Returns:

        the current value

      • 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 interface HasValue<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: HasValue

        Sets the required indicator visible or not.

        If set visible, it is visually indicated in the user interface.

        Specified by:

        setRequiredIndicatorVisible in interface HasValue<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 interface HasValue<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 interface HasValue<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 interface HasValue<T>

        Returns:

        false if the user can modify the value, true if not.