Class ObjectField<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<T>
org.vaadin.miki.superfields.object.ObjectField<T>
- 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,Serializable,HasHelperPositionable,HasId,HasLabelPositionable,WithHelperMixin<ObjectField<T>>,WithHelperPositionableMixin<ObjectField<T>>,WithIdMixin<ObjectField<T>>,WithLabelMixin<ObjectField<T>>,WithLabelPositionableMixin<ObjectField<T>>,WithValueMixin<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<com.vaadin.flow.component.customfield.CustomField<T>,T>, T, ObjectField<T>>
@CssImport(value="./styles/label-positions.css",
themeFor="vaadin-custom-field")
public class ObjectField<T>
extends com.vaadin.flow.component.customfield.CustomField<T>
implements com.vaadin.flow.component.HasStyle, WithHelperMixin<ObjectField<T>>, WithHelperPositionableMixin<ObjectField<T>>, WithIdMixin<ObjectField<T>>, WithLabelMixin<ObjectField<T>>, WithLabelPositionableMixin<ObjectField<T>>, WithValueMixin<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<com.vaadin.flow.component.customfield.CustomField<T>,T>,T,ObjectField<T>>
A field capable of displaying any object, provided it is known how to construct various elements of it.
Construction of the field happens in stages:
- obtain properties of the object
- group properties
- map each property to a component capable of showing that property
- configure components (individually and in defined groups)
- set value of each component
- Since:
- 2022-05-16
- 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
FieldsModifier and TypeFieldDescriptionstatic final com.vaadin.flow.function.SerializableSupplier<PropertyComponentBuilder>static final com.vaadin.flow.function.SerializableSupplier<PropertyGroupLayoutProvider>static final com.vaadin.flow.function.SerializableSupplier<PropertyGroupingProvider>static final com.vaadin.flow.function.SerializableSupplier<com.vaadin.flow.component.orderedlayout.FlexLayout>static final com.vaadin.flow.function.SerializableSupplier<PropertyProvider>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
ConstructorsConstructorDescriptionObjectField(Class<T> dataType, com.vaadin.flow.function.SerializableSupplier<T> emptyObjectSupplier) Builds anObjectFieldusingDEFAULT_LAYOUT_PROVIDERfor the main layout.ObjectField(Class<T> dataType, com.vaadin.flow.function.SerializableSupplier<T> emptyObjectSupplier, com.vaadin.flow.function.SerializableSupplier<L> layoutSupplier) Builds anObjectFieldusing a given supplier for the main layout. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddComponentConfigurators(Collection<ComponentConfigurator<T>> configurators) Adds givenComponentConfigurators.final voidaddComponentConfigurators(ComponentConfigurator<T>... configurators) Adds givenComponentConfigurators.voidaddComponentGroupConfigurators(Collection<ComponentGroupConfigurator> configurators) Adds givenComponentGroupConfigurators.voidaddComponentGroupConfigurators(ComponentGroupConfigurator... configurators) Adds givenComponentGroupConfigurators.voidRemoves all previously addedComponentConfigurator.voidRemoves all previously addedComponentGroupConfigurators.voidfocus()protected TReturns the type of the value returned by this field.Returns currentPropertyGroupLayoutProvider.Returns the currentPropertyComponentBuilder.Returns the currentPropertyGroupingProvider.Returns the currentPropertyProvider.protected booleanChecks if reloading is currently needed.protected voidIndicates that reload of data and components is needed.voidremoveComponentConfigurator(ComponentConfigurator<T> configurator) Removes given configurator.voidremoveComponentGroupConfigurator(ComponentGroupConfigurator configurator) Removes givenComponentGroupConfigurator.voidrepaint()Repaints the component with its current value.voidsetGroupLayoutProvider(PropertyGroupLayoutProvider groupLayoutProvider) Sets the newPropertyGroupLayoutProvider.protected voidvoidSets the newPropertyComponentBuilder.voidsetPropertyGroupingProvider(PropertyGroupingProvider propertyGroupingProvider) Sets the newPropertyGroupingProvider.voidsetPropertyProvider(PropertyProvider propertyProvider) Sets the newPropertyProvider.voidsetReadOnly(boolean readOnly) final ObjectField<T>withComponentConfigurators(Collection<ComponentConfigurator<T>> configurators) ChainsaddComponentConfigurators(Collection)and returns itself.final ObjectField<T>withComponentConfigurators(ComponentConfigurator<T>... configurators) ChainsaddComponentConfigurators(ComponentConfigurator[])and returns itself.final ObjectField<T>withComponentGroupConfigurators(Collection<ComponentGroupConfigurator> configurators) ChainsaddComponentGroupConfigurators(Collection)and returns itself.final ObjectField<T>withComponentGroupConfigurators(ComponentGroupConfigurator... configurators) ChainsaddComponentGroupConfigurators(ComponentGroupConfigurator...)and returns itself.final ObjectField<T>ChainssetGroupLayoutProvider(PropertyGroupLayoutProvider)and returns itself.final ObjectField<T>ChainssetPropertyComponentBuilder(PropertyComponentBuilder)and returns itself.final ObjectField<T>ChainssetPropertyGroupingProvider(PropertyGroupingProvider)and returns itself.final ObjectField<T>withPropertyProvider(PropertyProvider provider) ChainssetPropertyProvider(PropertyProvider)and returns itself.Methods inherited from class com.vaadin.flow.component.customfield.CustomField
add, addThemeVariants, getLabel, onAttach, remove, removeThemeVariants, setLabel, 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.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.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
-
DEFAULT_LAYOUT_PROVIDER
public static final com.vaadin.flow.function.SerializableSupplier<com.vaadin.flow.component.orderedlayout.FlexLayout> DEFAULT_LAYOUT_PROVIDER -
DEFAULT_PROPERTY_PROVIDER
public static final com.vaadin.flow.function.SerializableSupplier<PropertyProvider> DEFAULT_PROPERTY_PROVIDER -
DEFAULT_COMPONENT_BUILDER
public static final com.vaadin.flow.function.SerializableSupplier<PropertyComponentBuilder> DEFAULT_COMPONENT_BUILDER -
DEFAULT_GROUPING_PROVIDER
public static final com.vaadin.flow.function.SerializableSupplier<PropertyGroupingProvider> DEFAULT_GROUPING_PROVIDER -
DEFAULT_GROUP_LAYOUT_PROVIDER
public static final com.vaadin.flow.function.SerializableSupplier<PropertyGroupLayoutProvider> DEFAULT_GROUP_LAYOUT_PROVIDER
-
-
Constructor Details
-
ObjectField
public ObjectField(Class<T> dataType, com.vaadin.flow.function.SerializableSupplier<T> emptyObjectSupplier) Builds anObjectFieldusingDEFAULT_LAYOUT_PROVIDERfor the main layout.- Parameters:
dataType- Type of objects to display.emptyObjectSupplier- A method to provide new, empty objects of the given type.
-
ObjectField
public ObjectField(Class<T> dataType, com.vaadin.flow.function.SerializableSupplier<T> emptyObjectSupplier, com.vaadin.flow.function.SerializableSupplier<L> layoutSupplier) Builds anObjectFieldusing a given supplier for the main layout.- Type Parameters:
L- Layout type.- Parameters:
dataType- Type of objects to display.emptyObjectSupplier- A method to provide new, empty objects of the given type.layoutSupplier- A method to provide the main layout of this component.
-
-
Method Details
-
generateModelValue
- Specified by:
generateModelValuein classcom.vaadin.flow.component.customfield.CustomField<T>
-
repaint
public void repaint()Repaints the component with its current value. In some rare cases it makes sense to completely reload the components without changing the value of this field. -
setPresentationValue
- Specified by:
setPresentationValuein classcom.vaadin.flow.component.customfield.CustomField<T>
-
getDataType
Returns the type of the value returned by this field.- Returns:
- Type.
-
markReloadNeeded
protected void markReloadNeeded()Indicates that reload of data and components is needed. -
isReloadNeeded
protected boolean isReloadNeeded()Checks if reloading is currently needed.- Returns:
- When
true, the inner state of the component will be reloaded the next time a value is displayed.
-
getPropertyProvider
Returns the currentPropertyProvider.- Returns:
- Current
PropertyProvider.
-
setPropertyProvider
Sets the newPropertyProvider. Note that changes will not be reflected until the component isrepaint()ed or a new value is set.- Parameters:
propertyProvider- APropertyProviderto use. Ifnullis passed, one provided byDEFAULT_PROPERTY_PROVIDERwill be used.
-
withPropertyProvider
ChainssetPropertyProvider(PropertyProvider)and returns itself.- Parameters:
provider- APropertyProviderto use.- Returns:
- This.
- See Also:
-
setPropertyComponentBuilder
Sets the newPropertyComponentBuilder. Note that changes will not be reflected until the component isrepaint()ed or a new value is set.- Parameters:
builder- APropertyComponentBuilderto use. Ifnullis passed, one provided byDEFAULT_COMPONENT_BUILDERwill be used.
-
getPropertyComponentBuilder
Returns the currentPropertyComponentBuilder.- Returns:
- A
PropertyComponentBuilder.
-
withPropertyComponentBuilder
ChainssetPropertyComponentBuilder(PropertyComponentBuilder)and returns itself.- Parameters:
builder- Builder.- Returns:
- This.
- See Also:
-
setPropertyGroupingProvider
Sets the newPropertyGroupingProvider. Note that changes will not be reflected until the component isrepaint()ed or a new value is set.- Parameters:
propertyGroupingProvider- APropertyGroupingProviderto use. Ifnullis passed, one provided byDEFAULT_GROUPING_PROVIDERwill be used.
-
getPropertyGroupingProvider
Returns the currentPropertyGroupingProvider.- Returns:
- A
PropertyGroupingProvider.
-
withPropertyGroupingProvider
ChainssetPropertyGroupingProvider(PropertyGroupingProvider)and returns itself.- Parameters:
provider- Provider.- Returns:
- This.
- See Also:
-
getGroupLayoutProvider
Returns currentPropertyGroupLayoutProvider.- Returns:
- A
PropertyGroupLayoutProvider.
-
setGroupLayoutProvider
Sets the newPropertyGroupLayoutProvider. Note that changes will not be reflected until the component isrepaint()ed or a new value is set.- Parameters:
groupLayoutProvider- APropertyGroupLayoutProviderto use. Ifnullis passed, one provided byDEFAULT_GROUP_LAYOUT_PROVIDERwill be used.
-
withGroupLayoutProvider
ChainssetGroupLayoutProvider(PropertyGroupLayoutProvider)and returns itself.- Parameters:
provider- Provider.- Returns:
- This.
- See Also:
-
addComponentConfigurators
Adds givenComponentConfigurators. Each configurator receives every component for each property. Configurators are run in the order of adding. Note that changes will not be reflected until the component isrepaint()ed or a new value is set.- Parameters:
configurators- Configurators to add.
-
addComponentConfigurators
Adds givenComponentConfigurators. Each configurator receives every component for each property. Configurators are run in the order of adding. Note that changes will not be reflected until the component isrepaint()ed or a new value is set.- Parameters:
configurators- Configurators to add.
-
removeComponentConfigurator
Removes given configurator.- Parameters:
configurator- Configurator to remove.
-
withComponentConfigurators
@SafeVarargs public final ObjectField<T> withComponentConfigurators(ComponentConfigurator<T>... configurators) ChainsaddComponentConfigurators(ComponentConfigurator[])and returns itself.- Parameters:
configurators- Configurators to add.- Returns:
- This.
- See Also:
-
withComponentConfigurators
public final ObjectField<T> withComponentConfigurators(Collection<ComponentConfigurator<T>> configurators) ChainsaddComponentConfigurators(Collection)and returns itself.- Parameters:
configurators- Configurators to add.- Returns:
- This.
- See Also:
-
clearComponentConfigurators
public void clearComponentConfigurators()Removes all previously addedComponentConfigurator. Note that changes will not be reflected until the component isrepaint()ed or a new value is set. -
addComponentGroupConfigurators
Adds givenComponentGroupConfigurators. Each configurator receives every group of components after basicComponentConfigurators are executed. Configurators are run in the order of adding. Note that changes will not be reflected until the component isrepaint()ed or a new value is set.- Parameters:
configurators- Configurators to add.
-
addComponentGroupConfigurators
Adds givenComponentGroupConfigurators. Each configurator receives every group of components after basicComponentConfigurators are executed. Configurators are run in the order of adding. Note that changes will not be reflected until the component isrepaint()ed or a new value is set.- Parameters:
configurators- Configurators to add.
-
removeComponentGroupConfigurator
Removes givenComponentGroupConfigurator. Note that changes will not be reflected until the component isrepaint()ed or a new value is set.- Parameters:
configurator- Configurator to remove.
-
withComponentGroupConfigurators
public final ObjectField<T> withComponentGroupConfigurators(ComponentGroupConfigurator... configurators) ChainsaddComponentGroupConfigurators(ComponentGroupConfigurator...)and returns itself.- Parameters:
configurators- Configurators to add.- Returns:
- This.
- See Also:
-
withComponentGroupConfigurators
public final ObjectField<T> withComponentGroupConfigurators(Collection<ComponentGroupConfigurator> configurators) ChainsaddComponentGroupConfigurators(Collection)and returns itself.- Parameters:
configurators- Configurators to add.- Returns:
- This.
- See Also:
-
clearComponentGroupConfigurators
public void clearComponentGroupConfigurators()Removes all previously addedComponentGroupConfigurators. Note that changes will not be reflected until the component isrepaint()ed or a new value is set. -
setReadOnly
public void setReadOnly(boolean readOnly) - Specified by:
setReadOnlyin interfacecom.vaadin.flow.component.HasValue<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<com.vaadin.flow.component.customfield.CustomField<T>,T>, T> - Specified by:
setReadOnlyin interfacecom.vaadin.flow.component.HasValueAndElement<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<com.vaadin.flow.component.customfield.CustomField<T>,T>, T>
-
focus
public void focus()- Specified by:
focusin interfacecom.vaadin.flow.component.Focusable<T>
-