Search in sources :

Example 6 with ComponentRenderer

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

the class GridWithTemplatePage method createGridInATemplateWithTemplatesInTheCells.

private void createGridInATemplateWithTemplatesInTheCells() {
    GridInATemplate gridInATemplate = new GridInATemplate();
    gridInATemplate.setId("injected-template-in-cells");
    Grid<String> grid = gridInATemplate.getGrid();
    setCommonGridFeatures(grid, gridInATemplate.getId().get());
    grid.addColumn(value -> value);
    grid.addColumn(new ComponentRenderer<>(value -> getTestTemplate(value, grid.getId().get())));
    add(new H3("Grid with templates in the cells"), gridInATemplate);
}
Also used : ComponentRenderer(com.vaadin.flow.data.renderer.ComponentRenderer) Grid(com.vaadin.flow.component.grid.Grid) TemplateRenderer(com.vaadin.flow.data.renderer.TemplateRenderer) Element(com.vaadin.flow.dom.Element) Div(com.vaadin.flow.component.html.Div) H3(com.vaadin.flow.component.html.H3) H2(com.vaadin.flow.component.html.H2) Route(com.vaadin.flow.router.Route) H3(com.vaadin.flow.component.html.H3)

Example 7 with ComponentRenderer

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

the class GridWithTemplatePage method createGridInTemplateWithColumnProperties.

private void createGridInTemplateWithColumnProperties() {
    GridInATemplate gridInATemplate = new GridInATemplate();
    gridInATemplate.setId("injected-columns-with-properties");
    Grid<String> grid = gridInATemplate.getGrid();
    setCommonGridFeatures(grid, gridInATemplate.getId().get());
    grid.addColumn(value -> value).setFlexGrow(2);
    grid.addColumn(TemplateRenderer.of("[[index]]")).setFlexGrow(0).setWidth("20px");
    grid.addColumn(new ComponentRenderer<>(value -> getTestTemplate(value, grid.getId().get()))).setFrozen(true).setResizable(true);
    add(new H3("Grid with column properties"), gridInATemplate);
}
Also used : ComponentRenderer(com.vaadin.flow.data.renderer.ComponentRenderer) Grid(com.vaadin.flow.component.grid.Grid) TemplateRenderer(com.vaadin.flow.data.renderer.TemplateRenderer) Element(com.vaadin.flow.dom.Element) Div(com.vaadin.flow.component.html.Div) H3(com.vaadin.flow.component.html.H3) H2(com.vaadin.flow.component.html.H2) Route(com.vaadin.flow.router.Route) H3(com.vaadin.flow.component.html.H3)

Example 8 with ComponentRenderer

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

the class GridWithTemplatePage method createGridInATemplateWithTemplatesInTheDetails.

private void createGridInATemplateWithTemplatesInTheDetails() {
    GridInATemplate gridInATemplate = new GridInATemplate();
    gridInATemplate.setId("injected-template-in-details");
    Grid<String> grid = gridInATemplate.getGrid();
    setCommonGridFeatures(grid, gridInATemplate.getId().get());
    grid.addColumn(value -> value);
    grid.setItemDetailsRenderer(new ComponentRenderer<>(value -> getTestTemplate(value, grid.getId().get())));
    add(new H3("Grid with templates in the details"), gridInATemplate);
}
Also used : ComponentRenderer(com.vaadin.flow.data.renderer.ComponentRenderer) Grid(com.vaadin.flow.component.grid.Grid) TemplateRenderer(com.vaadin.flow.data.renderer.TemplateRenderer) Element(com.vaadin.flow.dom.Element) Div(com.vaadin.flow.component.html.Div) H3(com.vaadin.flow.component.html.H3) H2(com.vaadin.flow.component.html.H2) Route(com.vaadin.flow.router.Route) H3(com.vaadin.flow.component.html.H3)

Example 9 with ComponentRenderer

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

the class GridTestPage method createGridWithComponentRenderers.

