Class ChipComboBox<T>

java.lang.Object
com.vaadin.flow.component.Component
com.vaadin.flow.component.Composite<C>
com.vaadin.flow.component.AbstractCompositeField<com.vaadin.flow.component.orderedlayout.VerticalLayout,ChipComboBox<T>,Set<T>>
software.xdev.vaadin.chips.ChipComboBox<T>
All Implemented Interfaces:
com.vaadin.flow.component.AttachNotifier, com.vaadin.flow.component.BlurNotifier<ChipComboBox<T>>, com.vaadin.flow.component.DetachNotifier, com.vaadin.flow.component.Focusable<ChipComboBox<T>>, com.vaadin.flow.component.FocusNotifier<ChipComboBox<T>>, com.vaadin.flow.component.HasElement, com.vaadin.flow.component.HasEnabled, 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<ChipComboBox<T>,Set<T>>,Set<T>>, com.vaadin.flow.component.HasValueAndElement<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<ChipComboBox<T>,Set<T>>,Set<T>>, com.vaadin.flow.component.shared.HasTooltip, com.vaadin.flow.data.binder.HasItems<T>, com.vaadin.flow.data.binder.HasValidator<T>, Serializable

public class ChipComboBox<T> extends com.vaadin.flow.component.AbstractCompositeField<com.vaadin.flow.component.orderedlayout.VerticalLayout,ChipComboBox<T>,Set<T>> implements com.vaadin.flow.component.HasStyle, com.vaadin.flow.component.Focusable<ChipComboBox<T>>, com.vaadin.flow.component.HasSize, com.vaadin.flow.component.HasValidation, com.vaadin.flow.component.HasTheme, com.vaadin.flow.component.HasLabel, com.vaadin.flow.component.shared.HasTooltip, com.vaadin.flow.data.binder.HasItems<T>, com.vaadin.flow.data.binder.HasValidator<T>
This component has a ComboBox with available items and displays the selected items as "chips" underneath it.
It behaves somewhat similar to a Select.
See Also:
  • Nested Class Summary

    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
    protected final List<T>
     
    protected com.vaadin.flow.component.button.Button
     
    protected com.vaadin.flow.component.combobox.ComboBox<T>
     
    protected com.vaadin.flow.component.ItemLabelGenerator<T>
     
    protected com.vaadin.flow.component.orderedlayout.FlexLayout
     
    protected com.vaadin.flow.function.SerializableFunction<T,ChipComponent<T>>
     
    protected com.vaadin.flow.component.orderedlayout.HorizontalLayout
     
    protected final List<ChipComponent<T>>
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
     
    ChipComboBox(String label, Set<T> defaultValue)
     
    ChipComboBox(Set<T> defaultValue)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    addItem(T item, boolean isFromClient)
     
    void
    void
    Get all available items, that can potentially get selected
    com.vaadin.flow.component.combobox.ComboBox<T>
    Returns the ComboBox which contains the available items.
    com.vaadin.flow.component.orderedlayout.FlexLayout
    Returns the FlexLayout with the select items (as ChipComponents).
    Returns the current supplier for creating new ChipComponents
    com.vaadin.flow.component.Component
     
    com.vaadin.flow.component.orderedlayout.HorizontalLayout
    Returns the HorizontalLayout which contains cbAvailableItems.
     
    protected void
     
    protected void
     
    boolean
     
    boolean
    boolean
    protected void
    onCbAvailableItemsValueChanged(com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<com.vaadin.flow.component.combobox.ComboBox<T>,T> event)
     
    protected void
    onClickClearAll(com.vaadin.flow.component.ClickEvent<com.vaadin.flow.component.button.Button> event)
     
    protected void
    removeItem(T item, boolean isFromClient)
     
    void
    setChipItemLabelGenerator(com.vaadin.flow.component.ItemLabelGenerator<T> generator)
    Sets the item label generator used by the individual ChipComponents.
    void
    setChipsSupplier(com.vaadin.flow.function.SerializableFunction<T,ChipComponent<T>> chipsSupplier)
    Sets the supplier for creating new ChipComponents
    void
    setClearAllButtonVisible(boolean clearAllButtonVisible)
    Sets the "Clear All Button" to visible or invisible.
    void
    setClearAllIcon(com.vaadin.flow.component.Component clearAllIcon)
    Sets the "Clear All Button" icon.
    void
    setErrorMessage(String errorMessage)
    void
    setFullComboBoxWidth(boolean useFullWidth)
     
    void
    setInvalid(boolean invalid)
    void
    setItemLabelGenerator(com.vaadin.flow.component.ItemLabelGenerator<T> generator)
    Convenience method, which sets the item label generator used by *BOTH* ComboBox and the ChipComponents.
    void
    void
    void
    setPlaceholder(String placeholder)
     
    protected void
    setPresentationValue(Set<T> newPresentationValue)
     
    void
    setReadOnly(boolean readOnly)
    void
    setRequiredIndicatorVisible(boolean requiredIndicatorVisible)
    void
    setValue(Set<T> value)
    protected void
     
    protected void
     
    protected void
     
    protected void
    Updates/Rebuilds the UI from the fields
    protected void
    updateValues(Set<T> newValues, boolean isFromClient)
    Updates the underlying values (if the newValues doesn't equals the oldValue)
    withAllAvailableItems(Collection<T> allAvailableItems)
     
    withChipItemLabelGenerator(com.vaadin.flow.component.ItemLabelGenerator<T> generator)
    Sets the item label generator used by the individual ChipComponents.
    withChipsSupplier(com.vaadin.flow.function.SerializableFunction<T,ChipComponent<T>> chipsSupplier)
     
    withClearAllButtonVisible(boolean clearAllButtonVisible)
     
    withClearAllIcon(com.vaadin.flow.component.Component clearAllIcon)
     
    withFullComboBoxWidth(boolean useFullWidth)
     
    withItemLabelGenerator(com.vaadin.flow.component.ItemLabelGenerator<T> generator)
    Convenience method, which sets the item label generator used by *BOTH* ComboBox and the ChipComponents.
     
    withPlaceholder(String placeholder)
     

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

    addValueChangeListener, getEmptyValue, getValue, isEmpty, setModelValue, valueEquals

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

    getChildren, getContent, getElement, initContent

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

    addListener, findAncestor, fireEvent, from, get, getEventBus, getId, getListeners, getLocale, getParent, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onAttach, 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, 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.data.binder.HasItems

    setItems, setItems

    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.data.binder.HasValidator

    addValidationStatusChangeListener, getDefaultValidator

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

    clear, getOptionalValue

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

    isReadOnly
  • Field Details

    • cbAvailableItems

      protected com.vaadin.flow.component.combobox.ComboBox<T> cbAvailableItems
    • btnClearAll

      protected com.vaadin.flow.component.button.Button btnClearAll
    • comboBoxContainer

      protected com.vaadin.flow.component.orderedlayout.HorizontalLayout comboBoxContainer
    • chipsContainer

      protected com.vaadin.flow.component.orderedlayout.FlexLayout chipsContainer
    • chipsSupplier

      protected com.vaadin.flow.function.SerializableFunction<T,ChipComponent<T>> chipsSupplier
    • chipItemLabelGenerator

      protected com.vaadin.flow.component.ItemLabelGenerator<T> chipItemLabelGenerator
    • allAvailableItems

      protected final List<T> allAvailableItems
    • selectedComponents

      protected final List<ChipComponent<T>> selectedComponents
  • Constructor Details

    • ChipComboBox

      public ChipComboBox()
    • ChipComboBox

      public ChipComboBox(Set<T> defaultValue)
    • ChipComboBox

      public ChipComboBox(String label)
    • ChipComboBox

      public ChipComboBox(String label, Set<T> defaultValue)
  • Method Details

    • initUI

      protected void initUI()
    • initListeners

      protected void initListeners()
    • onCbAvailableItemsValueChanged

      protected void onCbAvailableItemsValueChanged(com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<com.vaadin.flow.component.combobox.ComboBox<T>,T> event)
    • onClickClearAll

      protected void onClickClearAll(com.vaadin.flow.component.ClickEvent<com.vaadin.flow.component.button.Button> event)
    • setPresentationValue

      protected void setPresentationValue(Set<T> newPresentationValue)
      Specified by:
      setPresentationValue in class com.vaadin.flow.component.AbstractCompositeField<com.vaadin.flow.component.orderedlayout.VerticalLayout,ChipComboBox<T>,Set<T>>
    • addItem

      protected void addItem(T item, boolean isFromClient)
    • removeItem

      protected void removeItem(T item, boolean isFromClient)
    • updateValues

      protected void updateValues(Set<T> newValues, boolean isFromClient)
      Updates the underlying values (if the newValues doesn't equals the oldValue)
    • updateUI

      protected void updateUI()
      Updates/Rebuilds the UI from the fields
    • updateSelectedChips

      protected void updateSelectedChips()
    • updateAvailableItems

      protected void updateAvailableItems()
    • updateRequiredIndicatorOfCbAvailableItems

      protected void updateRequiredIndicatorOfCbAvailableItems()
    • setItems

      public void setItems(Collection<T> items)
      Specified by:
      setItems in interface com.vaadin.flow.data.binder.HasItems<T>
    • getChipsSupplier

      public Function<T,ChipComponent<T>> getChipsSupplier()
      Returns the current supplier for creating new ChipComponents
      Returns:
      the current supplier for creating new ChipComponents
    • withChipsSupplier

      public ChipComboBox<T> withChipsSupplier(com.vaadin.flow.function.SerializableFunction<T,ChipComponent<T>> chipsSupplier)
      Returns:
      self
      See Also:
    • setChipsSupplier

      public void setChipsSupplier(com.vaadin.flow.function.SerializableFunction<T,ChipComponent<T>> chipsSupplier)
      Sets the supplier for creating new ChipComponents
      Parameters:
      chipsSupplier - supplier for creating new ChipComponents
    • getAllAvailableItems

      public List<T> getAllAvailableItems()
      Get all available items, that can potentially get selected
    • withAllAvailableItems

      public ChipComboBox<T> withAllAvailableItems(Collection<T> allAvailableItems)
    • getLabel

      public String getLabel()
      Specified by:
      getLabel in interface com.vaadin.flow.component.HasLabel
    • withLabel

      public ChipComboBox<T> withLabel(String label)
    • setLabel

      public void setLabel(String label)
      Specified by:
      setLabel in interface com.vaadin.flow.component.HasLabel
    • getPlaceholder

      public String getPlaceholder()
    • withPlaceholder

      public ChipComboBox<T> withPlaceholder(String placeholder)
    • setPlaceholder

      public void setPlaceholder(String placeholder)
    • isClearAllButtonVisible

      public boolean isClearAllButtonVisible()
      Returns:
      "Clear All Button" visibility. With this button it is possible to clear all selected items with one click. The default value is true.
    • withClearAllButtonVisible

      public ChipComboBox<T> withClearAllButtonVisible(boolean clearAllButtonVisible)
      Returns:
      self
      See Also:
    • setClearAllButtonVisible

      public void setClearAllButtonVisible(boolean clearAllButtonVisible)
      Sets the "Clear All Button" to visible or invisible. With this button it is possible to clear all selected items with one click. The default value is true.
      Parameters:
      clearAllButtonVisible - defines the visibility of the "Clear All Button".
    • getClearAllIcon

      public com.vaadin.flow.component.Component getClearAllIcon()
      Returns:
      "Clear All Button" icon. With this button it is possible to clear all selected items with one click. The default value is VaadinIcon.TRASH.
    • withClearAllIcon

      public ChipComboBox<T> withClearAllIcon(com.vaadin.flow.component.Component clearAllIcon)
      Returns:
      self
      See Also:
    • setClearAllIcon

      public void setClearAllIcon(com.vaadin.flow.component.Component clearAllIcon)
      Sets the "Clear All Button" icon. With this button it is possible to clear all selected items with one click. The default value is VaadinIcon.TRASH.
      Parameters:
      clearAllIcon - the "Clear All Button" icon.
    • withFullComboBoxWidth

      public ChipComboBox<T> withFullComboBoxWidth(boolean useFullWidth)
    • setFullComboBoxWidth

      public void setFullComboBoxWidth(boolean useFullWidth)
    • setChipItemLabelGenerator

      public void setChipItemLabelGenerator(com.vaadin.flow.component.ItemLabelGenerator<T> generator)
      Sets the item label generator used by the individual ChipComponents.
    • withChipItemLabelGenerator

      public ChipComboBox<T> withChipItemLabelGenerator(com.vaadin.flow.component.ItemLabelGenerator<T> generator)
      Sets the item label generator used by the individual ChipComponents. Equal to setChipItemLabelGenerator, but allows in-line usage for easier component creation.
      Returns:
      this
    • setItemLabelGenerator

      public void setItemLabelGenerator(com.vaadin.flow.component.ItemLabelGenerator<T> generator)
      Convenience method, which sets the item label generator used by *BOTH* ComboBox and the ChipComponents.
    • withItemLabelGenerator

      public ChipComboBox<T> withItemLabelGenerator(com.vaadin.flow.component.ItemLabelGenerator<T> generator)
      Convenience method, which sets the item label generator used by *BOTH* ComboBox and the ChipComponents. Identical with setItemLabelGenerator, but allows in-line usage for easier component creation.
      Returns:
      this
    • setValue

      public void setValue(Set<T> value)
      Specified by:
      setValue in interface com.vaadin.flow.component.HasValue<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<ChipComboBox<T>,Set<T>>,Set<T>>
      Overrides:
      setValue in class com.vaadin.flow.component.AbstractCompositeField<com.vaadin.flow.component.orderedlayout.VerticalLayout,ChipComboBox<T>,Set<T>>
    • setReadOnly

      public void setReadOnly(boolean readOnly)
      Specified by:
      setReadOnly in interface com.vaadin.flow.component.HasValue<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<ChipComboBox<T>,Set<T>>,Set<T>>
      Specified by:
      setReadOnly in interface com.vaadin.flow.component.HasValueAndElement<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<ChipComboBox<T>,Set<T>>,Set<T>>
    • setRequiredIndicatorVisible

      public void setRequiredIndicatorVisible(boolean requiredIndicatorVisible)
      Specified by:
      setRequiredIndicatorVisible in interface com.vaadin.flow.component.HasValue<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<ChipComboBox<T>,Set<T>>,Set<T>>
      Specified by:
      setRequiredIndicatorVisible in interface com.vaadin.flow.component.HasValueAndElement<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<ChipComboBox<T>,Set<T>>,Set<T>>
    • isRequiredIndicatorVisible

      public boolean isRequiredIndicatorVisible()
      Specified by:
      isRequiredIndicatorVisible in interface com.vaadin.flow.component.HasValue<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<ChipComboBox<T>,Set<T>>,Set<T>>
      Specified by:
      isRequiredIndicatorVisible in interface com.vaadin.flow.component.HasValueAndElement<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<ChipComboBox<T>,Set<T>>,Set<T>>
    • setErrorMessage

      public void setErrorMessage(String errorMessage)
      Specified by:
      setErrorMessage in interface com.vaadin.flow.component.HasValidation
    • getErrorMessage

      public String getErrorMessage()
      Specified by:
      getErrorMessage in interface com.vaadin.flow.component.HasValidation
    • setInvalid

      public void setInvalid(boolean invalid)
      Specified by:
      setInvalid in interface com.vaadin.flow.component.HasValidation
    • isInvalid

      public boolean isInvalid()
      Specified by:
      isInvalid in interface com.vaadin.flow.component.HasValidation
    • focus

      public void focus()
      Specified by:
      focus in interface com.vaadin.flow.component.Focusable<T>
    • blur

      public void blur()
      Specified by:
      blur in interface com.vaadin.flow.component.Focusable<T>
    • getCbAvailableItems

      public com.vaadin.flow.component.combobox.ComboBox<T> getCbAvailableItems()
      Returns the ComboBox which contains the available items.

      NOTE: If the contents are modified from the outside this component may break

    • getComboBoxContainer

      public com.vaadin.flow.component.orderedlayout.HorizontalLayout getComboBoxContainer()
      Returns the HorizontalLayout which contains cbAvailableItems.

      NOTE: If the contents are modified from the outside this component may break

    • getChipsContainer

      public com.vaadin.flow.component.orderedlayout.FlexLayout getChipsContainer()
      Returns the FlexLayout with the select items (as ChipComponents).

      NOTE: If the contents are modified from the outside this component may break