Search in sources :

Example 56 with ComboBox

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);
}
Also used : ListDataProvider(com.vaadin.flow.data.provider.ListDataProvider) Arrays(java.util.Arrays) Query(com.vaadin.flow.data.provider.Query) Component(com.vaadin.flow.component.Component) Collection(java.util.Collection) Div(com.vaadin.flow.component.html.Div) Label(com.vaadin.flow.component.html.Label) NativeButton(com.vaadin.flow.component.html.NativeButton) SerializableConsumer(com.vaadin.flow.function.SerializableConsumer) ComboBox(com.vaadin.flow.component.combobox.ComboBox) Route(com.vaadin.flow.router.Route) Stream(java.util.stream.Stream) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) NativeButtonRenderer(com.vaadin.flow.data.renderer.NativeButtonRenderer) DataProvider(com.vaadin.flow.data.provider.DataProvider) Optional(java.util.Optional) SerializablePredicate(com.vaadin.flow.function.SerializablePredicate) SimpleBean(com.vaadin.flow.component.combobox.bean.SimpleBean) Span(com.vaadin.flow.component.html.Span) ComboBox(com.vaadin.flow.component.combobox.ComboBox) Label(com.vaadin.flow.component.html.Label)

Example 57 with ComboBox

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);
}
Also used : ListDataProvider(com.vaadin.flow.data.provider.ListDataProvider) Arrays(java.util.Arrays) Query(com.vaadin.flow.data.provider.Query) Component(com.vaadin.flow.component.Component) Collection(java.util.Collection) Div(com.vaadin.flow.component.html.Div) Label(com.vaadin.flow.component.html.Label) NativeButton(com.vaadin.flow.component.html.NativeButton) SerializableConsumer(com.vaadin.flow.function.SerializableConsumer) ComboBox(com.vaadin.flow.component.combobox.ComboBox) Route(com.vaadin.flow.router.Route) Stream(java.util.stream.Stream) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) NativeButtonRenderer(com.vaadin.flow.data.renderer.NativeButtonRenderer) DataProvider(com.vaadin.flow.data.provider.DataProvider) Optional(java.util.Optional) SerializablePredicate(com.vaadin.flow.function.SerializablePredicate) SimpleBean(com.vaadin.flow.component.combobox.bean.SimpleBean) Span(com.vaadin.flow.component.html.Span) NativeButton(com.vaadin.flow.component.html.NativeButton) ComboBox(com.vaadin.flow.component.combobox.ComboBox)

Example 58 with ComboBox

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);
}
Also used : NativeButton(com.vaadin.flow.component.html.NativeButton) ComboBox(com.vaadin.flow.component.combobox.ComboBox) Hr(com.vaadin.flow.component.html.Hr) TestItem(com.vaadin.flow.component.combobox.bean.TestItem)

Example 59 with ComboBox

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);
}
Also used : NativeButton(com.vaadin.flow.component.html.NativeButton) ComboBox(com.vaadin.flow.component.combobox.ComboBox) TestItem(com.vaadin.flow.component.combobox.bean.TestItem)

Example 60 with ComboBox

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);
}
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) ListDataProvider(com.vaadin.flow.data.provider.ListDataProvider) NativeButton(com.vaadin.flow.component.html.NativeButton) ComponentRenderer(com.vaadin.flow.data.renderer.ComponentRenderer) ComboBox(com.vaadin.flow.component.combobox.ComboBox) H4(com.vaadin.flow.component.html.H4)

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