Class CheckboxGroup<T>
- java.lang.Object
-
- com.vaadin.flow.component.Component
-
- com.vaadin.flow.component.AbstractField<C,T>
-
- com.vaadin.flow.component.AbstractSinglePropertyField<R,T>
-
- com.vaadin.flow.component.checkbox.GeneratedVaadinCheckboxGroup<CheckboxGroup<T>,Set<T>>
-
- com.vaadin.flow.component.checkbox.CheckboxGroup<T>
-
- All Implemented Interfaces:
AttachNotifier,DetachNotifier,HasComponents,HasElement,HasEnabled,HasHelper,HasLabel,HasSize,HasStyle,HasTheme,HasValidation,HasValue<AbstractField.ComponentValueChangeEvent<CheckboxGroup<T>,Set<T>>,Set<T>>,HasValueAndElement<AbstractField.ComponentValueChangeEvent<CheckboxGroup<T>,Set<T>>,Set<T>>,HasItemComponents<T>,HasDataView<T,Void,CheckboxGroupDataView<T>>,HasListDataView<T,CheckboxGroupListDataView<T>>,MultiSelect<CheckboxGroup<T>,T>,Serializable
public class CheckboxGroup<T> extends GeneratedVaadinCheckboxGroup<CheckboxGroup<T>,Set<T>> implements HasItemComponents<T>, HasSize, HasValidation, MultiSelect<CheckboxGroup<T>,T>, HasListDataView<T,CheckboxGroupListDataView<T>>, HasDataView<T,Void,CheckboxGroupDataView<T>>, HasHelper, HasLabel
Server-side component for thevaadin-checkbox-groupelement.CheckBoxGroup is a multiselection component where items are displayed as check boxes.
- Author:
- Vaadin Ltd
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.vaadin.flow.component.checkbox.GeneratedVaadinCheckboxGroup
GeneratedVaadinCheckboxGroup.InvalidChangeEvent<R extends GeneratedVaadinCheckboxGroup<R,?>>
-
Nested classes/interfaces inherited from class com.vaadin.flow.component.AbstractField
AbstractField.ComponentValueChangeEvent<C extends Component,V>
-
Nested classes/interfaces inherited from interface com.vaadin.flow.data.binder.HasItemComponents
HasItemComponents.ItemComponent<T>
-
Nested classes/interfaces inherited from interface com.vaadin.flow.component.HasValue
HasValue.ValueChangeEvent<V>, HasValue.ValueChangeListener<E extends HasValue.ValueChangeEvent<?>>
-
-
Constructor Summary
Constructors Constructor Description CheckboxGroup()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description RegistrationaddSelectionListener(MultiSelectionListener<CheckboxGroup<T>,T> listener)Adds a selection listener that will be called when the selection is changed either by the user or programmatically.DataProvider<T,?>getDataProvider()Deprecated.usegetListDataView()orgetGenericDataView()insteadStringgetErrorMessage()Gets the current error message from the checkbox group.CheckboxGroupDataView<T>getGenericDataView()Gets the generic data view for the checkbox group.SerializablePredicate<T>getItemEnabledProvider()Returns the item enabled predicate.ItemLabelGenerator<T>getItemLabelGenerator()Gets the item label generator that is used to produce the strings shown in the checkbox group for each item.StringgetLabel()Gets the label of the checkbox group.CheckboxGroupListDataView<T>getListDataView()Gets the list data view for the checkbox group.Set<T>getSelectedItems()Returns an immutable set of the currently selected items.protected booleanhasValidValue()Checks whether the element property has a value that can be converted to the model type.booleanisInvalid()Returnstrueif component input is invalid,falseotherwise.booleanisReadOnly()Returns whether thisHasValueis in read-only mode or not.booleanisRequired()Determines whether the checkbox group is marked as input required.voidonEnabledStateChanged(boolean enabled)Handle component enable state when the enabled state changes.voidsetDataProvider(DataProvider<T,?> dataProvider)Deprecated.use instead one of thesetItemsmethods which provide access to eitherCheckboxGroupListDataVieworCheckboxGroupDataViewvoidsetErrorMessage(String errorMessage)Description copied from corresponding location in WebComponent:voidsetInvalid(boolean invalid)Description copied from corresponding location in WebComponent:voidsetItemEnabledProvider(SerializablePredicate<T> itemEnabledProvider)Sets the item enabled predicate for this checkbox group.voidsetItemLabelGenerator(ItemLabelGenerator<T> itemLabelGenerator)Sets the item label generator that is used to produce the strings shown in the checkbox group for each item.CheckboxGroupDataView<T>setItems(DataProvider<T,Void> dataProvider)Set a generic data provider for the component to use and returns the baseDataViewthat provides API to get information on the items.CheckboxGroupDataView<T>setItems(InMemoryDataProvider<T> inMemoryDataProvider)Sets an in-memory data provider for the component to useCheckboxGroupListDataView<T>setItems(ListDataProvider<T> dataProvider)Sets a ListDataProvider for the component to use and returns aListDataViewthat provides information and allows operations on the items.voidsetItems(Stream<T> streamOfItems)Deprecated.Because the stream is collected to a list anyway, useHasListDataView.setItems(Collection)instead.voidsetLabel(String label)Sets the label for the checkbox group.voidsetReadOnly(boolean readOnly)Sets the read-only mode of thisHasValueto given mode.voidsetRequired(boolean required)Description copied from corresponding location in WebComponent:voidsetValue(Set<T> value)Sets the value of this component.voidupdateSelection(Set<T> addedItems, Set<T> removedItems)Updates the selection by adding and removing the given items from it.protected booleanvalueEquals(Set<T> value1, Set<T> value2)Compares to value instances to each other to determine whether they are equal.-
Methods inherited from class com.vaadin.flow.component.checkbox.GeneratedVaadinCheckboxGroup
addInvalidChangeListener, addThemeVariants, getErrorMessageString, getLabelString, isDisabledBoolean, isInvalidBoolean, isRequiredBoolean, removeThemeVariants, setDisabled, validate
-
Methods inherited from class com.vaadin.flow.component.AbstractSinglePropertyField
getSynchronizationRegistration, setPresentationValue, setSynchronizedEvent
-
Methods inherited from class com.vaadin.flow.component.AbstractField
addValueChangeListener, getEmptyValue, getValue, isEmpty, setModelValue
-
Methods inherited from class com.vaadin.flow.component.Component
addListener, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getLocale, getParent, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onAttach, onDetach, 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.HasComponents
add, add, addComponentAsFirst, addComponentAtIndex, 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.component.HasHelper
getHelperComponent, getHelperText, setHelperComponent, setHelperText
-
Methods inherited from interface com.vaadin.flow.data.binder.HasItemComponents
addComponents, getItemPosition, prependComponents
-
Methods inherited from interface com.vaadin.flow.data.provider.HasListDataView
setItems, 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.HasTheme
addThemeName, addThemeNames, getThemeName, getThemeNames, hasThemeName, removeThemeName, removeThemeNames, setThemeName, setThemeName
-
Methods inherited from interface com.vaadin.flow.component.HasValue
addValueChangeListener, clear, getOptionalValue, isEmpty
-
Methods inherited from interface com.vaadin.flow.component.HasValueAndElement
isRequiredIndicatorVisible, setRequiredIndicatorVisible
-
Methods inherited from interface com.vaadin.flow.data.selection.MultiSelect
deselect, deselect, deselectAll, getEmptyValue, getValue, isSelected, select, select
-
-
-
-
Method Detail
-
setItems
public CheckboxGroupDataView<T> setItems(DataProvider<T,Void> dataProvider)
Description copied from interface:HasDataViewSet a generic data provider for the component to use and returns the baseDataViewthat provides API to get information on the items.This method should be used only when the data provider type is not either
ListDataProviderorBackEndDataProvider.- Specified by:
setItemsin interfaceHasDataView<T,Void,CheckboxGroupDataView<T>>- Parameters:
dataProvider- DataProvider instance to use, notnull- Returns:
- DataView providing information on the data
-
setItems
public CheckboxGroupDataView<T> setItems(InMemoryDataProvider<T> inMemoryDataProvider)
Description copied from interface:HasDataViewSets an in-memory data provider for the component to useNote! Using a
ListDataProviderinstead of aInMemoryDataProvideris recommended to get access toListDataViewAPI by usingHasListDataView.setItems(ListDataProvider).- Specified by:
setItemsin interfaceHasDataView<T,Void,CheckboxGroupDataView<T>>- Parameters:
inMemoryDataProvider- InMemoryDataProvider to use, notnull- Returns:
- DataView providing information on the data
-
setItems
public CheckboxGroupListDataView<T> setItems(ListDataProvider<T> dataProvider)
Description copied from interface:HasListDataViewSets a ListDataProvider for the component to use and returns aListDataViewthat provides information and allows operations on the items.- Specified by:
setItemsin interfaceHasListDataView<T,CheckboxGroupListDataView<T>>- Parameters:
dataProvider- ListDataProvider providing items to the component.- Returns:
- ListDataView providing access to the items
-
getListDataView
public CheckboxGroupListDataView<T> getListDataView()
Gets the list data view for the checkbox group. This data view should only be used when the items are in-memory and set with: If the items are not in-memory an exception is thrown.- Specified by:
getListDataViewin interfaceHasListDataView<T,CheckboxGroupListDataView<T>>- Returns:
- the list data view that provides access to the data bound to the checkbox group
-
getGenericDataView
public CheckboxGroupDataView<T> getGenericDataView()
Gets the generic data view for the checkbox group. This data view should only be used whengetListDataView()is not applicable for the underlying data provider.- Specified by:
getGenericDataViewin interfaceHasDataView<T,Void,CheckboxGroupDataView<T>>- Returns:
- the generic DataView instance implementing
CheckboxGroupDataView
-
setItems
@Deprecated public void setItems(Stream<T> streamOfItems)
Deprecated.Because the stream is collected to a list anyway, useHasListDataView.setItems(Collection)instead.
-
setDataProvider
@Deprecated public void setDataProvider(DataProvider<T,?> dataProvider)
Deprecated.use instead one of thesetItemsmethods which provide access to eitherCheckboxGroupListDataVieworCheckboxGroupDataView
-
updateSelection
public void updateSelection(Set<T> addedItems, Set<T> removedItems)
Description copied from interface:MultiSelectUpdates the selection by adding and removing the given items from it.If all the added items were already selected and the removed items were not selected, this is a NO-OP.
Duplicate items (in both add and remove sets) are ignored.
- Specified by:
updateSelectionin interfaceMultiSelect<CheckboxGroup<T>,T>- Parameters:
addedItems- the items to add, notnullremovedItems- the items to remove, notnull
-
setValue
public void setValue(Set<T> value)
Sets the value of this component. If the new value is not equal to the previous value, fires a value change event.The component doesn't accept
nullvalues. The value of a checkbox group without any selected items is an empty set. You can use theHasValue.clear()method to set the empty value.- Specified by:
setValuein interfaceHasValue<AbstractField.ComponentValueChangeEvent<CheckboxGroup<T>,Set<T>>,Set<T>>- Specified by:
setValuein interfaceMultiSelect<CheckboxGroup<T>,T>- Overrides:
setValuein classAbstractField<CheckboxGroup<T>,Set<T>>- Parameters:
value- the new value to set, notnull- Throws:
NullPointerException- if value isnull
-
getSelectedItems
public Set<T> getSelectedItems()
Description copied from interface:MultiSelectReturns an immutable set of the currently selected items. It is safe to invoke otherSelectionModelmethods while iterating over the set.Implementation note: the iteration order of the items in the returned set should be well-defined and documented by the implementing class.
- Specified by:
getSelectedItemsin interfaceMultiSelect<CheckboxGroup<T>,T>- Returns:
- the items in the current selection, not
null
-
addSelectionListener
public Registration addSelectionListener(MultiSelectionListener<CheckboxGroup<T>,T> listener)
Description copied from interface:MultiSelectAdds a selection listener that will be called when the selection is changed either by the user or programmatically.- Specified by:
addSelectionListenerin interfaceMultiSelect<CheckboxGroup<T>,T>- Parameters:
listener- the value change listener, notnull- Returns:
- a registration for the listener
-
getDataProvider
@Deprecated public DataProvider<T,?> getDataProvider()
Deprecated.usegetListDataView()orgetGenericDataView()insteadGets the data provider.- Returns:
- the data provider, not
null
-
onEnabledStateChanged
public void onEnabledStateChanged(boolean enabled)
Description copied from class:ComponentHandle component enable state when the enabled state changes.By default this sets or removes the 'disabled' attribute from the element. This can be overridden to have custom handling.
- Overrides:
onEnabledStateChangedin classComponent- Parameters:
enabled- the new enabled state of the component
-
setReadOnly
public void setReadOnly(boolean readOnly)
Description copied from interface:HasValueSets the read-only mode of thisHasValueto given mode. The user can't change the value when in read-only mode.A
HasValuewith a visual component in read-only mode typically looks visually different to signal to the user that the value cannot be edited.- Specified by:
setReadOnlyin interfaceHasValue<AbstractField.ComponentValueChangeEvent<CheckboxGroup<T>,Set<T>>,Set<T>>- Specified by:
setReadOnlyin interfaceHasValueAndElement<AbstractField.ComponentValueChangeEvent<CheckboxGroup<T>,Set<T>>,Set<T>>- Parameters:
readOnly- a boolean value specifying whether the component is put read-only mode or not
-
isReadOnly
public boolean isReadOnly()
Description copied from interface:HasValueReturns whether thisHasValueis in read-only mode or not.- Specified by:
isReadOnlyin interfaceHasValue<AbstractField.ComponentValueChangeEvent<CheckboxGroup<T>,Set<T>>,Set<T>>- Specified by:
isReadOnlyin interfaceHasValueAndElement<AbstractField.ComponentValueChangeEvent<CheckboxGroup<T>,Set<T>>,Set<T>>- Returns:
falseif the user can modify the value,trueif not.
-
getItemEnabledProvider
public SerializablePredicate<T> getItemEnabledProvider()
Returns the item enabled predicate.- Returns:
- the item enabled predicate
- See Also:
setItemEnabledProvider(com.vaadin.flow.function.SerializablePredicate<T>)
-
setItemEnabledProvider
public void setItemEnabledProvider(SerializablePredicate<T> itemEnabledProvider)
Sets the item enabled predicate for this checkbox group. The predicate is applied to each item to determine whether the item should be enabled (true) or disabled (false). Disabled items are displayed as grayed out and the user cannot select them. The default predicate always returns true (all the items are enabled).- Parameters:
itemEnabledProvider- the item enable predicate, notnull
-
setItemLabelGenerator
public void setItemLabelGenerator(ItemLabelGenerator<T> itemLabelGenerator)
Sets the item label generator that is used to produce the strings shown in the checkbox group for each item. By default,String.valueOf(Object)is used.- Parameters:
itemLabelGenerator- the item label provider to use, not null
-
getItemLabelGenerator
public ItemLabelGenerator<T> getItemLabelGenerator()
Gets the item label generator that is used to produce the strings shown in the checkbox group for each item.- Returns:
- the item label generator used, not null
-
setLabel
public void setLabel(String label)
Sets the label for the checkbox group.- Specified by:
setLabelin interfaceHasLabel- Overrides:
setLabelin classGeneratedVaadinCheckboxGroup<CheckboxGroup<T>,Set<T>>- Parameters:
label- value for thelabelproperty in the checkbox group
-
getLabel
public String getLabel()
Gets the label of the checkbox group.
-
setErrorMessage
public void setErrorMessage(String errorMessage)
Description copied from class:GeneratedVaadinCheckboxGroupDescription copied from corresponding location in WebComponent:
Error to show when the input value is invalid.
- Specified by:
setErrorMessagein interfaceHasValidation- Overrides:
setErrorMessagein classGeneratedVaadinCheckboxGroup<CheckboxGroup<T>,Set<T>>- Parameters:
errorMessage- the String value to set
-
getErrorMessage
public String getErrorMessage()
Gets the current error message from the checkbox group.- Specified by:
getErrorMessagein interfaceHasValidation- Returns:
- the current error message
-
setRequired
public void setRequired(boolean required)
Description copied from class:GeneratedVaadinCheckboxGroupDescription copied from corresponding location in WebComponent:
Specifies that the user must fill in a value.
- Overrides:
setRequiredin classGeneratedVaadinCheckboxGroup<CheckboxGroup<T>,Set<T>>- Parameters:
required- the boolean value to set
-
isRequired
public boolean isRequired()
Determines whether the checkbox group is marked as input required.This property is not synchronized automatically from the client side, so the returned value may not be the same as in client side.
- Returns:
trueif the input is required,falseotherwise
-
isInvalid
public boolean isInvalid()
Description copied from interface:HasValidationReturnstrueif component input is invalid,falseotherwise.- Specified by:
isInvalidin interfaceHasValidation- Returns:
- whether the component input is valid
-
setInvalid
public void setInvalid(boolean invalid)
Description copied from class:GeneratedVaadinCheckboxGroupDescription copied from corresponding location in WebComponent:
This property is set to true when the control value is invalid.
- Specified by:
setInvalidin interfaceHasValidation- Overrides:
setInvalidin classGeneratedVaadinCheckboxGroup<CheckboxGroup<T>,Set<T>>- Parameters:
invalid- the boolean value to set
-
valueEquals
protected boolean valueEquals(Set<T> value1, Set<T> value2)
Description copied from class:AbstractFieldCompares to value instances to each other to determine whether they are equal. Equality is used to determine whether to update internal state and fire an event whenAbstractField.setValue(Object)orAbstractField.setModelValue(Object, boolean)is called. Subclasses can override this method to define an alternative comparison method instead ofObject.equals(Object).- Overrides:
valueEqualsin classAbstractField<CheckboxGroup<T>,Set<T>>- Parameters:
value1- the first instancevalue2- the second instance- Returns:
trueif the instances are equal; otherwisefalse
-
hasValidValue
protected boolean hasValidValue()
Description copied from class:AbstractSinglePropertyFieldChecks whether the element property has a value that can be converted to the model type. Property changes from the element will be ignored if this method returnsfalse. The default implementation always returntrue.- Overrides:
hasValidValuein classAbstractSinglePropertyField<CheckboxGroup<T>,Set<T>>- Returns:
trueif the element property value can be converted to the model type; otherwisefalse
-
-