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
FieldsModifier and TypeFieldDescriptionstatic final CollectionLayoutProvider<com.vaadin.flow.component.orderedlayout.FlexLayout>Default layout provider.static final StringCSS class name that will be added to the main layout of this component.static final intInteger value indicating no index being passed.Fields 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
ConstructorsConstructorDescriptionCollectionField(com.vaadin.flow.function.SerializableSupplier<C> emptyCollectionSupplier, com.vaadin.flow.function.SerializableSupplier<F> fieldSupplier) Creates new field usingDEFAULT_LAYOUT_PROVIDERas 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 usingDEFAULT_LAYOUT_PROVIDERas root layout provider. -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(int atIndex) Adds a new component at a specified position, moving subsequent elements by one.voidfocus()protected Ccom.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.voidremove(int atIndex) Removes a component at given index.voidClears the collection and removes all elements from it.protected voidrepaintFields(C ts) Paints all fields that need repainting and assigns values from the collection to each of them.voidsetCollectionElementFilter(com.vaadin.flow.function.SerializablePredicate<T> collectionElementFilter) Sets a value filter.final voidsetCollectionLayoutProvider(CollectionLayoutProvider<?> collectionLayoutProvider) Sets new layout from a given provider and repaints all fields.final voidsetCollectionValueComponentProvider(CollectionValueComponentProvider<T, ?> collectionValueComponentProvider) Sets the provider used to generate components for each element of the collection.protected voidvoidsetReadOnly(boolean readOnly) intsize()Returns the current size of the collection.protected voidupdateIndices(int fromIndex) Updates all indices on all fields that implementHasIndex.protected voidfinal CollectionField<T,C> withCollectionLayoutProvider(CollectionLayoutProvider<?> collectionLayoutProvider) ChainssetCollectionLayoutProvider(CollectionLayoutProvider)and returns itself.Methods inherited from class com.vaadin.flow.component.customfield.CustomField
add, addThemeVariants, getLabel, onAttach, remove, removeThemeVariants, setLabelMethods 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 org.vaadin.miki.superfields.collections.CollectionController
add, isEmpty, removeMethods 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.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.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, setRequiredIndicatorVisibleMethods inherited from interface org.vaadin.miki.superfields.collections.WithCollectionElementFilterMixin
withCollectionElementFilterMethods inherited from interface org.vaadin.miki.superfields.collections.WithCollectionValueComponentProviderMixin
withCollectionComponentProviderMethods 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.WithLabelMixin
withLabelMethods inherited from interface org.vaadin.miki.markers.WithLabelPositionableMixin
withLabelPositionMethods inherited from interface org.vaadin.miki.markers.WithValueMixin
withValue
-
Field Details
-
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_INDEXInteger value indicating no index being passed.- See Also:
-
DEFAULT_LAYOUT_PROVIDER
public static final CollectionLayoutProvider<com.vaadin.flow.component.orderedlayout.FlexLayout> DEFAULT_LAYOUT_PROVIDERDefault layout provider. Produces a column-basedFlexLayout.
-
-
Constructor Details
-
CollectionField
public CollectionField(com.vaadin.flow.function.SerializableSupplier<C> emptyCollectionSupplier, com.vaadin.flow.function.SerializableSupplier<F> fieldSupplier) Creates new field usingDEFAULT_LAYOUT_PROVIDERas 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 usingDEFAULT_LAYOUT_PROVIDERas 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
Sets new layout from a given provider and repaints all fields.- Parameters:
collectionLayoutProvider- A provider to use. Defaults toDEFAULT_LAYOUT_PROVIDER.
-
withCollectionLayoutProvider
public final CollectionField<T,C> withCollectionLayoutProvider(CollectionLayoutProvider<?> collectionLayoutProvider) ChainssetCollectionLayoutProvider(CollectionLayoutProvider)and returns itself.- Parameters:
collectionLayoutProvider- A provider to use. Defaults toDEFAULT_LAYOUT_PROVIDER.- Returns:
- This.
- See Also:
-
setReadOnly
public void setReadOnly(boolean readOnly) - Specified by:
setReadOnlyin interfacecom.vaadin.flow.component.HasValue<T,C extends Collection<T>> - Specified by:
setReadOnlyin interfacecom.vaadin.flow.component.HasValueAndElement<T,C extends Collection<T>>
-
generateModelValue
- Specified by:
generateModelValuein classcom.vaadin.flow.component.customfield.CustomField<C extends Collection<T>>
-
updateValue
protected void updateValue()- Overrides:
updateValuein classcom.vaadin.flow.component.customfield.CustomField<C extends Collection<T>>
-
setPresentationValue
- Specified by:
setPresentationValuein classcom.vaadin.flow.component.customfield.CustomField<C extends Collection<T>>
-
size
public int size()Description copied from interface:CollectionControllerReturns the current size of the collection.- Specified by:
sizein interfaceCollectionController- Returns:
- A non-negative number.
-
updateIndices
protected void updateIndices(int fromIndex) Updates all indices on all fields that implementHasIndex. 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:CollectionControllerAdds a new component at a specified position, moving subsequent elements by one.- Specified by:
addin interfaceCollectionController- Parameters:
atIndex- Index to add at.
-
remove
public void remove(int atIndex) Description copied from interface:CollectionControllerRemoves a component at given index. All subsequent components are moved forward by one.- Specified by:
removein interfaceCollectionController- Parameters:
atIndex- Index to remove component at.
-
removeAll
public void removeAll()Description copied from interface:CollectionControllerClears the collection and removes all elements from it.- Specified by:
removeAllin interfaceCollectionController
-
repaintFields
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:HasCollectionValueComponentProviderSets the provider used to generate components for each element of the collection.- Specified by:
setCollectionValueComponentProviderin interfaceHasCollectionValueComponentProvider<T>- Parameters:
collectionValueComponentProvider- A non-nullprovider.
-
getCollectionValueComponentProvider
public <W extends com.vaadin.flow.component.Component & com.vaadin.flow.component.HasValue<?,T>> CollectionValueComponentProvider<T,W> getCollectionValueComponentProvider()Description copied from interface:HasCollectionValueComponentProviderReturns the current provider used to generate components.- Specified by:
getCollectionValueComponentProviderin interfaceHasCollectionValueComponentProvider<T>- Type Parameters:
W- Generic type of the actual component.- Returns:
- A non-
nullprovider.
-
setCollectionElementFilter
public void setCollectionElementFilter(com.vaadin.flow.function.SerializablePredicate<T> collectionElementFilter) Description copied from interface:HasCollectionElementFilterSets a value filter. Only items matching the filter will be included in the generated value.- Specified by:
setCollectionElementFilterin interfaceHasCollectionElementFilter<T>- Parameters:
collectionElementFilter- Value filter to use.
-
getCollectionElementFilter
Description copied from interface:HasCollectionElementFilterReturns current value filter. All items in the value will pass this filter.- Specified by:
getCollectionElementFilterin interfaceHasCollectionElementFilter<T>- Returns:
- A non-
nullfilter.
-
focus
public void focus()- Specified by:
focusin interfacecom.vaadin.flow.component.Focusable<T>
-