Package com.storedobject.vaadin
Class CommentField
java.lang.Object
- All Implemented Interfaces:
com.vaadin.flow.component.AttachNotifier,com.vaadin.flow.component.BlurNotifier<com.vaadin.flow.component.customfield.CustomField<String>>,com.vaadin.flow.component.DetachNotifier,com.vaadin.flow.component.Focusable<com.vaadin.flow.component.customfield.CustomField<String>>,com.vaadin.flow.component.FocusNotifier<com.vaadin.flow.component.customfield.CustomField<String>>,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<String>,,String>, String> com.vaadin.flow.component.HasValueAndElement<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<com.vaadin.flow.component.customfield.CustomField<String>,,String>, String> com.vaadin.flow.component.shared.HasTooltip,com.vaadin.flow.component.shared.HasValidationProperties,com.vaadin.flow.component.shared.InputField<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<com.vaadin.flow.component.customfield.CustomField<String>,,String>, String> Serializable
A custom field implementation for managing and editing text comments.
The field includes a popover for editing values, with an icon that indicates
the state of the field and buttons for saving or cancelling changes.
- Author:
- Syam
- 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> 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>, com.vaadin.flow.component.HasValue.ValueChangeListener<E extends com.vaadin.flow.component.HasValue.ValueChangeEvent<?>> -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final ButtonLayoutRepresents the layout container for managing and organizing buttons within the CommentField component.protected ButtonRepresents the cancel button in the CommentField component.protected ButtonThe "OK" button used within the CommentField component. -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new instance of the CommentField with no initial label or value.CommentField(String label) Constructs a CommentField with a specified label.CommentField(String label, String value) Constructs a CommentField instance with a specified label and initial value. -
Method Summary
Modifier and TypeMethodDescriptioncom.vaadin.flow.shared.RegistrationaddCancelledListener(Consumer<CommentField> listener) Registers a listener to be notified when the "Cancel" button is clicked in the CommentField.com.vaadin.flow.shared.RegistrationaddSavedListener(Consumer<CommentField> listener) Registers a listener that will be invoked when a comment is saved.protected voidBuilds and initializes the "OK" and "Cancel" buttons for the CommentField.voidclose()Closes the associated popover in the CommentField.protected Stringprotected booleanisBlank()Determines whether the current value of the comment field is blank.voidopen()Opens the popover associated with the CommentField.static voidsetActiveColor(String activeColor) Sets the active color for the comment field.static voidsetBlankColor(String blankColor) Sets the color to be used when the comment field value is blank.voidsetEnabled(boolean enabled) protected voidvoidsetReadOnly(boolean readOnly) voidsetTextAreaHeight(int heightInPixels) Sets the height of the text area within the CommentField.voidsetTextAreaWidth(int widthInPixels) Sets the width of the text area in pixels.voidUpdates the appearance of the icon based on the current state of the comment field.Methods inherited from class com.storedobject.vaadin.CustomField
addField, addField, focusMethods inherited from class com.vaadin.flow.component.customfield.CustomField
add, addThemeVariants, getLabel, 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, onAttach, 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
isEnabledMethods inherited from interface com.vaadin.flow.component.HasHelper
getHelperComponent, getHelperText, setHelperComponent, setHelperTextMethods 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.HasValidation
setManualValidationMethods 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, setRequiredIndicatorVisible
-
Field Details
-
buttonLayout
Represents the layout container for managing and organizing buttons within the CommentField component. This layout is used to house and structure interactive elements like "ok" and "cancel" buttons. It ensures a consistent arrangement of buttons when interacting with the component's UI. The layout is immutable and is initialized when the CommentField is instantiated. -
ok
The "OK" button used within the CommentField component. This button is typically associated with a confirmation or save action for the input provided in the component. -
cancel
Represents the cancel button in the CommentField component. This variable is used to handle the cancellation events within the comment editing functionality. It allows users to discard any unsaved changes they make to the comment field.
-
-
Constructor Details
-
CommentField
public CommentField()Constructs a new instance of the CommentField with no initial label or value. This constructor initializes the field with a null label and an empty value. -
CommentField
Constructs a CommentField with a specified label.- Parameters:
label- the label to set for the comment field; a null value will not set a label
-
CommentField
Constructs a CommentField instance with a specified label and initial value.- Parameters:
label- the label to display for the CommentField. If null, no label is set.value- the initial value of the CommentField. If blank or null, the icon color will be grey.
-
-
Method Details
-
setBlankColor
Sets the color to be used when the comment field value is blank. This method allows defining a visual indicator (like a background color) for the blank state of the comment field.- Parameters:
blankColor- the color value to set for the blank state; must be a valid color format
-
setActiveColor
Sets the active color for the comment field. The active color is used to visually indicate the non-blank state of the comment field, such as highlighting the icon or other UI elements when a value is present.- Parameters:
activeColor- the color value to set for the active state; must be a valid color format
-
updateIconAppearance
public void updateIconAppearance()Updates the appearance of the icon based on the current state of the comment field. The method evaluates whether the comment field's value is blank by invoking theisBlankmethod. If the value is determined to be blank, the icon's color is set to the value ofblankColor. Otherwise, the icon's color is set to the value ofactiveColor. -
isBlank
protected boolean isBlank()Determines whether the current value of the comment field is blank. This method checks if the underlying value string is empty or contains only whitespace characters.- Returns:
trueif the current value is blank,falseotherwise
-
generateModelValue
-
setPresentationValue
-
setTextAreaWidth
public void setTextAreaWidth(int widthInPixels) Sets the width of the text area in pixels. This method adjusts the width of the comment field's text area to the specified value, applying the width as a CSS pixel value.- Parameters:
widthInPixels- the desired width of the text area in pixels; must be a non-negative integer
-
setTextAreaHeight
public void setTextAreaHeight(int heightInPixels) Sets the height of the text area within the CommentField. This method adjusts the visual height of the text area to the specified value in pixels.- Parameters:
heightInPixels- the desired height of the text area in pixels; must be a non-negative integer
-
buildButtons
protected void buildButtons()Builds and initializes the "OK" and "Cancel" buttons for the CommentField.The "OK" button is configured to: - Close the associated popover when clicked. - Trigger the `updateValue` method to update the field's value. - Notify all registered saved listeners by invoking their `accept` method with the current instance. The "Cancel" button is configured to: - Close the associated popover when clicked. - Notify all registered cancelled listeners by invoking their `accept` method with the current instance.
Both buttons are styled, with the "OK" button being a primary button and both buttons rendered in a small size. The buttons are added to the `buttonLayout` of the field. -
setReadOnly
public void setReadOnly(boolean readOnly) -
setEnabled
public void setEnabled(boolean enabled) -
addSavedListener
Registers a listener that will be invoked when a comment is saved. The provided listener is triggered whenever the "save" action is performed on this comment field. The listener consumes the current instance ofCommentField.- Parameters:
listener- theConsumerto be invoked when the comment is saved; must not be null- Returns:
- a
Registrationobject that can be used to remove the listener
-
addCancelledListener
Registers a listener to be notified when the "Cancel" button is clicked in the CommentField.- Parameters:
listener- aConsumerthat accepts the current instance ofCommentField, invoked when the "Cancel" button is clicked.- Returns:
- a
Registrationobject that can be used to remove the registered listener.
-
open
public void open()Opens the popover associated with the CommentField. This method triggers the display of the popover, allowing the user to interact with the CommentField, such as entering or modifying text content. -
close
public void close()Closes the associated popover in the CommentField. This method is responsible for hiding or dismissing the popover element associated with the CommentField. It gets invoked typically when the user interacts with the "Cancel" or "OK" buttons, or in other scenarios where the popover should no longer be displayed.
-