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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations