Search in sources :

Example 11 with ComponentRenderer

use of com.vaadin.flow.data.renderer.ComponentRenderer in project flow-components by vaadin.

the class TestView method createOptions.

private void createOptions() {
    Div options = new Div();
    options.add(new NativeButton(SELECT_FIRST_ITEM, event -> select.setValue(items.get(0))));
    options.add(new NativeButton(SELECT_THIRD_ITEM, event -> select.setValue(items.get(2))));
    options.add(new NativeButton(SELECT_LAST_ITEM, event -> select.setValue(items.get(items.size() - 1))));
    options.add(new Div());
    options.add(new NativeButton("Reset 0 items", event -> setItems(0)));
    options.add(new NativeButton("Reset 1 items", event -> setItems(1)));
    options.add(new NativeButton("Reset 2 items", event -> setItems(2)));
    options.add(new NativeButton("Reset 5 items", event -> setItems(5)));
    options.add(new NativeButton("Reset 10 items", event -> setItems(10)));
    options.add(new NativeButton("Reset 20 items", event -> setItems(20)));
    options.add(new NativeButton("Reset 50 items", event -> setItems(50)));
    options.add(new Div());
    options.add(new NativeButton("Refresh item 0", event -> refreshItem(0)));
    options.add(new NativeButton("Refresh item 2", event -> refreshItem(2)));
    options.add(new NativeButton("Refresh item 10", event -> refreshItem(10)));
    options.add(new NativeButton("Refresh All", event -> refreshAll()));
    options.add(new Div());
    options.add(new Checkbox("ItemLabelGenerator", event -> setItemLabelGenerator(event.getValue())));
    options.add(new Checkbox("ItemEnabledProvider", event -> setItemEnabledProvider(event.getValue())));
    options.add(new Div());
    Checkbox emptySelectionEnabled = new Checkbox("emptySelectionEnabled", event -> setEmptySelectionAllowed(event.getValue()));
    emptySelectionEnabled.setValue(select.isEmptySelectionAllowed());
    emptySelectionEnabled.setId("emptySelectionEnabled");
    options.add(emptySelectionEnabled);
    Input emptySelectionCaption = new Input();
    emptySelectionCaption.setId("emptySelectionCaption");
    emptySelectionCaption.setValue(select.getEmptySelectionCaption());
    emptySelectionCaption.addValueChangeListener(event -> setEmptySelectionCaption(event.getValue()));
    options.add(new Span("EmptySelectionCaption:"), emptySelectionCaption);
    options.add(new Div());
    options.add(new NativeButton("focus()", event -> select.focus()));
    Checkbox requiredIndicatorVisible = new Checkbox("RequiredIndicator", event -> select.setRequiredIndicatorVisible(event.getValue()));
    requiredIndicatorVisible.setValue(select.isRequiredIndicatorVisible());
    requiredIndicatorVisible.setId("requiredIndicatorVisible");
    options.add(requiredIndicatorVisible);
    Input errorMessage = new Input();
    errorMessage.setId("errorMessage");
    errorMessage.addValueChangeListener(event -> select.setErrorMessage(event.getValue()));
    options.add(new Span("errorMessage"), errorMessage);
    Input placeholder = new Input();
    placeholder.setId("placeholder");
    placeholder.addValueChangeListener(event -> select.setPlaceholder(event.getValue()));
    options.add(new Span("placeholder"), placeholder);
    options.add(new Div());
    options.add(new NativeButton("Set renderer", event -> {
        if (select.getItemRenderer() == null) {
            select.setRenderer(componentRenderer);
        } else {
            select.setRenderer(null);
        }
    }), new NativeButton("Add HR 0", event -> addHrInBeginning()), new NativeButton("Remove HR 0", event -> removeHrInBeginning()), new NativeButton("Add HR 2", event -> addHrAfterIndexTwo()), new NativeButton("Remove HR 2", event -> removeHrAfterIndexTwo()), new NativeButton("Add HR LAST", event -> addHrLast()), new NativeButton("Remove HR LAST", event -> removeHrLast()));
    options.add(new Div());
    enabled = new Checkbox("Enabled");
    enabled.setValue(select.isEnabled());
    enabled.addValueChangeListener(event -> select.setEnabled(event.getValue()));
    readOnly = new Checkbox("ReadOnly");
    readOnly.setValue(select.isReadOnly());
    readOnly.addValueChangeListener(event -> select.setReadOnly(event.getValue()));
    visible = new Checkbox("Visible");
    visible.setValue(select.isVisible());
    visible.addValueChangeListener(event -> select.setVisible(event.getValue()));
    helperText = new Checkbox("HelperText");
    helperText.setValue(false);
    helperText.addValueChangeListener(event -> {
        if (event.getValue())
            select.setHelperText("Helper text");
        else
            select.setHelperText(null);
    });
    options.add(enabled, readOnly, visible, helperText);
    add(options);
}
Also used : Div(com.vaadin.flow.component.html.Div) HasValue(com.vaadin.flow.component.HasValue) ComponentRenderer(com.vaadin.flow.data.renderer.ComponentRenderer) HasUrlParameter(com.vaadin.flow.router.HasUrlParameter) Select(com.vaadin.flow.component.select.Select) Div(com.vaadin.flow.component.html.Div) NativeButton(com.vaadin.flow.component.html.NativeButton) Hr(com.vaadin.flow.component.html.Hr) BeforeEvent(com.vaadin.flow.router.BeforeEvent) Serializable(java.io.Serializable) ArrayList(java.util.ArrayList) Route(com.vaadin.flow.router.Route) Objects(java.util.Objects) OptionalParameter(com.vaadin.flow.router.OptionalParameter) Checkbox(com.vaadin.flow.component.checkbox.Checkbox) List(java.util.List) Input(com.vaadin.flow.component.html.Input) Span(com.vaadin.flow.component.html.Span) NativeButton(com.vaadin.flow.component.html.NativeButton) Input(com.vaadin.flow.component.html.Input) Checkbox(com.vaadin.flow.component.checkbox.Checkbox) Span(com.vaadin.flow.component.html.Span)

