com.vaadin.ui.components.grid.

Class GridMultiSelect<T>

  • Type Parameters:

    T - the bean type of grid

    All Implemented Interfaces:

    HasValue<Set<T>>, MultiSelect<T>, Serializable

    public class GridMultiSelect<T>
    extends Object
    implements MultiSelect<T>

    Wrapper class to wrap Grid into a MultiSelect. This class also provides useful access to API of MultiSelectionModel.

    Since:

    8.6.0

    See Also:

    Serialized Form

    • Constructor Detail

      • GridMultiSelect

        public GridMultiSelect​(Grid<T> grid)

        Constructs a MultiSelect wrapper for given Grid.

        Parameters:

        grid - the grid to wrap

    • Method Detail

      • getFirstSelectedItem

        public Optional<T> getFirstSelectedItem()

        Get first selected data item.

        Returns:

        the first selected item.

      • selectAll

        public void selectAll()

        Selects all available the items.

      • 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

      • 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

      • deselectAll

        public void deselectAll()

        Deselects all currently selected items, if any.

        Specified by:

        deselectAll in interface MultiSelect<T>

      • selectItems

        public void selectItems​(T... items)

        Adds the given items to the set of currently selected items.

        By default this does not clear any previous selection. To do that, use deselectAll().

        If the all the items were already selected, this is a NO-OP.

        This is a short-hand for updateSelection(Set, Set) with nothing to deselect.

        Parameters:

        items - to add to selection, not null

      • deselectItems

        public void deselectItems​(T... items)

        Removes the given items from the set of currently selected items.

        If the none of the items were selected, this is a NO-OP.

        This is a short-hand for updateSelection(Set, Set) with nothing to select.

        Parameters:

        items - to remove from selection, not null

      • 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

      • isAllSelected

        public boolean isAllSelected()

        Returns whether all items are selected or not.

        This is only true if user has selected all rows with the select all checkbox on client side, or if selectAll() has been used from server side.

        Returns:

        true if all selected, false if not

        Since:

        8.12.0

      • 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

      • addSelectionListener

        public Registration addSelectionListener​(SelectionListener<T> listener)

        Adds a generic listener to this selection model, accepting both single and multiselection events.

        Parameters:

        listener - the listener to add

        Returns:

        a registration handle for removing the listener

      • addMultiSelectionListener

        public Registration addMultiSelectionListener​(MultiSelectionListener<T> listener)

        Adds a selection listener that will be called when the selection is changed either by the user or programmatically.

        Parameters:

        listener - the value change listener, not null

        Returns:

        a registration for the listener

      • setValue

        public void setValue​(Set<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 Set<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<Set<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.

      • updateSelection

        public void updateSelection​(Set<T> addedItems,
                                    Set<T> removedItems)

        Description copied from interface: MultiSelect

        Updates the selection by adding and removing the given items from it.

        If all the added items were already selected and the removed items were not selected, this is a NO-OP.

        Duplicate items (in both add & remove sets) are ignored and removed from the sets.

        Specified by:

        updateSelection in interface MultiSelect<T>

        Parameters:

        addedItems - the items to add, not null

        removedItems - the items to remove, not null

      • getSelectedItems

        public Set<T> getSelectedItems()

        Description copied from interface: MultiSelect

        Returns an immutable set of the currently selected items. It is safe to invoke other SelectionModel methods while iterating over the set.

        Implementation note: the iteration order of the items in the returned set should be well-defined and documented by the implementing class.

        Specified by:

        getSelectedItems in interface MultiSelect<T>

        Returns:

        the items in the current selection, not null

      • addSelectionListener

        public Registration addSelectionListener​(MultiSelectionListener<T> listener)

        Description copied from interface: MultiSelect

        Adds a selection listener that will be called when the selection is changed either by the user or programmatically.

        Specified by:

        addSelectionListener in interface MultiSelect<T>

        Parameters:

        listener - the value change listener, not null

        Returns:

        a registration for the listener