com.vaadin.ui.

Class AbstractSingleSelect<T>

    • Constructor Detail

      • AbstractSingleSelect

        protected AbstractSingleSelect()

        Creates a new AbstractListing with a default data communicator.

      • AbstractSingleSelect

        protected AbstractSingleSelect​(DataCommunicator<T> dataCommunicator)

        Creates a new AbstractSingleSelect with the given custom data communicator.

        Note: This method is for creating an AbstractSingleSelect with a custom communicator. In the common case AbstractSingleSelect() should be used.

        Parameters:

        dataCommunicator - the data communicator to use, not null

    • Method Detail

      • addSelectionListener

        public Registration addSelectionListener​(SingleSelectionListener<T> listener)

        Adds a selection listener to this select. The listener is called when the selection is changed either by the user or programmatically.

        Parameters:

        listener - the selection 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

      • 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

      • getState

        protected AbstractSingleSelectState getState()

        Description copied from class: AbstractComponent

        Returns the shared state bean with information to be sent from the server to the client. Subclasses should override this method and set any relevant fields of the state returned by super.getState().

        Overrides:

        getState in class AbstractListing<T>

        Returns:

        updated component shared state

      • setReadOnly

        public void setReadOnly​(boolean readOnly)

        Description copied from class: AbstractComponent

        Sets the read-only status in the state of this AbstractComponent. This method should be made public in Components that implement HasValue.

        Specified by:

        setReadOnly in interface HasValue<T>

        Overrides:

        setReadOnly in class AbstractComponent

        Parameters:

        readOnly - a boolean value specifying whether the component is put read-only mode or not

      • keyToItem

        protected T keyToItem​(String key)

        Returns the item that the given key is assigned to, or null if there is no such item.

        Parameters:

        key - the key whose item to return

        Returns:

        the associated item if any, null otherwise.

      • 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

      • writeItem

        protected org.jsoup.nodes.Element writeItem​(org.jsoup.nodes.Element design,
                                                    T item,
                                                    DesignContext context)

        Description copied from class: AbstractListing

        Writes a data source Item to a design. Hierarchical select components should override this method to recursively write any child items as well.

        Overrides:

        writeItem in class AbstractListing<T>

        Parameters:

        design - the element into which to insert the item

        item - the item to write

        context - the DesignContext instance used in writing

        Returns:

        a JSOUP element representing the item

      • readItems

        protected void readItems​(org.jsoup.nodes.Element design,
                                 DesignContext context)

        Description copied from class: AbstractListing

        Reads the data source items from the design.

        Specified by:

        readItems in class AbstractListing<T>

        Parameters:

        design - The element to obtain the state from

        context - The DesignContext instance used for parsing the design

      • readItem

        protected T readItem​(org.jsoup.nodes.Element child,
                             Set<T> selected,
                             DesignContext context)

        Reads an Item from a design and inserts it into the data source. Hierarchical select components should override this method to recursively recursively read any child items as well.

        Parameters:

        child - a child element representing the item

        selected - A set accumulating selected items. If the item that is read is marked as selected, its item id should be added to this set.

        context - the DesignContext instance used in parsing

        Returns:

        the item id of the new item

        Throws:

        DesignException - if the tag name of the child element is not option.

      • setSelectedItem

        protected void setSelectedItem​(T value,
                                       boolean userOriginated)

        This method updates the internal selection state of the server-side of AbstractSingleSelect.

        Parameters:

        value - the value that should be selected

        userOriginated - true if selection was done by user, false if not

        Since:

        8.5

      • updateSelectedItemState

        protected void updateSelectedItemState​(T value)

        This method updates the shared selection state of the AbstractSingleSelect.

        Parameters:

        value - the value that is selected; may be null

        Since:

        8.5