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
FieldsFields inherited from interface org.vaadin.miki.markers.HasHelperPositionable
HELPER_ABOVE_THEME_VARIANTFields inherited from interface org.vaadin.miki.markers.HasLabelPositionable
LABEL_POSITION_ATTRIBUTE, LABEL_POSITION_DETAILS_ATTRIBUTE -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractComponentSelect(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 TypeMethodDescriptionprotected voiddeselect(int index) Deselects component at the given index.protected voidensureValidIndex(int index) Ensures the index is within bounds.voidfocus()Returns the action that is currently performed when a component gets deselected.Returns the current component factory.protected final intgetComponentIndex(C component) Returns the index of the given component.Returns the action that is currently performed when a component gets selected.Returns the current list of options.protected abstract booleanisSelected(int index) Checks if the item at the given index is currently selected.protected abstract booleanitemClicked(int index) Clicks an item at the given index.protected static <X,Y> com.vaadin.flow.function.SerializableBiConsumer<X, Y> noOp()A no-op, default do-nothing operation for selection/deselection.protected final voidRebuilds the components - removes the existing ones then calls the factory to produce new ones.protected voidselect(int index) Selects component at the given index.final voidsetComponentDeselectedAction(com.vaadin.flow.function.SerializableBiConsumer<Integer, C> action) Sets the action to be performed on a deselected component.final voidsetComponentFactory(com.vaadin.flow.function.SerializableBiFunction<Integer, I, C> factory) Sets the factory that will be used to create new components.final voidsetComponentSelectedAction(com.vaadin.flow.function.SerializableBiConsumer<Integer, C> action) Sets the action to be performed on a selected component.voidsetItems(Collection<I> items) final SELFwithComponentDeselectedAction(com.vaadin.flow.function.SerializableBiConsumer<Integer, C> action) ChainssetComponentDeselectedAction(SerializableBiConsumer)and returns itself.final SELFwithComponentFactory(com.vaadin.flow.function.SerializableBiFunction<Integer, I, C> factory) ChainssetComponentFactory(SerializableBiFunction)and returns itself.final SELFwithComponentSelectedAction(com.vaadin.flow.function.SerializableBiConsumer<Integer, C> action) ChainssetComponentSelectedAction(SerializableBiConsumer)and returns itself.Methods inherited from class com.vaadin.flow.component.customfield.CustomField
add, addThemeVariants, generateModelValue, getLabel, onAttach, remove, removeThemeVariants, setLabel, setPresentationValue, updateValueMethods inherited from class com.vaadin.flow.component.AbstractField
addValueChangeListener, getEmptyValue, getValue, isEmpty, setModelValue, setValue, valueEqualsMethods 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, setVisibleMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.vaadin.flow.component.AttachNotifier
addAttachListenerMethods inherited from interface com.vaadin.flow.component.BlurNotifier
addBlurListenerMethods inherited from interface com.vaadin.flow.component.DetachNotifier
addDetachListenerMethods inherited from interface com.vaadin.flow.component.Focusable
addFocusShortcut, blur, getTabIndex, setTabIndexMethods inherited from interface com.vaadin.flow.component.FocusNotifier
addFocusListenerMethods inherited from interface com.vaadin.flow.component.HasElement
getElementMethods inherited from interface com.vaadin.flow.component.HasEnabled
isEnabled, setEnabledMethods inherited from interface com.vaadin.flow.component.HasHelper
getHelperComponent, getHelperText, setHelperComponent, setHelperTextMethods inherited from interface org.vaadin.miki.markers.HasHelperPositionable
isHelperAbove, setHelperAbove, setHelperAbove, setHelperBelowMethods inherited from interface com.vaadin.flow.data.binder.HasItems
setItems, setItemsMethods inherited from interface com.vaadin.flow.component.HasLabel
getLabel, setLabelMethods inherited from interface org.vaadin.miki.markers.HasLabelPositionable
getLabelPosition, setLabelPositionMethods 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, setWidthFullMethods inherited from interface com.vaadin.flow.component.HasStyle
addClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassNameMethods inherited from interface com.vaadin.flow.component.HasTheme
addThemeName, addThemeNames, getThemeName, getThemeNames, hasThemeName, removeThemeName, removeThemeNames, setThemeName, setThemeNameMethods inherited from interface com.vaadin.flow.component.shared.HasTooltip
getTooltip, setTooltipTextMethods inherited from interface com.vaadin.flow.component.HasValidation
setManualValidationMethods inherited from interface com.vaadin.flow.component.shared.HasValidationProperties
getErrorMessage, isInvalid, setErrorMessage, setInvalidMethods inherited from interface com.vaadin.flow.component.HasValue
addValueChangeListener, clear, getEmptyValue, getOptionalValue, getValue, isEmpty, setValueMethods inherited from interface com.vaadin.flow.component.HasValueAndElement
isReadOnly, isRequiredIndicatorVisible, setReadOnly, setRequiredIndicatorVisibleMethods inherited from interface org.vaadin.miki.markers.WithHelperMixin
withHelperComponent, withHelperTextMethods inherited from interface org.vaadin.miki.markers.WithHelperPositionableMixin
withHelperAbove, withHelperAbove, withHelperBelowMethods inherited from interface org.vaadin.miki.markers.WithIdMixin
withIdMethods inherited from interface org.vaadin.miki.markers.WithItemsMixin
withItems, withItems, withItemsMethods inherited from interface org.vaadin.miki.markers.WithLabelMixin
withLabelMethods inherited from interface org.vaadin.miki.markers.WithLabelPositionableMixin
withLabelPositionMethods inherited from interface org.vaadin.miki.markers.WithValueMixin
withValue
-
Field Details
-
NO_SELECTION
public static final int NO_SELECTIONIndex 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 theoptions.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:
truewhen the item is selected,falseotherwise.
-
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
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
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 benull.
-
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) ChainssetComponentFactory(SerializableBiFunction)and returns itself.- Parameters:
factory- Factory. Must not benull.- 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. Ifnullis passed, result ofnoOp()will be used instead.
-
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) ChainssetComponentSelectedAction(SerializableBiConsumer)and returns itself.- 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. Ifnullis passed, result ofnoOp()will be used instead.
-
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) ChainssetComponentDeselectedAction(SerializableBiConsumer)and returns itself.- Parameters:
action- Action.- Returns:
- This.
-
setItems
-
focus
public void focus()
-