private void createGridWithComponentRenderers() {
    Grid<Item> grid = new Grid<>();
    grid.setSelectionMode(Grid.SelectionMode.MULTI);
    AtomicBoolean usingFirstList = new AtomicBoolean(true);
    List<Item> firstList = generateItems(20, 0);
    List<Item> secondList = generateItems(10, 20);
    grid.setItems(firstList);
    grid.addColumn(new ComponentRenderer<>(item -> {
        Label label = new Label(item.getName());
        label.setId("grid-with-component-renderers-item-name-" + item.getNumber());
        return label;
    })).setKey("name").setHeader("Name");
    grid.addColumn(new ComponentRenderer<>(item -> {
        Label label = new Label(String.valueOf(item.getNumber()));
        label.setId("grid-with-component-renderers-item-number-" + item.getNumber());
        return label;
    })).setKey("number").setHeader("Number");
    grid.addColumn(new ComponentRenderer<>(item -> {
        NativeButton remove = new NativeButton("Remove", evt -> {
            if (usingFirstList.get()) {
                firstList.remove(item);
            } else {
                secondList.remove(item);
            }
            grid.getDataProvider().refreshAll();
        });
        remove.setId("grid-with-component-renderers-remove-" + item.getNumber());
        return remove;
    })).setKey("remove");
    grid.addColumn(TemplateRenderer.<Item>of("hidden")).setHeader("hidden").setKey("hidden").setVisible(false);
    grid.setId("grid-with-component-renderers");
    grid.setWidth("500px");
    grid.setHeight("500px");
    NativeButton changeList = new NativeButton("Change list", evt -> {
        if (usingFirstList.get()) {
            grid.setItems(secondList);
        } else {
            grid.setItems(firstList);
        }
        usingFirstList.set(!usingFirstList.get());
    });
    changeList.setId("grid-with-component-renderers-change-list");
    NativeButton toggleColumnOrdering = new NativeButton("Toggle column ordering", evt -> {
        grid.setColumnReorderingAllowed(!grid.isColumnReorderingAllowed());
    });
    toggleColumnOrdering.setId("toggle-column-ordering");
    NativeButton setReorderListener = new NativeButton("Set reorder listener", evt -> {
        grid.addColumnReorderListener(e -> {
            if (e.isFromClient()) {
                List<Column<Item>> columnList = e.getColumns().stream().collect(Collectors.toList());
                // Reorder columns in the list
                Collections.swap(columnList, 1, 2);
                grid.setColumnOrder(columnList);
            }
        });
    });
    setReorderListener.setId("set-reorder-listener");
    Span currentColumnOrdering = new Span();
    currentColumnOrdering.setId("current-column-ordering");
    grid.addColumnReorderListener(e -> currentColumnOrdering.setText(e.getColumns().stream().map(Column::getKey).collect(Collectors.joining(", "))));
    add(grid, changeList, toggleColumnOrdering, setReorderListener, currentColumnOrdering);
}
Also used : ComponentRenderer(com.vaadin.flow.data.renderer.ComponentRenderer) Grid(com.vaadin.flow.component.grid.Grid) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) 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) Serializable(java.io.Serializable) ArrayList(java.util.ArrayList) Route(com.vaadin.flow.router.Route) List(java.util.List) Column(com.vaadin.flow.component.grid.Grid.Column) TemplateRenderer(com.vaadin.flow.data.renderer.TemplateRenderer) HasComponents(com.vaadin.flow.component.HasComponents) Collections(java.util.Collections) Span(com.vaadin.flow.component.html.Span) NativeButton(com.vaadin.flow.component.html.NativeButton) Grid(com.vaadin.flow.component.grid.Grid) Label(com.vaadin.flow.component.html.Label) Span(com.vaadin.flow.component.html.Span) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ComponentRenderer(com.vaadin.flow.data.renderer.ComponentRenderer) Column(com.vaadin.flow.component.grid.Grid.Column)

Example 10 with ComponentRenderer

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

the class TreeComponentColumnsPage method addTreeGrid.

private void addTreeGrid(boolean addGridBefore) {
    TreeGrid<String> grid = new TreeGrid<>();
    if (addGridBefore) {
        grid.setId("grid-then-comp");
        add(grid);
    }
    ComponentRenderer<TextField, String> componentRenderer = new ComponentRenderer<>(TextField::new, (component, item) -> {
        component.setReadOnly(true);
        component.setValue(item);
    });
    grid.addComponentHierarchyColumn(this::createTextField).setHeader("Header A").setId("textfield");
    grid.addColumn(componentRenderer).setHeader("Header B");
    ComponentRenderer<Button, String> componentRendererBtn = new ComponentRenderer<>(() -> new Button("btn"), ((button, s) -> {
        button.setText(s);
        button.setThemeName(ButtonVariant.LUMO_ERROR.getVariantName());
    }));
    grid.addColumn(componentRendererBtn).setHeader("Header C");
    TreeData<String> data = new TreeData<>();
    final Map<String, String> parentPathMap = new HashMap<>();
    addRootItems("Granddad", 3, data, parentPathMap).forEach(granddad -> addItems("Dad", 3, granddad, data, parentPathMap).forEach(dad -> addItems("Son", 100, dad, data, parentPathMap)));
    grid.setDataProvider(new TreeDataProvider<>(data));
    if (!addGridBefore) {
        grid.setId("comp-then-grid");
        add(grid);
    }
}
Also used : ComponentRenderer(com.vaadin.flow.data.renderer.ComponentRenderer) TreeGridHugeTreePage.addItems(com.vaadin.flow.component.treegrid.it.TreeGridHugeTreePage.addItems) ButtonVariant(com.vaadin.flow.component.button.ButtonVariant) TreeData(com.vaadin.flow.data.provider.hierarchy.TreeData) TreeGridHugeTreePage.addRootItems(com.vaadin.flow.component.treegrid.it.TreeGridHugeTreePage.addRootItems) Div(com.vaadin.flow.component.html.Div) NativeButton(com.vaadin.flow.component.html.NativeButton) HashMap(java.util.HashMap) TreeGrid(com.vaadin.flow.component.treegrid.TreeGrid) TreeDataProvider(com.vaadin.flow.data.provider.hierarchy.TreeDataProvider) Route(com.vaadin.flow.router.Route) Button(com.vaadin.flow.component.button.Button) Map(java.util.Map) Command(com.vaadin.flow.server.Command) TextField(com.vaadin.flow.component.textfield.TextField) HashMap(java.util.HashMap) ComponentRenderer(com.vaadin.flow.data.renderer.ComponentRenderer) NativeButton(com.vaadin.flow.component.html.NativeButton) Button(com.vaadin.flow.component.button.Button) TreeGrid(com.vaadin.flow.component.treegrid.TreeGrid) TextField(com.vaadin.flow.component.textfield.TextField) TreeData(com.vaadin.flow.data.provider.hierarchy.TreeData)

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