Class AbstractComponentSelect<C extends com.vaadin.flow.component.Component & com.vaadin.flow.component.ClickNotifier<C>,T,I,SELF extends AbstractComponentSelect<C,T,I,SELF>>

java.lang.Object
com.vaadin.flow.component.Component
com.vaadin.flow.component.AbstractField<com.vaadin.flow.component.customfield.CustomField<T>,T>
com.vaadin.flow.component.customfield.CustomField<T>
org.vaadin.miki.superfields.componentselect.AbstractComponentSelect<C,T,I,SELF>
Type Parameters:
C - Component to display for each option.
T - Type of the field.
I - Type of item.
SELF - Self type.
All Implemented Interfaces:
com.vaadin.flow.component.AttachNotifier, com.vaadin.flow.component.BlurNotifier<com.vaadin.flow.component.customfield.CustomField<T>>, com.vaadin.flow.component.DetachNotifier, com.vaadin.flow.component.Focusable<com.vaadin.flow.component.customfield.CustomField<T>>, com.vaadin.flow.component.FocusNotifier<com.vaadin.flow.component.customfield.CustomField<T>>, com.vaadin.flow.component.HasElement, com.vaadin.flow.component.HasEnabled, com.vaadin.flow.component.HasHelper, com.vaadin.flow.component.HasLabel, com.vaadin.flow.component.HasSize, com.vaadin.flow.component.HasStyle, com.vaadin.flow.component.HasTheme, com.vaadin.flow.component.HasValidation, com.vaadin.flow.component.HasValue<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<com.vaadin.flow.component.customfield.CustomField<T>,T>,T>, com.vaadin.flow.component.HasValueAndElement<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<com.vaadin.flow.component.customfield.CustomField<T>,T>,T>, com.vaadin.flow.component.shared.HasTooltip, com.vaadin.flow.component.shared.HasValidationProperties, com.vaadin.flow.component.shared.InputField<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<com.vaadin.flow.component.customfield.CustomField<T>,T>,T>, com.vaadin.flow.data.binder.HasItems<I>, Serializable, HasHelperPositionable, HasId, HasLabelPositionable, WithHelperMixin<SELF>, WithHelperPositionableMixin<SELF>, WithIdMixin<SELF>, WithItemsMixin<I,SELF>, WithLabelMixin<SELF>, WithLabelPositionableMixin<SELF>, WithValueMixin<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<com.vaadin.flow.component.customfield.CustomField<T>,T>,T,SELF>
Direct Known Subclasses:
ComponentMultiSelect, ComponentSelect

