Search in sources :

Example 46 with H2

use of com.vaadin.flow.component.html.H2 in project flow-components by vaadin.

the class ComboBoxDemoPage method createComboBoxUsingComponentRenderer.

private void createComboBoxUsingComponentRenderer() {
    Div message = createMessageDiv("component-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(new ComponentRenderer<>(item -> {
        VerticalLayout container = new VerticalLayout();
        Label song = new Label(item.getName());
        container.add(song);
        Label artist = new Label(item.getArtist());
        artist.getStyle().set("fontSize", "smaller");
        container.add(artist);
        return container;
    }));
    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("component-selection-box");
    add(new Div(new H2("Using components"), new H2("Rendering items using ComponentTemplateRenderer"), 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) Label(com.vaadin.flow.component.html.Label) VerticalLayout(com.vaadin.flow.component.orderedlayout.VerticalLayout) H2(com.vaadin.flow.component.html.H2)

Example 47 with H2

use of com.vaadin.flow.component.html.H2 in project flow-components by vaadin.

the class ContextMenuView method addCard.

private void addCard(String title, Component... components) {
    VerticalLayout layout = new VerticalLayout();
    layout.setMargin(true);
    layout.add(new H2(title));
    layout.add(components);
    add(layout);
}
Also used : VerticalLayout(com.vaadin.flow.component.orderedlayout.VerticalLayout) H2(com.vaadin.flow.component.html.H2)

Example 48 with H2

use of com.vaadin.flow.component.html.H2 in project flow-components by vaadin.

the class IronListView method addCard.

private void addCard(String title, String description, Component... components) {
    if (description != null) {
        title = title + ": " + description;
    }
    VerticalLayout layout = new VerticalLayout();
    layout.setMargin(true);
    layout.add(new H2(title));
    layout.add(components);
    add(layout);
}
Also used : VerticalLayout(com.vaadin.flow.component.orderedlayout.VerticalLayout) H2(com.vaadin.flow.component.html.H2)

Example 49 with H2

use of com.vaadin.flow.component.html.H2 in project flow-components by vaadin.

the class RadioButtonGroupDemoPage method addCard.

private Component addCard(String title, Component... components) {
    VerticalLayout layout = new VerticalLayout();
    layout.setMargin(true);
    layout.add(new H2(title));
    layout.add(components);
    add(layout);
    return layout;
}
Also used : VerticalLayout(com.vaadin.flow.component.orderedlayout.VerticalLayout) H2(com.vaadin.flow.component.html.H2)

Example 50 with H2

use of com.vaadin.flow.component.html.H2 in project flow-components by vaadin.

the class CheckboxDemoPage method addCard.

private void addCard(String title, Component... components) {
    VerticalLayout layout = new VerticalLayout();
    layout.setMargin(true);
    layout.add(new H2(title));
    layout.add(components);
    add(layout);
}
Also used : VerticalLayout(com.vaadin.flow.component.orderedlayout.VerticalLayout) H2(com.vaadin.flow.component.html.H2)

Aggregations

H2 (com.vaadin.flow.component.html.H2)68 VerticalLayout (com.vaadin.flow.component.orderedlayout.VerticalLayout)29 Div (com.vaadin.flow.component.html.Div)25 Grid (com.vaadin.flow.component.grid.Grid)11 ComboBox (com.vaadin.flow.component.combobox.ComboBox)10 Button (com.vaadin.flow.component.button.Button)8 Paragraph (com.vaadin.flow.component.html.Paragraph)7 HorizontalLayout (com.vaadin.flow.component.orderedlayout.HorizontalLayout)7 Route (com.vaadin.flow.router.Route)6 List (java.util.List)6 IntStream (java.util.stream.IntStream)6 NativeButton (com.vaadin.flow.component.html.NativeButton)5 ArrayList (java.util.ArrayList)5 Html (com.vaadin.flow.component.Html)4 TextField (com.vaadin.flow.component.textfield.TextField)4 Faker (com.github.javafaker.Faker)3 ItemFilter (com.vaadin.flow.component.combobox.ComboBox.ItemFilter)3 Label (com.vaadin.flow.component.html.Label)3 CallbackDataProvider (com.vaadin.flow.data.provider.CallbackDataProvider)3 ComponentRenderer (com.vaadin.flow.data.renderer.ComponentRenderer)3