Package com.storedobject.vaadin.util
Class BasicComboList<T>
java.lang.Object
com.vaadin.flow.component.Component
com.vaadin.flow.component.AbstractField<com.vaadin.flow.component.listbox.ListBox<T>,T>
com.vaadin.flow.component.AbstractSinglePropertyField<com.vaadin.flow.component.listbox.ListBox<T>,T>
com.vaadin.flow.component.listbox.ListBoxBase<com.vaadin.flow.component.listbox.ListBox<T>,T,T>
com.vaadin.flow.component.listbox.ListBox<T>
com.storedobject.vaadin.util.BasicComboList<T>
- Type Parameters:
T
- the type of items managed by this combo list
- All Implemented Interfaces:
com.vaadin.flow.component.AttachNotifier
,com.vaadin.flow.component.DetachNotifier
,com.vaadin.flow.component.HasAriaLabel
,com.vaadin.flow.component.HasComponents
,com.vaadin.flow.component.HasElement
,com.vaadin.flow.component.HasEnabled
,com.vaadin.flow.component.HasSize
,com.vaadin.flow.component.HasStyle
,com.vaadin.flow.component.HasValue<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<com.vaadin.flow.component.listbox.ListBox<T>,
,T>, T> com.vaadin.flow.component.HasValueAndElement<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<com.vaadin.flow.component.listbox.ListBox<T>,
,T>, T> com.vaadin.flow.component.shared.HasTooltip
,com.vaadin.flow.data.binder.HasItemComponents<T>
,com.vaadin.flow.data.provider.HasDataView<T,
,Void, com.vaadin.flow.component.listbox.dataview.ListBoxDataView<T>> com.vaadin.flow.data.provider.HasListDataView<T,
,com.vaadin.flow.component.listbox.dataview.ListBoxListDataView<T>> com.vaadin.flow.data.selection.SingleSelect<com.vaadin.flow.component.listbox.ListBox<T>,
,T> Serializable
public class BasicComboList<T>
extends com.vaadin.flow.component.listbox.ListBox<T>
A generic combo box component that extends the ListBox class.
This class allows managing a collection of items and provides methods to access,
manipulate, and retrieve item values and their corresponding indices.
- 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.data.binder.HasItemComponents
com.vaadin.flow.data.binder.HasItemComponents.ItemComponent<T>
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
Fields -
Constructor Summary
ConstructorsConstructorDescriptionBasicComboList
(Collection<T> list) Constructs a BasicComboList instance using the provided collection of items.BasicComboList
(T... list) Constructs a BasicComboList instance with a variable number of elements. -
Method Summary
Modifier and TypeMethodDescriptionReturns the default empty value for the component.int
getIndex()
Retrieves the index of the item currently selected or set as the value of the combo list.int
Returns the index of the specified item in the list.getValue
(int index) Retrieves the value at the specified index from the combo list.protected void
Sets the current value of the combo list to the first item in the list.com.vaadin.flow.component.listbox.dataview.ListBoxListDataView
<T> setItems
(Collection<T> items) Sets the items for the combo list with the provided collection.Methods inherited from class com.vaadin.flow.component.listbox.ListBox
valueEquals
Methods inherited from class com.vaadin.flow.component.listbox.ListBoxBase
getDataProvider, getGenericDataView, getItemEnabledProvider, getItemId, getItemLabelGenerator, getItemRenderer, getListDataView, onAttach, onDetach, onEnabledStateChanged, setDataProvider, setItemEnabledProvider, setItemLabelGenerator, setItems, setItems, setItems, setRenderer, setRequiredIndicatorVisible
Methods inherited from class com.vaadin.flow.component.AbstractSinglePropertyField
getSynchronizationRegistration, hasValidValue, setPresentationValue, setSynchronizedEvent
Methods inherited from class com.vaadin.flow.component.AbstractField
addValueChangeListener, getValue, isEmpty, setModelValue, setValue
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, 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.DetachNotifier
addDetachListener
Methods inherited from interface com.vaadin.flow.component.HasAriaLabel
getAriaLabel, getAriaLabelledBy, setAriaLabel, setAriaLabelledBy
Methods inherited from interface com.vaadin.flow.component.HasComponents
add, add, add, addComponentAsFirst, addComponentAtIndex, remove, remove, removeAll
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.data.binder.HasItemComponents
addComponents, getItemPosition, prependComponents
Methods inherited from interface com.vaadin.flow.data.provider.HasListDataView
setItems
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.shared.HasTooltip
getTooltip, setTooltipText
Methods inherited from interface com.vaadin.flow.component.HasValue
addValueChangeListener, clear, getOptionalValue, getValue, isEmpty, setValue
Methods inherited from interface com.vaadin.flow.component.HasValueAndElement
isReadOnly, isRequiredIndicatorVisible, setReadOnly, setRequiredIndicatorVisible
-
Field Details
-
list
-
-
Constructor Details
-
BasicComboList
Constructs a BasicComboList instance with a variable number of elements. Allows initializing the combo list with multiple items provided as arguments.- Parameters:
list
- the elements to initialize the combo list with. These elements will be converted into a collection of items managed by this combo list.
-
BasicComboList
Constructs a BasicComboList instance using the provided collection of items.- Parameters:
list
- the collection of items to initialize the combo list; if null, an empty list will be used
-
-
Method Details
-
setItems
public com.vaadin.flow.component.listbox.dataview.ListBoxListDataView<T> setItems(Collection<T> items) Sets the items for the combo list with the provided collection. If the input collection is null, an empty collection is used instead. This method also updates the internal list and sets the first value of the list as the selected value, if applicable.- Parameters:
items
- the collection of items to be set in the combo list- Returns:
- the updated ListBoxListDataView instance reflecting the new items
-
setFirstValue
protected void setFirstValue()Sets the current value of the combo list to the first item in the list. If the list is empty, the value is set tonull
. This method ensures that the combo list initializes its value to the first available item in its data collection, or remains unset if no items exist. -
getIndex
public int getIndex()Retrieves the index of the item currently selected or set as the value of the combo list.- Returns:
- the index of the current value in the list, or -1 if the value is not found
-
getIndex
Returns the index of the specified item in the list.- Parameters:
item
- the item whose index is to be determined; can be null- Returns:
- the zero-based index of the specified item in the list, or -1 if the item is not present
-
getValue
Retrieves the value at the specified index from the combo list.- Parameters:
index
- the position of the item in the list to retrieve. If the index is out of bounds (less than 0 or greater than or equal to the size of the list), null is returned.- Returns:
- the value at the specified index, or null if the index is invalid.
-
getEmptyValue
Returns the default empty value for the component. This method is overridden to provide a null value as the representation of an empty value for the generic combo box.- Specified by:
getEmptyValue
in interfacecom.vaadin.flow.component.HasValue<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<com.vaadin.flow.component.listbox.ListBox<T>,
T>, T> - Overrides:
getEmptyValue
in classcom.vaadin.flow.component.AbstractField<com.vaadin.flow.component.listbox.ListBox<T>,
T> - Returns:
- the empty value of the component, which is null
-