public abstract class AbstractComponentSelect<C extends com.vaadin.flow.component.Component & com.vaadin.flow.component.ClickNotifier<C>,T,I,SELF extends AbstractComponentSelect<C,T,I,SELF>> extends com.vaadin.flow.component.customfield.CustomField<T> implements com.vaadin.flow.component.HasStyle, WithItemsMixin<I,SELF>, WithIdMixin<SELF>, WithLabelMixin<SELF>, WithLabelPositionableMixin<SELF>, WithHelperMixin<SELF>, WithHelperPositionableMixin<SELF>, WithValueMixin<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<com.vaadin.flow.component.customfield.CustomField<T>,T>,T,SELF>
Base class for Component(Multi)Select.
Since:
2023-11-28
Author:
miki
See Also:
  • Nested Class Summary

    Nested classes/interfaces inherited from class com.vaadin.flow.component.AbstractField

    com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<C extends com.vaadin.flow.component.Component,V extends Object>

    Nested classes/interfaces inherited from interface com.vaadin.flow.component.BlurNotifier

    com.vaadin.flow.component.BlurNotifier.BlurEvent<C extends com.vaadin.flow.component.Component>

    Nested classes/interfaces inherited from interface com.vaadin.flow.component.FocusNotifier

    com.vaadin.flow.component.FocusNotifier.FocusEvent<C extends com.vaadin.flow.component.Component>

    Nested classes/interfaces inherited from interface com.vaadin.flow.component.HasValue

    com.vaadin.flow.component.HasValue.ValueChangeEvent<V extends Object>, com.vaadin.flow.component.HasValue.ValueChangeListener<E extends com.vaadin.flow.component.HasValue.ValueChangeEvent<?>>
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    Index for no selection.

    Fields inherited from interface org.vaadin.miki.markers.HasHelperPositionable

    HELPER_ABOVE_THEME_VARIANT

    Fields inherited from interface org.vaadin.miki.markers.HasLabelPositionable

    LABEL_POSITION_ATTRIBUTE, LABEL_POSITION_DETAILS_ATTRIBUTE
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    AbstractComponentSelect(T defaultValue, Supplier<L> layoutSupplier, com.vaadin.flow.function.SerializableBiFunction<Integer,I,C> componentFactory, com.vaadin.flow.function.SerializableBiConsumer<Integer,C> selectionModifier, com.vaadin.flow.function.SerializableBiConsumer<Integer,C> deselectionModifier, I... options)
    Creates the select with given options.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    deselect(int index)
    Deselects component at the given index.
    protected void
    ensureValidIndex(int index)
    Ensures the index is within bounds.
    void
     
    com.vaadin.flow.function.SerializableBiConsumer<Integer,C>
    Returns the action that is currently performed when a component gets deselected.
    com.vaadin.flow.function.SerializableBiFunction<Integer,I,C>
    Returns the current component factory.
    protected final int
    getComponentIndex(C component)
    Returns the index of the given component.
    com.vaadin.flow.function.SerializableBiConsumer<Integer,C>
    Returns the action that is currently performed when a component gets selected.
    protected List<I>
    Returns the current list of options.
    protected abstract boolean
    isSelected(int index)
    Checks if the item at the given index is currently selected.
    protected abstract boolean
    itemClicked(int index)
    Clicks an item at the given index.
    protected static <X, Y> com.vaadin.flow.function.SerializableBiConsumer<X,Y>
    A no-op, default do-nothing operation for selection/deselection.
    protected final void
    Rebuilds the components - removes the existing ones then calls the factory to produce new ones.
    protected void
    select(int index)
    Selects component at the given index.
    final void
    setComponentDeselectedAction(com.vaadin.flow.function.SerializableBiConsumer<Integer,C> action)
    Sets the action to be performed on a deselected component.
    final void
    setComponentFactory(com.vaadin.flow.function.SerializableBiFunction<Integer,I,C> factory)
    Sets the factory that will be used to create new components.
    final void
    setComponentSelectedAction(com.vaadin.flow.function.SerializableBiConsumer<Integer,C> action)
    Sets the action to be performed on a selected component.
    void
     
    final SELF
    withComponentDeselectedAction(com.vaadin.flow.function.SerializableBiConsumer<Integer,C> action)
    final SELF
    withComponentFactory(com.vaadin.flow.function.SerializableBiFunction<Integer,I,C> factory)
    final SELF
    withComponentSelectedAction(com.vaadin.flow.function.SerializableBiConsumer<Integer,C> action)

    Methods inherited from class com.vaadin.flow.component.customfield.CustomField

    add, addThemeVariants, generateModelValue, getLabel, onAttach, remove, removeThemeVariants, setLabel, setPresentationValue, updateValue

    Methods inherited from class com.vaadin.flow.component.AbstractField

    addValueChangeListener, getEmptyValue, getValue, isEmpty, setModelValue, setValue, valueEquals

    Methods inherited from class com.vaadin.flow.component.Component

    addListener, findAncestor, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getListeners, getLocale, getParent, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onDetach, onEnabledStateChanged, removeFromParent, scrollIntoView, scrollIntoView, set, setElement, setId, setVisible

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface com.vaadin.flow.component.AttachNotifier

    addAttachListener

    Methods inherited from interface com.vaadin.flow.component.BlurNotifier

    addBlurListener

    Methods inherited from interface com.vaadin.flow.component.DetachNotifier

    addDetachListener

    Methods inherited from interface com.vaadin.flow.component.Focusable

    addFocusShortcut, blur, getTabIndex, setTabIndex

    Methods inherited from interface com.vaadin.flow.component.FocusNotifier

    addFocusListener

    Methods inherited from interface com.vaadin.flow.component.HasElement

    getElement

    Methods inherited from interface com.vaadin.flow.component.HasEnabled

    isEnabled, setEnabled

    Methods inherited from interface com.vaadin.flow.component.HasHelper

    getHelperComponent, getHelperText, setHelperComponent, setHelperText

    Methods inherited from interface org.vaadin.miki.markers.HasHelperPositionable

    isHelperAbove, setHelperAbove, setHelperAbove, setHelperBelow

    Methods inherited from interface org.vaadin.miki.markers.HasId

    getId, setId

    Methods inherited from interface com.vaadin.flow.data.binder.HasItems

    setItems, setItems

    Methods inherited from interface com.vaadin.flow.component.HasLabel

    getLabel, setLabel

    Methods inherited from interface org.vaadin.miki.markers.HasLabelPositionable

    getLabelPosition, setLabelPosition

    Methods inherited from interface com.vaadin.flow.component.HasSize

    getHeight, getHeightUnit, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getWidth, getWidthUnit, setHeight, setHeight, setHeightFull, setMaxHeight, setMaxHeight, setMaxWidth, setMaxWidth, setMinHeight, setMinHeight, setMinWidth, setMinWidth, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthFull

    Methods inherited from interface com.vaadin.flow.component.HasStyle

    addClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassName

    Methods inherited from interface com.vaadin.flow.component.HasTheme

    addThemeName, addThemeNames, getThemeName, getThemeNames, hasThemeName, removeThemeName, removeThemeNames, setThemeName, setThemeName

    Methods inherited from interface com.vaadin.flow.component.shared.HasTooltip

    getTooltip, setTooltipText

    Methods inherited from interface com.vaadin.flow.component.HasValidation

    setManualValidation

    Methods inherited from interface com.vaadin.flow.component.shared.HasValidationProperties

    getErrorMessage, isInvalid, setErrorMessage, setInvalid

    Methods inherited from interface com.vaadin.flow.component.HasValue

    addValueChangeListener, clear, getEmptyValue, getOptionalValue, getValue, isEmpty, setValue

    Methods inherited from interface com.vaadin.flow.component.HasValueAndElement

    isReadOnly, isRequiredIndicatorVisible, setReadOnly, setRequiredIndicatorVisible

    Methods inherited from interface org.vaadin.miki.markers.WithHelperMixin

    withHelperComponent, withHelperText

    Methods inherited from interface org.vaadin.miki.markers.WithHelperPositionableMixin

    withHelperAbove, withHelperAbove, withHelperBelow

    Methods inherited from interface org.vaadin.miki.markers.WithIdMixin

    withId

    Methods inherited from interface org.vaadin.miki.markers.WithItemsMixin

    withItems, withItems, withItems

    Methods inherited from interface org.vaadin.miki.markers.WithLabelMixin

    withLabel

    Methods inherited from interface org.vaadin.miki.markers.WithLabelPositionableMixin

    withLabelPosition

    Methods inherited from interface org.vaadin.miki.markers.WithValueMixin

    withValue
  • Field Details

    • NO_SELECTION

      public static final int NO_SELECTION
      Index for no selection.
      See Also:
  • Constructor Details

    • AbstractComponentSelect

      @SafeVarargs protected AbstractComponentSelect(T defaultValue, Supplier<L> layoutSupplier, com.vaadin.flow.function.SerializableBiFunction<Integer,I,C> componentFactory, com.vaadin.flow.function.SerializableBiConsumer<Integer,C> selectionModifier, com.vaadin.flow.function.SerializableBiConsumer<Integer,C> deselectionModifier, I... options)
      Creates the select with given options.
      Type Parameters:
      L - Layout type.
      Parameters:
      layoutSupplier - Provides layout for the component.
      componentFactory - A function that creates components for the options.
      selectionModifier - Action to perform on a component when it is selected.
      deselectionModifier - Action to perform on a component when it is deselected.
      options - Items to select from.
  • Method Details

    • noOp

      protected static <X, Y> com.vaadin.flow.function.SerializableBiConsumer<X,Y> noOp()
      A no-op, default do-nothing operation for selection/deselection.
      Type Parameters:
      X - First argument type.
      Y - Second argument type.
      Returns:
      A bi-consumer that does nothing.
    • isSelected

      protected abstract boolean isSelected(int index)
      Checks if the item at the given index is currently selected.
      Parameters:
      index - Index of an item.
      Returns:
      true when the item is selected, false otherwise.
    • itemClicked

      protected abstract boolean itemClicked(int index)
      Clicks an item at the given index.
      Parameters:
      index - Index of an item to be clicked.
      Returns:
      Whether value should be updated.
    • deselect

      protected void deselect(int index)
      Deselects component at the given index.
      Parameters:
      index - Index of a component to deselect.
    • select

      protected void select(int index)
      Selects component at the given index.
      Parameters:
      index - Index of a component to select.
    • rebuildComponents

      protected final void rebuildComponents()
      Rebuilds the components - removes the existing ones then calls the factory to produce new ones. Selected/deselected actions will be called on the newly created components, depending on their state.
    • getOptions

      protected List<I> getOptions()
      Returns the current list of options. Modifying this list will modify the options available to this component, but will not rebuild components.
      Returns:
      List of options. Never null, but possibly empty.
    • getComponentIndex

      protected final int getComponentIndex(C component)
      Returns the index of the given component.
      Parameters:
      component - Component to find.
      Returns:
      The index of the component, if found, otherwise NO_SELECTION.
    • ensureValidIndex

      protected void ensureValidIndex(int index)
      Ensures the index is within bounds.
      Parameters:
      index - Index to check.
      Throws:
      IllegalArgumentException - when the index is outside the allowed bounds.
    • setComponentFactory

      public final void setComponentFactory(com.vaadin.flow.function.SerializableBiFunction<Integer,I,C> factory)
      Sets the factory that will be used to create new components.
      Parameters:
      factory - Factory. Must not be null.
    • getComponentFactory

      public com.vaadin.flow.function.SerializableBiFunction<Integer,I,C> getComponentFactory()
      Returns the current component factory.
      Returns:
      The factory. Never null.
    • withComponentFactory

      public final SELF withComponentFactory(com.vaadin.flow.function.SerializableBiFunction<Integer,I,C> factory)
      Parameters:
      factory - Factory. Must not be null.
      Returns:
      This.
      See Also:
    • setComponentSelectedAction

      public final void setComponentSelectedAction(com.vaadin.flow.function.SerializableBiConsumer<Integer,C> action)
      Sets the action to be performed on a selected component.
      Parameters:
      action - Action to use. If null is passed, result of noOp() will be used instead.
    • getComponentSelectedAction

      public com.vaadin.flow.function.SerializableBiConsumer<Integer,C> getComponentSelectedAction()
      Returns the action that is currently performed when a component gets selected.
      Returns:
      An action. Never null.
    • withComponentSelectedAction

      public final SELF withComponentSelectedAction(com.vaadin.flow.function.SerializableBiConsumer<Integer,C> action)
      Parameters:
      action - Action.
      Returns:
      This.
      See Also:
    • setComponentDeselectedAction

      public final void setComponentDeselectedAction(com.vaadin.flow.function.SerializableBiConsumer<Integer,C> action)
      Sets the action to be performed on a deselected component.
      Parameters:
      action - Action to use. If null is passed, result of noOp() will be used instead.
    • getComponentDeselectedAction

      public com.vaadin.flow.function.SerializableBiConsumer<Integer,C> getComponentDeselectedAction()
      Returns the action that is currently performed when a component gets deselected.
      Returns:
      An action. Never null.
    • withComponentDeselectedAction

      public final SELF withComponentDeselectedAction(com.vaadin.flow.function.SerializableBiConsumer<Integer,C> action)
      Parameters:
      action - Action.
      Returns:
      This.
    • setItems

      public void setItems(Collection<I> items)
      Specified by:
      setItems in interface com.vaadin.flow.data.binder.HasItems<C extends com.vaadin.flow.component.Component & com.vaadin.flow.component.ClickNotifier<C>>
    • focus

      public void focus()
      Specified by:
      focus in interface com.vaadin.flow.component.Focusable<C extends com.vaadin.flow.component.Component & com.vaadin.flow.component.ClickNotifier<C>>