Search in sources :

Example 11 with ComboBox

use of com.vaadin.flow.component.combobox.ComboBox in project flow-components by vaadin.

the class FilteringPage method createComboBoxWithMultiplePagesAndSourceSwitchers.

private void createComboBoxWithMultiplePagesAndSourceSwitchers() {
    ComboBox<String> comboBox = new ComboBox<>();
    comboBox.setId(COMBOBOX_WITH_FILTERED_ITEMS_ID);
    List<String> items = LazyLoadingPage.generateStrings(500);
    ComboBoxLazyDataView<String> dataView = comboBox.setItems(query -> items.stream().filter(item -> item.contains(query.getFilter().orElse(""))).skip(query.getOffset()).limit(query.getLimit()), query -> (int) items.stream().filter(item -> item.contains(query.getFilter().orElse(""))).count());
    NativeButton switchToUnknown = new NativeButton("Switch To Unknown Item Count", click -> dataView.setItemCountUnknown());
    switchToUnknown.setId(SWITCH_TO_UNKNOWN_ITEM_COUNT_BUTTON_ID);
    NativeButton switchToInMemory = new NativeButton("Switch To In-memory Items", click -> comboBox.setItems(items));
    switchToInMemory.setId(SWITCH_TO_IN_MEMORY_ITEMS_BUTTON_ID);
    add(new Div(), comboBox, switchToUnknown, switchToInMemory);
}
Also used : IntStream(java.util.stream.IntStream) ListDataProvider(com.vaadin.flow.data.provider.ListDataProvider) ItemFilter(com.vaadin.flow.component.combobox.ComboBox.ItemFilter) List(java.util.List) ComboBoxLazyDataView(com.vaadin.flow.component.combobox.dataview.ComboBoxLazyDataView) DataProvider(com.vaadin.flow.data.provider.DataProvider) Div(com.vaadin.flow.component.html.Div) NativeButton(com.vaadin.flow.component.html.NativeButton) CallbackDataProvider(com.vaadin.flow.data.provider.CallbackDataProvider) ComboBox(com.vaadin.flow.component.combobox.ComboBox) Route(com.vaadin.flow.router.Route) Div(com.vaadin.flow.component.html.Div) NativeButton(com.vaadin.flow.component.html.NativeButton) ComboBox(com.vaadin.flow.component.combobox.ComboBox)

Example 12 with ComboBox

use of com.vaadin.flow.component.combobox.ComboBox in project flow-components by vaadin.

the class LazyLoadingPage method createDataProviderWithCustomItemFilter.

private void createDataProviderWithCustomItemFilter() {
    addTitle("ListDataProvider with custom item filter");
    ComboBox<Person> comboBox = new ComboBox<>();
    comboBox.setId("custom-filter");
    List<Person> people = IntStream.range(0, 500).mapToObj(i -> new Person("Person", i)).collect(Collectors.toList());
    ListDataProvider<Person> personDataProvider = new ListDataProvider<>(people);
    comboBox.setRenderer(new ComponentRenderer<Div, Person>(person -> {
        return new Div(new H4(person.getName()), new Label("Born: " + person.getBorn()));
    }));
    comboBox.setDataProvider((person, filter) -> String.valueOf(person.getBorn()).startsWith(filter), personDataProvider);
    add(comboBox);
}
Also used : IntStream(java.util.stream.IntStream) ListDataProvider(com.vaadin.flow.data.provider.ListDataProvider) ComponentRenderer(com.vaadin.flow.data.renderer.ComponentRenderer) Div(com.vaadin.flow.component.html.Div) Label(com.vaadin.flow.component.html.Label) NativeButton(com.vaadin.flow.component.html.NativeButton) CallbackDataProvider(com.vaadin.flow.data.provider.CallbackDataProvider) ComboBox(com.vaadin.flow.component.combobox.ComboBox) Collectors(java.util.stream.Collectors) H4(com.vaadin.flow.component.html.H4) Serializable(java.io.Serializable) Route(com.vaadin.flow.router.Route) ComboBoxInATemplate(com.vaadin.flow.component.combobox.test.template.ComboBoxInATemplate) List(java.util.List) Stream(java.util.stream.Stream) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DataProvider(com.vaadin.flow.data.provider.DataProvider) Element(com.vaadin.flow.dom.Element) Collections(java.util.Collections) Paragraph(com.vaadin.flow.component.html.Paragraph) Span(com.vaadin.flow.component.html.Span) Div(com.vaadin.flow.component.html.Div) ListDataProvider(com.vaadin.flow.data.provider.ListDataProvider) ComboBox(com.vaadin.flow.component.combobox.ComboBox) Label(com.vaadin.flow.component.html.Label) H4(com.vaadin.flow.component.html.H4)

Example 13 with ComboBox

use of com.vaadin.flow.component.combobox.ComboBox in project flow-components by vaadin.

the class LazyLoadingPage method createListDataProviderWithStrings.

