Search in sources :

Example 46 with ComboBox

use of com.vaadin.flow.component.combobox.ComboBox in project flow-components by vaadin.

the class ComboBoxView method autoOpenDisabled.

private void autoOpenDisabled() {
    Span note = new Span("Dropdown is only opened when clicking the toggle button or pressing Up or Down arrow keys.");
    ComboBox<String> comboBox = new ComboBox<>();
    comboBox.setItems("Option one", "Option two");
    comboBox.setAutoOpen(false);
    addCard("Auto open disabled", note, comboBox);
}
Also used : ComboBox(com.vaadin.flow.component.combobox.ComboBox) Span(com.vaadin.flow.component.html.Span)

Example 47 with ComboBox

use of com.vaadin.flow.component.combobox.ComboBox in project flow-components by vaadin.

the class ComboBoxDemoPage method createWithClearButton.

private void createWithClearButton() {
    ComboBox<String> comboBox = new ComboBox<>("Browsers");
    comboBox.setItems("Google Chrome", "Mozilla Firefox", "Opera", "Apple Safari", "Microsoft Edge");
    comboBox.setValue("Google Chrome");
    // Display an icon which can be clicked to clear the value:
    comboBox.setClearButtonVisible(true);
    comboBox.getStyle().set(ElementConstants.STYLE_WIDTH, WIDTH_STRING);
    comboBox.setId("clear-button-box");
    add(new Div(new H2("Clear button"), comboBox));
}
Also used : Div(com.vaadin.flow.component.html.Div) ComboBox(com.vaadin.flow.component.combobox.ComboBox) H2(com.vaadin.flow.component.html.H2)

Example 48 with ComboBox

use of com.vaadin.flow.component.combobox.ComboBox in project flow-components by vaadin.

the class ComboBoxDemoPage method createComboBoxWithObjectStringSimpleValue.

private void createComboBoxWithObjectStringSimpleValue() {
    Div message = createMessageDiv("value-selection-message");
    ComboBox<Song> comboBox = new ComboBox<>("Artists");
    comboBox.setItemLabelGenerator(Song::getArtist);
    List<Song> listOfSongs = createListOfSongs();
    comboBox.setItems(listOfSongs);
    comboBox.addValueChangeListener(event -> {
        if (event.getSource().isEmpty()) {
            message.setText("No artist selected");
        } else if (event.getOldValue() == null) {
            message.setText("Selected artist: " + event.getValue().getArtist());
        } else {
            message.setText("Selected artist: " + event.getValue().getArtist() + "\nThe old selection was: " + event.getOldValue().getArtist());
        }
    });
    comboBox.getStyle().set(ElementConstants.STYLE_WIDTH, WIDTH_STRING);
    comboBox.setId("value-selection-box");
    add(new Div(new H2("Value selection from objects"), comboBox, message));
}
Also used : Div(com.vaadin.flow.component.html.Div) ComboBox(com.vaadin.flow.component.combobox.ComboBox) H2(com.vaadin.flow.component.html.H2)

Example 49 with ComboBox

use of com.vaadin.flow.component.combobox.ComboBox in project flow-components by vaadin.

the class ComboBoxDemoPage method createComboBoxWithInMemoryLazyLoading.

private void createComboBoxWithInMemoryLazyLoading() {
    ComboBox<String> comboBox = new ComboBox<>();
    /*
         * Using a large data set makes the browser request items lazily as the
         * user scrolls down the overlay. This will also trigger server-side
         * filtering.
         */
    List<String> names = getNames(500);
    comboBox.setItems(names);
    comboBox.setId("lazy-loading-box");
    add(new Div(new H2("Lazy Loading"), new H2("Lazy loading between client and server"), comboBox));
}
Also used : Div(com.vaadin.flow.component.html.Div) ComboBox(com.vaadin.flow.component.combobox.ComboBox) H2(com.vaadin.flow.component.html.H2)

Example 50 with ComboBox

use of com.vaadin.flow.component.combobox.ComboBox in project flow-components by vaadin.

the class ComboBoxDemoPage method createComboBoxUsingTemplateRenderer.

private void createComboBoxUsingTemplateRenderer() {
    Div message = createMessageDiv("template-selection-message");
    ComboBox<Song> comboBox = new ComboBox<>();
    List<Song> listOfSongs = createListOfSongs();
    /*
         * Providing a custom item filter allows filtering based on all of the
         * rendered properties:
         */
    ItemFilter<Song> filter = (song, filterString) -> song.getName().toLowerCase().contains(filterString.toLowerCase()) || song.getArtist().toLowerCase().contains(filterString.toLowerCase());
    comboBox.setItems(filter, listOfSongs);
    comboBox.setItemLabelGenerator(Song::getName);
    comboBox.setRenderer(TemplateRenderer.<Song>of("<div>[[item.song]]<br><small>[[item.artist]]</small></div>").withProperty("song", Song::getName).withProperty("artist", Song::getArtist));
    comboBox.addValueChangeListener(event -> {
        if (event.getSource().isEmpty()) {
            message.setText("No artist selected");
        } else if (event.getOldValue() == null) {
            message.setText("Selected artist: " + event.getValue().getArtist());
        } else {
            message.setText("Selected artist: " + event.getValue().getArtist() + "\nThe old selection was: " + event.getOldValue().getArtist());
        }
    });
    comboBox.getStyle().set(ElementConstants.STYLE_WIDTH, WIDTH_STRING);
    comboBox.setId("template-selection-box");
    add(new Div(new H2("Using templates"), new H2("Rendering items using TemplateRenderer"), comboBox, message));
}
Also used : Div(com.vaadin.flow.component.html.Div) IntStream(java.util.stream.IntStream) ItemFilter(com.vaadin.flow.component.combobox.ComboBox.ItemFilter) ComponentRenderer(com.vaadin.flow.data.renderer.ComponentRenderer) VerticalLayout(com.vaadin.flow.component.orderedlayout.VerticalLayout) Div(com.vaadin.flow.component.html.Div) Label(com.vaadin.flow.component.html.Label) H2(com.vaadin.flow.component.html.H2) ComboBox(com.vaadin.flow.component.combobox.ComboBox) Collectors(java.util.stream.Collectors) Route(com.vaadin.flow.router.Route) ArrayList(java.util.ArrayList) List(java.util.List) Faker(com.github.javafaker.Faker) TemplateRenderer(com.vaadin.flow.data.renderer.TemplateRenderer) ElementConstants(com.vaadin.flow.dom.ElementConstants) ComboBox(com.vaadin.flow.component.combobox.ComboBox) H2(com.vaadin.flow.component.html.H2)

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