Example 12 with ComponentRenderer

use of com.vaadin.flow.data.renderer.ComponentRenderer in project flow-components by vaadin.

the class GridItemRefreshPage method createComponentGrid.

private void createComponentGrid() {
    Grid<Bean> grid = new Grid<>();
    grid.setHeight("500px");
    grid.addColumn(new ComponentRenderer<Label, Bean>(item -> new Label(item.getFirstField()))).setHeader("First Field");
    grid.addColumn(new ComponentRenderer<Label, Bean>(item -> new Label(String.valueOf(item.getSecondField())))).setHeader("Second Field");
    List<Bean> items = createItems(1000);
    grid.setItems(items);
    grid.setId("component-grid");
    Div div = new Div();
    div.setText("Component Grid");
    add(div, grid);
    addButtons(grid, items, "component-");
}
Also used : Div(com.vaadin.flow.component.html.Div) ComponentRenderer(com.vaadin.flow.data.renderer.ComponentRenderer) Grid(com.vaadin.flow.component.grid.Grid) Label(com.vaadin.flow.component.html.Label)

Example 13 with ComponentRenderer

use of com.vaadin.flow.data.renderer.ComponentRenderer in project flow-components by vaadin.

the class ListBoxViewDemoPage method addItemRenderer.

private void addItemRenderer() {
    ListBox<Item> listBox = new ListBox<>();
    ListBoxListDataView<Item> listDataView = listBox.setItems(getItems());
    listBox.setRenderer(new ComponentRenderer<>(item -> {
        Label name = new Label("Item: " + item.getName());
        Label stock = new Label("In stock: " + item.getStock());
        NativeButton button = new NativeButton("Buy", event -> {
            item.setStock(item.getStock() - 1);
            listDataView.refreshItem(item);
        });
        Div labels = new Div(name, stock);
        Div layout = new Div(labels, button);
        labels.getStyle().set("display", "flex").set("flexDirection", "column").set("marginRight", "10px");
        layout.getStyle().set("display", "flex").set("alignItems", "center");
        return layout;
    }));
    listBox.setItemEnabledProvider(item -> item.getStock() > 0);
    addCard("Using item renderer and disabling items", listBox).setId("list-box-with-renderer");
}
Also used : ListBoxListDataView(com.vaadin.flow.component.listbox.dataview.ListBoxListDataView) ComponentRenderer(com.vaadin.flow.data.renderer.ComponentRenderer) Component(com.vaadin.flow.component.Component) VerticalLayout(com.vaadin.flow.component.orderedlayout.VerticalLayout) Div(com.vaadin.flow.component.html.Div) Label(com.vaadin.flow.component.html.Label) NativeButton(com.vaadin.flow.component.html.NativeButton) ListBox(com.vaadin.flow.component.listbox.ListBox) H3(com.vaadin.flow.component.html.H3) H2(com.vaadin.flow.component.html.H2) Collectors(java.util.stream.Collectors) Route(com.vaadin.flow.router.Route) List(java.util.List) Stream(java.util.stream.Stream) Div(com.vaadin.flow.component.html.Div) NativeButton(com.vaadin.flow.component.html.NativeButton) Label(com.vaadin.flow.component.html.Label) ListBox(com.vaadin.flow.component.listbox.ListBox)

Example 14 with ComponentRenderer

use of com.vaadin.flow.data.renderer.ComponentRenderer in project flow-components by vaadin.

the class IronListTestPage method createListWithComponentRenderer.