private void createListDataProviderWithStrings() {
    addTitle("ListDataProvider with strings");
    ComboBox<String> comboBox = new ComboBox<>();
    comboBox.setId("lazy-strings");
    List<String> items = generateStrings(1000);
    comboBox.setDataProvider(DataProvider.ofCollection(items));
    comboBox.addValueChangeListener(e -> message.setText(e.getValue()));
    NativeButton setButton = new NativeButton("set value", e -> {
        comboBox.setValue(items.get(10));
    });
    setButton.setId("set-value");
    NativeButton disableButton = new NativeButton("set disabled", e -> {
        comboBox.setEnabled(false);
    });
    disableButton.setId("disable");
    NativeButton setCurrentValueButton = new NativeButton("set current value", e -> {
        comboBox.setValue(comboBox.getValue());
    });
    setCurrentValueButton.setId("set-current-value");
    add(comboBox, setButton, disableButton, setCurrentValueButton);
}
Also used : NativeButton(com.vaadin.flow.component.html.NativeButton) ComboBox(com.vaadin.flow.component.combobox.ComboBox)

Example 14 with ComboBox

use of com.vaadin.flow.component.combobox.ComboBox in project flow-components by vaadin.

the class LazyLoadingPage method createCallbackDataProvider.

private void createCallbackDataProvider() {
    addTitle("CallbackDataProvider");
    ComboBox<String> comboBox = new ComboBox<>();
    comboBox.setId("callback-dataprovider");
    AtomicInteger sizeRequestCount = new AtomicInteger(0);
    Span sizeRequestCountSpan = new Span("0");
    sizeRequestCountSpan.setId("callback-dataprovider-size-request-count");
    CallbackDataProvider<String, String> dataProvider = new CallbackDataProvider<String, String>(query -> IntStream.range(query.getOffset(), query.getOffset() + query.getLimit()).mapToObj(i -> "Item " + i), query -> {
        sizeRequestCountSpan.setText(String.valueOf(sizeRequestCount.incrementAndGet()));
        return 210;
    });
    comboBox.setDataProvider(dataProvider);
    add(comboBox, sizeRequestCountSpan);
}
Also used : IntStream(java.util.stream.IntStream) ListDataProvider(com.vaadin.flow.data.provider.ListDataProvider) ComponentRenderer(com.vaadin.flow.data.renderer.ComponentRenderer) Div(com.vaadin.flow.component.html.Div) Label(com.vaadin.flow.component.html.Label) NativeButton(com.vaadin.flow.component.html.NativeButton) CallbackDataProvider(com.vaadin.flow.data.provider.CallbackDataProvider) ComboBox(com.vaadin.flow.component.combobox.ComboBox) Collectors(java.util.stream.Collectors) H4(com.vaadin.flow.component.html.H4) Serializable(java.io.Serializable) Route(com.vaadin.flow.router.Route) ComboBoxInATemplate(com.vaadin.flow.component.combobox.test.template.ComboBoxInATemplate) List(java.util.List) Stream(java.util.stream.Stream) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DataProvider(com.vaadin.flow.data.provider.DataProvider) Element(com.vaadin.flow.dom.Element) Collections(java.util.Collections) Paragraph(com.vaadin.flow.component.html.Paragraph) Span(com.vaadin.flow.component.html.Span) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ComboBox(com.vaadin.flow.component.combobox.ComboBox) Span(com.vaadin.flow.component.html.Span) CallbackDataProvider(com.vaadin.flow.data.provider.CallbackDataProvider)

Example 15 with ComboBox

use of com.vaadin.flow.component.combobox.ComboBox in project flow-components by vaadin.

the class LazyLoadingPage method createComboBoxWithDisabledLazyLoading.

private void createComboBoxWithDisabledLazyLoading() {
    addTitle("ComboBox with disabled lazy loading");
    ComboBox<Integer> comboBox = new ComboBox<>(100);
    comboBox.setId("disabled-lazy-loading");
    // Having a number of items less than or equal than the page size will
    // disable lazy-loading
    List<Integer> items = IntStream.range(0, 100).boxed().collect(Collectors.toList());
    comboBox.setItems(items);
    NativeButton enableLazyLoading = new NativeButton("Enable lazy loading", // Reducing page size should enable lazy-loading
    event -> comboBox.setPageSize(50));
    enableLazyLoading.setId("enable-lazy-loading");
    add(comboBox, enableLazyLoading);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) NativeButton(com.vaadin.flow.component.html.NativeButton) ComboBox(com.vaadin.flow.component.combobox.ComboBox)

Aggregations

ComboBox (com.vaadin.flow.component.combobox.ComboBox)69 Div (com.vaadin.flow.component.html.Div)35 Span (com.vaadin.flow.component.html.Span)21 NativeButton (com.vaadin.flow.component.html.NativeButton)20 Route (com.vaadin.flow.router.Route)18 List (java.util.List)16 H2 (com.vaadin.flow.component.html.H2)14 Collectors (java.util.stream.Collectors)14 Label (com.vaadin.flow.component.html.Label)12 ComponentRenderer (com.vaadin.flow.data.renderer.ComponentRenderer)12 Stream (java.util.stream.Stream)12 Component (com.vaadin.flow.component.Component)10 VerticalLayout (com.vaadin.flow.component.orderedlayout.VerticalLayout)10 ArrayList (java.util.ArrayList)10 Button (com.vaadin.flow.component.button.Button)9 Person (com.vaadin.flow.component.combobox.test.entity.Person)9 PersonService (com.vaadin.flow.component.combobox.test.service.PersonService)9 IntStream (java.util.stream.IntStream)9 ItemFilter (com.vaadin.flow.component.combobox.ComboBox.ItemFilter)8 Paragraph (com.vaadin.flow.component.html.Paragraph)8