Class ComponentSelect<C extends com.vaadin.flow.component.Component & com.vaadin.flow.component.ClickNotifier<C>,T>

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,T,ComponentSelect<C,T>>
org.vaadin.miki.superfields.componentselect.ComponentSelect<C,T>
Type Parameters:
C - Type of the component.
T - Type of value.
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<T>, Serializable, HasHelperPositionable, HasId, HasLabelPositionable, HasNullValueOptionallyAllowed<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<com.vaadin.flow.component.customfield.CustomField<T>,T>,T>, WithHelperMixin<ComponentSelect<C,T>>, WithHelperPositionableMixin<ComponentSelect<C,T>>, WithIdMixin<ComponentSelect<C,T>>, WithItemsMixin<T,ComponentSelect<C,T>>, WithLabelMixin<ComponentSelect<C,T>>, WithLabelPositionableMixin<ComponentSelect<C,T>>, WithNullValueOptionallyAllowedMixin<ComponentSelect<C,T>,com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<com.vaadin.flow.component.customfield.CustomField<T>,T>,T>, WithValueMixin<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<com.vaadin.flow.component.customfield.CustomField<T>,T>,T,ComponentSelect<C,T>>
Direct Known Subclasses:
ButtonSelect

@Tag("component-select") @JsModule("./component-select.js") public class ComponentSelect<C extends com.vaadin.flow.component.Component & com.vaadin.flow.component.ClickNotifier<C>,T> extends AbstractComponentSelect<C,T,T,ComponentSelect<C,T>> implements WithNullValueOptionallyAllowedMixin<ComponentSelect<C,T>,com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<com.vaadin.flow.component.customfield.CustomField<T>,T>,T>
A selection component that shows options as ClickNotifiers.
Since:
2023-11-14
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 inherited from class org.vaadin.miki.superfields.componentselect.AbstractComponentSelect

    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
    Constructor
    Description
    ComponentSelect(Supplier<L> layoutSupplier, com.vaadin.flow.function.SerializableBiFunction<Integer,T,C> componentFactory, com.vaadin.flow.function.SerializableBiConsumer<Integer,C> selectionModifier, com.vaadin.flow.function.SerializableBiConsumer<Integer,C> deselectionModifier, T... options)
    Creates the select with given options.
    ComponentSelect(Supplier<L> layoutSupplier, com.vaadin.flow.function.SerializableBiFunction<Integer,T,C> componentFactory, T... options)
    Creates the select with given options, but without any action to perform on selection and deselection.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected T
     
    int
    Returns the index of the currently selected component.
    boolean
    Checks whether null is allowed as a value of the component.
    boolean
    Checks if any component is selected.
    protected boolean
    isSelected(int index)
    Checks if the item at the given index is currently selected.
    protected boolean
    itemClicked(int index)
    Clicks an item at the given index.
    void
    setNullValueAllowed(boolean allowingNullValue)
    Sets allowance of null as this component's value.
    protected void
     
    void
    setSelectedIndex(int index)
    Sets selection index.

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

    add, addThemeVariants, getLabel, onAttach, remove, removeThemeVariants, setLabel, 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
  • Constructor Details

    • ComponentSelect

      @SafeVarargs public ComponentSelect(Supplier<L> layoutSupplier, com.vaadin.flow.function.SerializableBiFunction<Integer,T,C> componentFactory, T... options)
      Creates the select with given options, but without any action to perform on selection and deselection.
      Type Parameters:
      L - Layout type.
      Parameters:
      layoutSupplier - Provides layout for the component.
      componentFactory - A function that creates components for the options.
      options - Items to select from.
    • ComponentSelect

      @SafeVarargs public ComponentSelect(Supplier<L> layoutSupplier, com.vaadin.flow.function.SerializableBiFunction<Integer,T,C> componentFactory, com.vaadin.flow.function.SerializableBiConsumer<Integer,C> selectionModifier, com.vaadin.flow.function.SerializableBiConsumer<Integer,C> deselectionModifier, T... 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

    • isSelected

      public boolean isSelected()
      Checks if any component is selected.
      Returns:
      Whether getSelectedIndex() is different from AbstractComponentSelect.NO_SELECTION.
    • isSelected

      protected boolean isSelected(int index)
      Description copied from class: AbstractComponentSelect
      Checks if the item at the given index is currently selected.
      Specified by:
      isSelected in class AbstractComponentSelect<C extends com.vaadin.flow.component.Component & com.vaadin.flow.component.ClickNotifier<C>,T,T,ComponentSelect<C extends com.vaadin.flow.component.Component & com.vaadin.flow.component.ClickNotifier<C>,T>>
      Parameters:
      index - Index of an item.
      Returns:
      true when the item is selected, false otherwise.
    • itemClicked

      protected boolean itemClicked(int index)
      Description copied from class: AbstractComponentSelect
      Clicks an item at the given index.
      Specified by:
      itemClicked in class AbstractComponentSelect<C extends com.vaadin.flow.component.Component & com.vaadin.flow.component.ClickNotifier<C>,T,T,ComponentSelect<C extends com.vaadin.flow.component.Component & com.vaadin.flow.component.ClickNotifier<C>,T>>
      Parameters:
      index - Index of an item to be clicked.
      Returns:
      Whether value should be updated.
    • setSelectedIndex

      public void setSelectedIndex(int index)
      Sets selection index. Note that when null value is not allowed and passed index is AbstractComponentSelect.NO_SELECTION, nothing will happen.
      Parameters:
      index - New index.
    • getSelectedIndex

      public int getSelectedIndex()
      Returns the index of the currently selected component.
      Returns:
      Index of the currently selected component. Can be AbstractComponentSelect.NO_SELECTION.
    • generateModelValue

      protected T generateModelValue()
      Specified by:
      generateModelValue in class com.vaadin.flow.component.customfield.CustomField<T>
    • setPresentationValue

      protected void setPresentationValue(T t)
      Specified by:
      setPresentationValue in class com.vaadin.flow.component.customfield.CustomField<T>
    • isNullValueAllowed

      public boolean isNullValueAllowed()
      Description copied from interface: HasNullValueOptionallyAllowed
      Checks whether null is allowed as a value of the component.
      Specified by:
      isNullValueAllowed in interface HasNullValueOptionallyAllowed<C extends com.vaadin.flow.component.Component & com.vaadin.flow.component.ClickNotifier<C>,T>
      Returns:
      Whether null is allowed as a value. Should default to false.
    • setNullValueAllowed

      public void setNullValueAllowed(boolean allowingNullValue)
      Description copied from interface: HasNullValueOptionallyAllowed
      Sets allowance of null as this component's value.
      Specified by:
      setNullValueAllowed in interface HasNullValueOptionallyAllowed<C extends com.vaadin.flow.component.Component & com.vaadin.flow.component.ClickNotifier<C>,T>
      Parameters:
      allowingNullValue - Whether to allow null as a value.