use of com.vaadin.flow.component.combobox.ComboBox in project flow-components by vaadin.
the class ComboBoxPage method createWithButtonRenderer.
private void createWithButtonRenderer() {
ComboBox<String> comboBox = new ComboBox<>();
Label message = new Label("Nothing clicked yet...");
message.setId("button-renderer-message");
comboBox.setRenderer(new NativeButtonRenderer<>(item -> item, item -> message.setText("Button clicked: " + item)));
comboBox.setItems("foo", "bar");
comboBox.setId("button-renderer");
add(comboBox, message);
}
use of com.vaadin.flow.component.combobox.ComboBox in project flow-components by vaadin.
the class ComboBoxPage method createWithUpdateProvider.
private void createWithUpdateProvider() {
ComboBox<String> comboBox = new ComboBox<>();
comboBox.setItems("foo", "bar");
comboBox.setId("combo");
NativeButton setProvider = new NativeButton("Update data provider", event -> comboBox.setDataProvider(DataProvider.ofItems("baz", "foobar")));
setProvider.setId("update-provider");
NativeButton setItemCaptionGenerator = new NativeButton("Update caption generator", event -> comboBox.setItemLabelGenerator(item -> String.valueOf(item.length())));
setItemCaptionGenerator.setId("update-caption-gen");
NativeButton setValue = new NativeButton("Update value", event -> comboBox.setValue("baz"));
setValue.setId("update-value");
add(comboBox, setProvider, setItemCaptionGenerator, setValue);
}
use of com.vaadin.flow.component.combobox.ComboBox in project flow-components by vaadin.
the class DataProviderPage method createDataProviderWithoutGetId.
private void createDataProviderWithoutGetId() {
add(new Hr());
ComboBox<TestItem> comboBoxWithoutGetId = new ComboBox<>();
comboBoxWithoutGetId.setId(COMBO_BOX_WITHOUT_GET_ID_ID);
comboBoxWithoutGetId.setItems(list);
add(comboBoxWithoutGetId);
NativeButton setValueUsingReferenceButton = new NativeButton("Set Value Using Reference", event -> comboBoxWithoutGetId.setValue(list.get(1)));
setValueUsingReferenceButton.setId(SET_VALUE_USING_REFERENCE_BUTTON_ID);
add(setValueUsingReferenceButton);
NativeButton setValueUsingEqualsButton = new NativeButton("Set Value Using Equals", event -> comboBoxWithoutGetId.setValue(new TestItem(4, "c", "")));
setValueUsingEqualsButton.setId(SET_VALUE_USING_EQUALS_BUTTON_ID);
add(setValueUsingEqualsButton);
}
use of com.vaadin.flow.component.combobox.ComboBox in project flow-components by vaadin.
the class DataProviderPage method createDataProviderWithGetId.
private void createDataProviderWithGetId() {
ComboBox<TestItem> comboBoxWithGetId = new ComboBox<>();
comboBoxWithGetId.setId(COMBO_BOX_WITH_GET_ID_ID);
comboBoxWithGetId.setDataProvider(new ListDataProvider<TestItem>(list) {
@Override
public Object getId(TestItem item) {
return item.getId();
}
});
add(comboBoxWithGetId);
NativeButton setValueUsingIdButton = new NativeButton("Set Value Using Id", event -> comboBoxWithGetId.setValue(new TestItem(2)));
setValueUsingIdButton.setId(SET_VALUE_USING_GET_ID_BUTTON_ID);
add(setValueUsingIdButton);
}
use of com.vaadin.flow.component.combobox.ComboBox in project flow-components by vaadin.
the class LazyLoadingPage method createListDataProviderWithBeans.
private void createListDataProviderWithBeans() {
addTitle("ListDataProvider with beans");
ComboBox<Person> comboBox = new ComboBox<>();
comboBox.setId("lazy-beans");
List<Person> people = IntStream.range(0, 987).mapToObj(i -> new Person("Person " + i, i)).collect(Collectors.toList());
ListDataProvider<Person> personDataProvider = new ListDataProvider<>(people);
comboBox.setDataProvider(personDataProvider);
NativeButton setButton = new NativeButton("set value", e -> comboBox.setValue(people.get(3)));
setButton.setId("set-bean-value");
NativeButton componentRendererButton = new NativeButton("set renderer", e -> comboBox.setRenderer(new ComponentRenderer<H4, Person>(person -> new H4(person.getName()))));
componentRendererButton.setId("component-renderer");
NativeButton itemLabelGeneratorButton = new NativeButton("change item label generator", e -> comboBox.setItemLabelGenerator(person -> "Born " + person.getBorn()));
itemLabelGeneratorButton.setId("item-label-generator");
List<Person> altPeople = IntStream.range(0, 220).mapToObj(i -> new Person("Changed " + i, 2000 + i)).collect(Collectors.toList());
ListDataProvider<Person> altPersonDataProvider = new ListDataProvider<>(altPeople);
NativeButton dataProviderButton = new NativeButton("Change data provider", e -> comboBox.setDataProvider(altPersonDataProvider));
dataProviderButton.setId("data-provider");
NativeButton updateButton = new NativeButton("Update first item", e -> {
people.get(0).setName("Updated");
personDataProvider.refreshItem(people.get(0));
});
updateButton.setId("update-item");
NativeButton removeButton = new NativeButton("Remove third item", e -> {
people.remove(2);
personDataProvider.refreshAll();
});
removeButton.setId("remove-item");
add(comboBox, setButton, componentRendererButton, itemLabelGeneratorButton, dataProviderButton, updateButton, removeButton);
}
Aggregations