Class CollectionField<T,C extends Collection<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<C>
org.vaadin.miki.superfields.collections.CollectionField<T,C>
Type Parameters:
T - Type of the element in the collection.
C - Type of the collection.
All Implemented Interfaces:
com.vaadin.flow.component.AttachNotifier, com.vaadin.flow.component.BlurNotifier<com.vaadin.flow.component.customfield.CustomField<C>>, com.vaadin.flow.component.DetachNotifier, com.vaadin.flow.component.Focusable<com.vaadin.flow.component.customfield.CustomField<C>>, com.vaadin.flow.component.FocusNotifier<com.vaadin.flow.component.customfield.CustomField<C>>, 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<C>,C>,C>, com.vaadin.flow.component.HasValueAndElement<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<com.vaadin.flow.component.customfield.CustomField<C>,C>,C>, com.vaadin.flow.component.shared.HasTooltip, com.vaadin.flow.component.shared.HasValidationProperties, Serializable, HasHelperPositionable, HasId, HasLabelPositionable, WithHelperMixin<CollectionField<T,C>>, WithHelperPositionableMixin<CollectionField<T,C>>, WithIdMixin<CollectionField<T,C>>, WithLabelMixin<CollectionField<T,C>>, WithLabelPositionableMixin<CollectionField<T,C>>, WithValueMixin<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<com.vaadin.flow.component.customfield.CustomField<C>,C>,C,CollectionField<T,C>>, CollectionController, HasCollectionElementFilter<T>, HasCollectionValueComponentProvider<T>, WithCollectionElementFilterMixin<T,CollectionField<T,C>>, WithCollectionValueComponentProviderMixin<T,CollectionField<T,C>>

