use of com.vaadin.flow.component.combobox.ComboBox 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.ComboBox in project flow-components by vaadin.
the class ComboBoxView method themeVariantsTextAlign.
private void themeVariantsTextAlign() {
Div div = new Div();
ComboBox<String> leftComboBox = new ComboBox<>();
leftComboBox.setItems("Left", "Center", "Right");
leftComboBox.setValue("Left");
leftComboBox.getElement().setAttribute("theme", "align-left");
ComboBox<String> centerComboBox = new ComboBox<>();
centerComboBox.setItems("Left", "Center", "Right");
centerComboBox.setValue("Center");
centerComboBox.getElement().setAttribute("theme", "align-center");
ComboBox<String> rightComboBox = new ComboBox<>();
rightComboBox.setItems("Left", "Center", "Right");
rightComboBox.setValue("Right");
rightComboBox.getElement().setAttribute("theme", "align-right");
div.add(leftComboBox, centerComboBox, rightComboBox);
leftComboBox.getStyle().set("margin-right", "5px");
centerComboBox.getStyle().set("margin-right", "5px");
addCard("Theme Variants", "Text align", div);
}
use of com.vaadin.flow.component.combobox.ComboBox in project flow-components by vaadin.
the class ComboBoxView method storingCustomValues.
private void storingCustomValues() {
Div message = createMessageDiv("custom-value-message");
ComboBox<Project> comboBox = new ComboBox<>("Project");
comboBox.setItems(this::fetchProjects, this::countProjects);
comboBox.setItemLabelGenerator(Project::getName);
comboBox.addValueChangeListener(valueChangeEvent -> {
if (valueChangeEvent.getValue() == null) {
message.setText("No project selected");
} else {
message.setText("Selected value: " + valueChangeEvent.getValue());
}
});
comboBox.addCustomValueSetListener(event -> {
Project project = projectData.addProject(event.getDetail());
comboBox.setValue(project);
});
addCard("Storing custom values", comboBox, message);
}
use of com.vaadin.flow.component.combobox.ComboBox in project flow-components by vaadin.
the class ComboBoxView method helperText.
private void helperText() {
Div div = new Div();
ComboBox<String> helperTextCombobox = new ComboBox<>("Language");
helperTextCombobox.setItems("Java", "Python", "C++", "Scala", "JavaScript");
helperTextCombobox.setHelperText("Select the language you are most familiar with");
ComboBox<String> helperComponentCombobox = new ComboBox<>("Continent");
helperComponentCombobox.setItems("North America", "South America", "Africa", "Europe", "Asia", "Australia", "Antarctica");
helperComponentCombobox.setHelperComponent(new Span("Select the continent of your residence"));
add(helperTextCombobox, helperComponentCombobox);
helperTextCombobox.getStyle().set("margin-right", "15px");
div.add(helperTextCombobox, helperComponentCombobox);
addCard("Helper text and helper component", div);
}
use of com.vaadin.flow.component.combobox.ComboBox in project flow-components by vaadin.
the class DataProviderPage method createRefreshWithSmallerDataSet.
private void createRefreshWithSmallerDataSet() {
add(new Hr());
ComboBox<String> cb = new ComboBox<>();
cb.setId("combo-box-with-reduce-data-set");
Span cbWrapper = new Span(cb);
List<String> items = new ArrayList<>();
items.add("foo");
items.add("bar");
DataProvider<String, String> dp = DataProvider.fromFilteringCallbacks(q -> items.stream().skip(q.getOffset()).limit(q.getLimit()), q -> items.size());
cb.setDataProvider(dp);
NativeButton refreshAllWithSmallerDataSetButton = new NativeButton("Refresh all with smaller data set", event -> {
items.remove("foo");
dp.refreshAll();
});
refreshAllWithSmallerDataSetButton.setId("refresh-all-with-smaller-data-set");
NativeButton toggleAttachedButton = new NativeButton("Toggle attached", event -> {
if (cb.isAttached()) {
cbWrapper.remove(cb);
} else {
cbWrapper.add(cb);
}
});
toggleAttachedButton.setId("toggle-attached");
add(cbWrapper, refreshAllWithSmallerDataSetButton, toggleAttachedButton);
}
Aggregations