use of com.vaadin.flow.component.combobox.test.service.PersonService in project flow-components by vaadin.
the class ComboBoxView method filteringWithTypesOtherThanString.
private void filteringWithTypesOtherThanString() {
// PersonService can be found:
// https://github.com/vaadin/vaadin-combo-box-flow/tree/master/vaadin-combo-box-flow-demo/src/main/java/com/vaadin/flow/component/combobox/demo/service/PersonService.java
PersonService personService = new PersonService(500);
ComboBox<Person> comboBox = new ComboBox<>("Person");
comboBox.setPlaceholder("Enter minimum age to filter");
comboBox.setPattern("^\\d+$");
comboBox.setPreventInvalidInput(true);
// Configuring fetch callback with a filter converter, so entered filter
// strings can refer also to other typed properties like age (integer):
comboBox.setItemsWithFilterConverter(query -> personService.fetchOlderThan(query.getFilter().orElse(null), query.getOffset(), query.getLimit()), ageStr -> ageStr.trim().isEmpty() ? null : Integer.parseInt(ageStr));
comboBox.setItemLabelGenerator(person -> person.getFirstName() + " " + person.getLastName() + " - " + person.getAge());
comboBox.setClearButtonVisible(true);
comboBox.setWidth(WIDTH_STRING);
addCard("Filtering", "Filtering with types other than String", comboBox);
}
use of com.vaadin.flow.component.combobox.test.service.PersonService in project flow-components by vaadin.
the class ComboBoxView method lazyLoadingWithExactItemCount.
private void lazyLoadingWithExactItemCount() {
ComboBox<Person> comboBox = new ComboBox<>();
PersonService service = new PersonService();
/*
* By using these callbacks the ComboBox doesn't load all the items to
* the server memory right away. The ComboBox calls the first provided
* callback to fetch items from the given range with the given filter.
* The second callback is optional and can be used to determine an exact
* count of items that match the query, if the exact count is desired.
*/
comboBox.setItems(query -> service.fetch(query.getFilter().orElse(null), query.getOffset(), query.getLimit()), query -> service.count(query.getFilter().orElse(null)));
comboBox.setId("with-exact-items-count");
addCard("Lazy Loading", "Lazy Loading with Exact Items Count", comboBox);
}
use of com.vaadin.flow.component.combobox.test.service.PersonService in project flow-components by vaadin.
the class ComboBoxView method filteringAndSortingWithDataView.
private void filteringAndSortingWithDataView() {
// PersonService can be found:
// https://github.com/vaadin/vaadin-combo-box-flow/tree/master/vaadin-combo-box-flow-demo/src/main/java/com/vaadin/flow/component/combobox/demo/service/PersonService.java
ComboBox<Person> comboBox = new ComboBox<>("Persons");
PersonService personService = new PersonService();
// We fetch the items to the memory and bind the obtained collection
// to the combo box
Collection<Person> persons = personService.fetchAll();
ComboBoxListDataView<Person> dataView = comboBox.setItems(persons);
/*
* Providing a predicate item filter allows filtering by any field of
* the business entity and apply a combo box's text filter independently
*/
IntegerField personAgeFilter = new IntegerField(event -> dataView.setFilter(person -> event.getValue() == null || person.getAge() > event.getValue()));
/*
* Providing a value provider or comparator allows sorting combo box's
* items by custom field, or combination of fields
*/
Button sortPersons = new Button("Sort Persons by Name", event -> dataView.setSortOrder(Person::toString, SortDirection.ASCENDING));
personAgeFilter.setLabel("Filter Persons with age more than:");
personAgeFilter.setWidth(WIDTH_STRING);
addCard("Filtering", "Filtering and Sorting with Data View", comboBox, personAgeFilter, sortPersons);
}
use of com.vaadin.flow.component.combobox.test.service.PersonService in project flow-components by vaadin.
the class ComboBoxView method lazyLoadingWithCustomItemCountEstimate.
private void lazyLoadingWithCustomItemCountEstimate() {
// The backend will have 12345 items
PersonService service = new PersonService(12345);
ComboBox<Person> comboBox = new ComboBox<>();
ComboBoxLazyDataView<Person> lazyDataView = comboBox.setItems(query -> service.fetch(query.getFilter().orElse(null), query.getOffset(), query.getLimit()));
/*
* By default, the combo box will initially adjust the scrollbar to 200
* items and as the user scrolls down it automatically increases the
* size by 200 until the backend runs out of items.
*
* Depending on the desired UX and the backend performance, the
* scrolling experience and the number of items in the drop down can be
* customized accordingly by constraining the page size, estimated item
* count and its increase.
*/
comboBox.setPageSize(10);
lazyDataView.setItemCountEstimate(50);
lazyDataView.setItemCountEstimateIncrease(50);
// Showing the item count for demo purposes
Div countText = new Div();
lazyDataView.addItemCountChangeListener(event -> {
if (event.isItemCountEstimated()) {
countText.setText("Person Count Estimate: " + event.getItemCount());
} else {
countText.setText("Exact Person Count: " + event.getItemCount());
}
});
HorizontalLayout layout = new HorizontalLayout(comboBox, countText);
comboBox.setId("custom-item-count-estimate");
addCard("Lazy Loading", "Custom Item Count Estimate And Increase", layout);
}
use of com.vaadin.flow.component.combobox.test.service.PersonService in project flow-components by vaadin.
the class ComboBoxView method pagedRepository.
private void pagedRepository() {
ComboBox<Person> comboBox = new ComboBox<>();
PersonService service = new PersonService();
/*
* For those backend repositories which use paged data fetching, it is
* possible to get the page number and page size from Query API.
*/
comboBox.setItems(query -> service.fetchPage(query.getFilter().orElse(null), query.getPage(), query.getPageSize()));
comboBox.setId("paged-box");
addCard("Lazy Loading", "Lazy Loading from Paged Repository", comboBox);
}
Aggregations