@CssImport(value="./styles/label-positions.css", themeFor="vaadin-custom-field") public class CollectionField<T,C extends Collection<T>> extends com.vaadin.flow.component.customfield.CustomField<C> implements CollectionController, WithIdMixin<CollectionField<T,C>>, com.vaadin.flow.component.HasStyle, WithCollectionValueComponentProviderMixin<T,CollectionField<T,C>>, WithHelperMixin<CollectionField<T,C>>, WithHelperPositionableMixin<CollectionField<T,C>>, WithValueMixin<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<com.vaadin.flow.component.customfield.CustomField<C>,C>,C,CollectionField<T,C>>, WithCollectionElementFilterMixin<T,CollectionField<T,C>>, WithLabelPositionableMixin<CollectionField<T,C>>, WithLabelMixin<CollectionField<T,C>>
All-purpose field for editing and maintaining values that are Collections. Allows filtering individual elements through setCollectionElementFilter(SerializablePredicate) (by default filters out all nulls).
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 CollectionLayoutProvider<com.vaadin.flow.component.orderedlayout.FlexLayout>
    Default layout provider.
    static final String
    CSS class name that will be added to the main layout of this component.
    static final int
    Integer value indicating no index being passed.

    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
    CollectionField(com.vaadin.flow.function.SerializableSupplier<C> emptyCollectionSupplier, com.vaadin.flow.function.SerializableSupplier<F> fieldSupplier)
    Creates new field using DEFAULT_LAYOUT_PROVIDER as root layout provider.
    CollectionField(com.vaadin.flow.function.SerializableSupplier<C> emptyCollectionSupplier, CollectionLayoutProvider<?> collectionLayoutProvider, com.vaadin.flow.function.SerializableSupplier<F> fieldSupplier)
    Creates new field.
    CollectionField(com.vaadin.flow.function.SerializableSupplier<C> emptyCollectionSupplier, CollectionLayoutProvider<?> collectionLayoutProvider, CollectionValueComponentProvider<T,?> collectionValueComponentProvider)
    Creates new field.
    CollectionField(com.vaadin.flow.function.SerializableSupplier<C> emptyCollectionSupplier, CollectionValueComponentProvider<T,?> collectionValueComponentProvider)
    Creates new field using DEFAULT_LAYOUT_PROVIDER as root layout provider.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(int atIndex)
    Adds a new component at a specified position, moving subsequent elements by one.
    void
     
    protected C
     
    com.vaadin.flow.function.SerializablePredicate<T>
    Returns current value filter.
    <W extends com.vaadin.flow.component.Component & com.vaadin.flow.component.HasValue<?, T>>
    CollectionValueComponentProvider<T,W>
    Returns the current provider used to generate components.
    void
    remove(int atIndex)
    Removes a component at given index.
    void
    Clears the collection and removes all elements from it.
    protected void
    Paints all fields that need repainting and assigns values from the collection to each of them.
    void
    setCollectionElementFilter(com.vaadin.flow.function.SerializablePredicate<T> collectionElementFilter)
    Sets a value filter.
    final void
    Sets new layout from a given provider and repaints all fields.
    final void
    Sets the provider used to generate components for each element of the collection.
    protected void
     
    void
    setReadOnly(boolean readOnly)
     
    int
    Returns the current size of the collection.
    protected void
    updateIndices(int fromIndex)
    Updates all indices on all fields that implement HasIndex.
    protected void
     

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

    add, addThemeVariants, getLabel, onAttach, remove, removeThemeVariants, setLabel

    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 org.vaadin.miki.superfields.collections.CollectionController

    add, isEmpty, remove

    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.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.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, setRequiredIndicatorVisible

    Methods inherited from interface org.vaadin.miki.superfields.collections.WithCollectionElementFilterMixin

    withCollectionElementFilter

    Methods inherited from interface org.vaadin.miki.superfields.collections.WithCollectionValueComponentProviderMixin

    withCollectionComponentProvider

    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.WithLabelMixin

    withLabel

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

    withLabelPosition

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

    withValue
  • Field Details

    • LAYOUT_STYLE_NAME

      public static final String LAYOUT_STYLE_NAME
      CSS class name that will be added to the main layout of this component.
      See Also:
    • NO_ITEM_INDEX

      public static final int NO_ITEM_INDEX
      Integer value indicating no index being passed.
      See Also:
    • DEFAULT_LAYOUT_PROVIDER

      public static final CollectionLayoutProvider<com.vaadin.flow.component.orderedlayout.FlexLayout> DEFAULT_LAYOUT_PROVIDER
      Default layout provider. Produces a column-based FlexLayout.
  • Constructor Details

    • CollectionField

      public CollectionField(com.vaadin.flow.function.SerializableSupplier<C> emptyCollectionSupplier, com.vaadin.flow.function.SerializableSupplier<F> fieldSupplier)
      Creates new field using DEFAULT_LAYOUT_PROVIDER as root layout provider.
      Type Parameters:
      F - Type of the field used.
      Parameters:
      emptyCollectionSupplier - Provides an empty collection of elements.
      fieldSupplier - Method to call when a component for an element is needed.
    • CollectionField

      public CollectionField(com.vaadin.flow.function.SerializableSupplier<C> emptyCollectionSupplier, CollectionValueComponentProvider<T,?> collectionValueComponentProvider)
      Creates new field using DEFAULT_LAYOUT_PROVIDER as root layout provider.
      Parameters:
      emptyCollectionSupplier - Provides an empty collection of elements.
      collectionValueComponentProvider - Provider for components for each element in the component.
    • CollectionField

      public CollectionField(com.vaadin.flow.function.SerializableSupplier<C> emptyCollectionSupplier, CollectionLayoutProvider<?> collectionLayoutProvider, com.vaadin.flow.function.SerializableSupplier<F> fieldSupplier)
      Creates new field.
      Type Parameters:
      F - Type of the field used.
      Parameters:
      emptyCollectionSupplier - Provides an empty collection of elements.
      collectionLayoutProvider - Source of root layout for this component.
      fieldSupplier - Method to call when a component for an element is needed.
    • CollectionField

      public CollectionField(com.vaadin.flow.function.SerializableSupplier<C> emptyCollectionSupplier, CollectionLayoutProvider<?> collectionLayoutProvider, CollectionValueComponentProvider<T,?> collectionValueComponentProvider)
      Creates new field.
      Parameters:
      emptyCollectionSupplier - Provides an empty collection of elements.
      collectionLayoutProvider - Source of root layout for this component.
      collectionValueComponentProvider - Provider for components for each element in the component.
  • Method Details

    • setCollectionLayoutProvider

      public final void setCollectionLayoutProvider(CollectionLayoutProvider<?> collectionLayoutProvider)
      Sets new layout from a given provider and repaints all fields.
      Parameters:
      collectionLayoutProvider - A provider to use. Defaults to DEFAULT_LAYOUT_PROVIDER.
    • withCollectionLayoutProvider

      public final CollectionField<T,C> withCollectionLayoutProvider(CollectionLayoutProvider<?> collectionLayoutProvider)
      Parameters:
      collectionLayoutProvider - A provider to use. Defaults to DEFAULT_LAYOUT_PROVIDER.
      Returns:
      This.
      See Also:
    • setReadOnly

      public void setReadOnly(boolean readOnly)
      Specified by:
      setReadOnly in interface com.vaadin.flow.component.HasValue<T,C extends Collection<T>>
      Specified by:
      setReadOnly in interface com.vaadin.flow.component.HasValueAndElement<T,C extends Collection<T>>
    • generateModelValue

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

      protected void updateValue()
      Overrides:
      updateValue in class com.vaadin.flow.component.customfield.CustomField<C extends Collection<T>>
    • setPresentationValue

      protected void setPresentationValue(C ts)
      Specified by:
      setPresentationValue in class com.vaadin.flow.component.customfield.CustomField<C extends Collection<T>>
    • size

      public int size()
      Description copied from interface: CollectionController
      Returns the current size of the collection.
      Specified by:
      size in interface CollectionController
      Returns:
      A non-negative number.
    • updateIndices

      protected void updateIndices(int fromIndex)
      Updates all indices on all fields that implement HasIndex. This method is called after a component is removed or added, but before the value of the component is changed.
      Parameters:
      fromIndex - Index, from which the reindexing should occur.
    • add

      public void add(int atIndex)
      Description copied from interface: CollectionController
      Adds a new component at a specified position, moving subsequent elements by one.
      Specified by:
      add in interface CollectionController
      Parameters:
      atIndex - Index to add at.
    • remove

      public void remove(int atIndex)
      Description copied from interface: CollectionController
      Removes a component at given index. All subsequent components are moved forward by one.
      Specified by:
      remove in interface CollectionController
      Parameters:
      atIndex - Index to remove component at.
    • removeAll

      public void removeAll()
      Description copied from interface: CollectionController
      Clears the collection and removes all elements from it.
      Specified by:
      removeAll in interface CollectionController
    • repaintFields

      protected void repaintFields(C ts)
      Paints all fields that need repainting and assigns values from the collection to each of them.
      Parameters:
      ts - Collection with elements.
    • setCollectionValueComponentProvider

      public final void setCollectionValueComponentProvider(CollectionValueComponentProvider<T,?> collectionValueComponentProvider)
      Description copied from interface: HasCollectionValueComponentProvider
      Sets the provider used to generate components for each element of the collection.
      Specified by:
      setCollectionValueComponentProvider in interface HasCollectionValueComponentProvider<T>
      Parameters:
      collectionValueComponentProvider - A non-null provider.
    • getCollectionValueComponentProvider

      public <W extends com.vaadin.flow.component.Component & com.vaadin.flow.component.HasValue<?, T>> CollectionValueComponentProvider<T,W> getCollectionValueComponentProvider()
      Description copied from interface: HasCollectionValueComponentProvider
      Returns the current provider used to generate components.
      Specified by:
      getCollectionValueComponentProvider in interface HasCollectionValueComponentProvider<T>
      Type Parameters:
      W - Generic type of the actual component.
      Returns:
      A non-null provider.
    • setCollectionElementFilter

      public void setCollectionElementFilter(com.vaadin.flow.function.SerializablePredicate<T> collectionElementFilter)
      Description copied from interface: HasCollectionElementFilter
      Sets a value filter. Only items matching the filter will be included in the generated value.
      Specified by:
      setCollectionElementFilter in interface HasCollectionElementFilter<T>
      Parameters:
      collectionElementFilter - Value filter to use.
    • getCollectionElementFilter

      public com.vaadin.flow.function.SerializablePredicate<T> getCollectionElementFilter()
      Description copied from interface: HasCollectionElementFilter
      Returns current value filter. All items in the value will pass this filter.
      Specified by:
      getCollectionElementFilter in interface HasCollectionElementFilter<T>
      Returns:
      A non-null filter.
    • focus

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