
com.vaadin.flow.component.listbox.MultiSelectListBox Maven / Gradle / Ivy
/*
* Copyright 2000-2024 Vaadin Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.vaadin.flow.component.listbox;
import java.util.Collections;
import java.util.HashSet;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;
import com.vaadin.flow.component.shared.SelectionPreservationHandler;
import com.vaadin.flow.component.shared.SelectionPreservationMode;
import com.vaadin.flow.data.provider.DataChangeEvent;
import com.vaadin.flow.data.provider.DataProvider;
import com.vaadin.flow.data.provider.DataViewUtils;
import com.vaadin.flow.data.selection.MultiSelect;
import com.vaadin.flow.data.selection.MultiSelectionEvent;
import com.vaadin.flow.data.selection.MultiSelectionListener;
import com.vaadin.flow.shared.Registration;
import elemental.json.Json;
import elemental.json.JsonArray;
/**
* Server-side component for the {@code vaadin-list-box} element with
* multi-selection.
*
* @author Vaadin Ltd
*
* @param
* the type of the items contained by this component
* @see ListBox
*/
public class MultiSelectListBox
extends ListBoxBase, T, Set>
implements MultiSelect, T> {
private SelectionPreservationHandler selectionPreservationHandler;
/**
* Creates a new list box component with multi-selection.
*/
public MultiSelectListBox() {
super("selectedValues", JsonArray.class, Collections.emptySet(),
MultiSelectListBox::presentationToModel,
MultiSelectListBox::modelToPresentation);
getElement().setProperty("multiple", true);
initSelectionPreservationHandler();
}
private void initSelectionPreservationHandler() {
selectionPreservationHandler = new SelectionPreservationHandler<>(
SelectionPreservationMode.DISCARD) {
@Override
public void onPreserveAll(DataChangeEvent dataChangeEvent) {
// NO-OP
}
@Override
public void onPreserveExisting(DataChangeEvent dataChangeEvent) {
Map
© 2015 - 2025 Weber Informatics LLC | Privacy Policy