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>,com.vaadin.flow.component.DetachNotifier,com.vaadin.flow.component.Focusable<com.vaadin.flow.component.customfield.CustomField>,com.vaadin.flow.component.FocusNotifier<com.vaadin.flow.component.customfield.CustomField>,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,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 areCollections. Allows filtering individual elements throughsetCollectionElementFilter(SerializablePredicate)(by default filters out allnulls).- See Also:
- Serialized Form
-
-
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 CollectionLayoutProvider<com.vaadin.flow.component.orderedlayout.FlexLayout>DEFAULT_LAYOUT_PROVIDERDefault layout provider.static StringLAYOUT_STYLE_NAMECSS class name that will be added to the main layout of this component.static intNO_ITEM_INDEXInteger 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 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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(int atIndex)Adds a new component at a specified position, moving subsequent elements by one.voidfocus()protected CgenerateModelValue()com.vaadin.flow.function.SerializablePredicate<T>getCollectionElementFilter()Returns current value filter.<W extends com.vaadin.flow.component.Component & com.vaadin.flow.component.HasValue<?,T>>
CollectionValueComponentProvider<T,W>getCollectionValueComponentProvider()Returns the current provider used to generate components.voidremove(int atIndex)Removes a component at given index.voidremoveAll()Clears 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.voidsetCollectionLayoutProvider(CollectionLayoutProvider<?> collectionLayoutProvider)Sets new layout from a given provider and repaints all fields.voidsetCollectionValueComponentProvider(CollectionValueComponentProvider<T,?> collectionValueComponentProvider)Sets the provider used to generate components for each element of the collection.protected voidsetPresentationValue(C ts)voidsetReadOnly(boolean readOnly)intsize()Returns the current size of the collection.protected voidupdateIndices(int fromIndex)Updates all indices on all fields that implementHasIndex.protected voidupdateValue()CollectionField<T,C>withCollectionLayoutProvider(CollectionLayoutProvider<?> collectionLayoutProvider)ChainssetCollectionLayoutProvider(CollectionLayoutProvider)and returns itself.-
Methods inherited from class com.vaadin.flow.component.customfield.CustomField
add, addThemeVariants, getErrorMessage, getLabel, isInvalid, onAttach, remove, removeThemeVariants, setErrorMessage, setInvalid, 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, 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 org.vaadin.miki.superfields.collections.CollectionController
add, isEmpty, remove
-
Methods inherited from interface com.vaadin.flow.component.Focusable
addFocusShortcut, blur, getTabIndex, setTabIndex
-
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.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.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 Detail
-
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:
- Constant Field Values
-
NO_ITEM_INDEX
public static final int NO_ITEM_INDEX
Integer value indicating no index being passed.- See Also:
- Constant Field Values
-
DEFAULT_LAYOUT_PROVIDER
public static final CollectionLayoutProvider<com.vaadin.flow.component.orderedlayout.FlexLayout> DEFAULT_LAYOUT_PROVIDER
Default layout provider. Produces a column-basedFlexLayout.
-
-
Constructor Detail
-
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 Detail
-
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 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:
setCollectionLayoutProvider(CollectionLayoutProvider)
-
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
protected C 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
protected void setPresentationValue(C ts)
- 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
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: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
public com.vaadin.flow.function.SerializablePredicate<T> 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>
-
-