private void createListWithComponentRenderer() {
    IronList<String> list = new IronList<>();
    list.setHeight("100px");
    List<String> items = IntStream.range(1, 101).mapToObj(i -> "Item " + i).collect(Collectors.toList());
    list.setRenderer(new ComponentRenderer<>(item -> {
        Label label = new Label(item);
        label.addClassName("component-rendered");
        return label;
    }));
    list.setItems(items);
    list.setId("component-renderer");
    add(list);
}
Also used : IntStream(java.util.stream.IntStream) LocalDateRenderer(com.vaadin.flow.data.renderer.LocalDateRenderer) ComponentRenderer(com.vaadin.flow.data.renderer.ComponentRenderer) Arrays(java.util.Arrays) Query(com.vaadin.flow.data.provider.Query) ValueProvider(com.vaadin.flow.function.ValueProvider) LocalDateTime(java.time.LocalDateTime) Div(com.vaadin.flow.component.html.Div) Label(com.vaadin.flow.component.html.Label) NativeButton(com.vaadin.flow.component.html.NativeButton) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) Route(com.vaadin.flow.router.Route) NumberRenderer(com.vaadin.flow.data.renderer.NumberRenderer) LocalDateTimeRenderer(com.vaadin.flow.data.renderer.LocalDateTimeRenderer) List(java.util.List) NativeButtonRenderer(com.vaadin.flow.data.renderer.NativeButtonRenderer) Locale(java.util.Locale) DataProvider(com.vaadin.flow.data.provider.DataProvider) TemplateRenderer(com.vaadin.flow.data.renderer.TemplateRenderer) LocalDate(java.time.LocalDate) IronList(com.vaadin.flow.component.ironlist.IronList) HasComponents(com.vaadin.flow.component.HasComponents) Renderer(com.vaadin.flow.data.renderer.Renderer) Label(com.vaadin.flow.component.html.Label) IronList(com.vaadin.flow.component.ironlist.IronList)

Example 15 with ComponentRenderer

use of com.vaadin.flow.data.renderer.ComponentRenderer in project flow-components by vaadin.

the class VirtualListPage method createListWithComponentRenderer.

private void createListWithComponentRenderer() {
    VirtualList<String> list = new VirtualList<>();
    list.setHeight("100px");
    List<String> items = IntStream.range(1, 101).mapToObj(i -> "Item " + i).collect(Collectors.toList());
    list.setRenderer(new ComponentRenderer<>(item -> {
        Div text = new Div(new Text(item));
        text.addClassName("component-rendered");
        text.setHeight("18px");
        return text;
    }));
    list.setItems(items);
    list.setId("component-renderer");
    add(list);
}
Also used : IntStream(java.util.stream.IntStream) Text(com.vaadin.flow.component.Text) LocalDateRenderer(com.vaadin.flow.data.renderer.LocalDateRenderer) ComponentRenderer(com.vaadin.flow.data.renderer.ComponentRenderer) Arrays(java.util.Arrays) Query(com.vaadin.flow.data.provider.Query) ValueProvider(com.vaadin.flow.function.ValueProvider) LocalDateTime(java.time.LocalDateTime) Div(com.vaadin.flow.component.html.Div) NativeButton(com.vaadin.flow.component.html.NativeButton) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) Route(com.vaadin.flow.router.Route) NumberRenderer(com.vaadin.flow.data.renderer.NumberRenderer) LocalDateTimeRenderer(com.vaadin.flow.data.renderer.LocalDateTimeRenderer) List(java.util.List) NativeButtonRenderer(com.vaadin.flow.data.renderer.NativeButtonRenderer) Locale(java.util.Locale) DataProvider(com.vaadin.flow.data.provider.DataProvider) TemplateRenderer(com.vaadin.flow.data.renderer.TemplateRenderer) LocalDate(java.time.LocalDate) VirtualList(com.vaadin.flow.component.virtuallist.VirtualList) HasComponents(com.vaadin.flow.component.HasComponents) Renderer(com.vaadin.flow.data.renderer.Renderer) Div(com.vaadin.flow.component.html.Div) VirtualList(com.vaadin.flow.component.virtuallist.VirtualList) Text(com.vaadin.flow.component.Text)

Aggregations

ComponentRenderer (com.vaadin.flow.data.renderer.ComponentRenderer)49 Div (com.vaadin.flow.component.html.Div)33 Route (com.vaadin.flow.router.Route)30 Grid (com.vaadin.flow.component.grid.Grid)23 HorizontalLayout (com.vaadin.flow.component.orderedlayout.HorizontalLayout)20 List (java.util.List)19 Icon (com.vaadin.flow.component.icon.Icon)18 NativeButton (com.vaadin.flow.component.html.NativeButton)14 VaadinIcon (com.vaadin.flow.component.icon.VaadinIcon)14 TemplateRenderer (com.vaadin.flow.data.renderer.TemplateRenderer)14 Collectors (java.util.stream.Collectors)14 Label (com.vaadin.flow.component.html.Label)13 Span (com.vaadin.flow.component.html.Span)12 EnhancedButton (org.komunumo.ui.component.EnhancedButton)12 Component (com.vaadin.flow.component.Component)10 H2 (com.vaadin.flow.component.html.H2)10 ArrayList (java.util.ArrayList)10 Element (com.vaadin.flow.dom.Element)9 Collections (java.util.Collections)9 UI (com.vaadin.flow.component.UI)8