Search in sources :

Example 1 with IconRenderer

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

the class GridColumnOrderTest method init.

@Before
public void init() {
    grid = new Grid<>();
    firstColumn = grid.addColumn(str -> str).setKey("firstColumn");
    secondColumn = grid.addColumn(str -> str).setKey("secondColumn");
    thirdColumn = grid.addColumn(str -> str).setKey("thirdColumn");
    IconRenderer<String> renderer = new IconRenderer<>(generator -> new Label(":D"));
    fourthColumn = grid.addColumn(renderer).setKey("fourthColumn");
}
Also used : IconRenderer(com.vaadin.flow.data.renderer.IconRenderer) Label(com.vaadin.flow.component.html.Label) Before(org.junit.Before)

Example 2 with IconRenderer

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

the class RadioButtonGroupDemoPage method addItemIconGenerator.

private void addItemIconGenerator() {
    RadioButtonGroup<Person> group = new RadioButtonGroup<>();
    group.setItems(new Person(1, "Joe"), new Person(2, "John"), new Person(3, "Bill"));
    group.setRenderer(new IconRenderer<>(item -> {
        Image image = new Image("https://vaadin.com/images/vaadin-logo.svg", "");
        image.getStyle().set("height", "15px");
        image.getStyle().set("float", "left");
        image.getStyle().set("marginRight", "5px");
        image.getStyle().set("marginTop", "2px");
        return image;
    }, Person::getName));
    group.setId("button-group-icon-generator");
    addCard("Radio button group with icon generator", group);
}
Also used : ComponentRenderer(com.vaadin.flow.data.renderer.ComponentRenderer) Anchor(com.vaadin.flow.component.html.Anchor) Image(com.vaadin.flow.component.html.Image) Component(com.vaadin.flow.component.Component) RadioGroupVariant(com.vaadin.flow.component.radiobutton.RadioGroupVariant) 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) H2(com.vaadin.flow.component.html.H2) Hr(com.vaadin.flow.component.html.Hr) RadioButtonGroup(com.vaadin.flow.component.radiobutton.RadioButtonGroup) IconRenderer(com.vaadin.flow.data.renderer.IconRenderer) Route(com.vaadin.flow.router.Route) Span(com.vaadin.flow.component.html.Span) RadioButtonGroup(com.vaadin.flow.component.radiobutton.RadioButtonGroup) Image(com.vaadin.flow.component.html.Image)

Example 3 with IconRenderer

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

the class GridViewUsingRenderersPage method createBasicRenderers.

private void createBasicRenderers() {
    Grid<Item> grid = new Grid<>();
    grid.setItems(getShoppingCart());
    grid.addColumn(Item::getName).setHeader("Name");
    // NumberRenderer to render numbers in general
    grid.addColumn(new NumberRenderer<>(Item::getPrice, "$ %(,.2f", Locale.US, "$ 0.00")).setHeader("Price");
    // LocalDateTimeRenderer for date and time
    grid.addColumn(new LocalDateTimeRenderer<>(Item::getPurchaseDate, DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT, FormatStyle.MEDIUM))).setHeader("Purchase date and time").setFlexGrow(2);
    // LocalDateRenderer for dates
    grid.addColumn(new LocalDateRenderer<>(Item::getEstimatedDeliveryDate, DateTimeFormatter.ofLocalizedDate(FormatStyle.MEDIUM))).setHeader("Estimated delivery date");
    // Icons
    grid.addColumn(new IconRenderer<>(item -> item.getPrice() > 50 ? new Span("$$$") : new Span("$"), item -> ""));
    // NativeButtonRenderer for an easy clickable button,
    // without creating a component
    grid.addColumn(new NativeButtonRenderer<>("Remove", item -> {
        ListDataProvider<Item> dataProvider = (ListDataProvider<Item>) grid.getDataProvider();
        dataProvider.getItems().remove(item);
        dataProvider.refreshAll();
    })).setWidth("100px").setFlexGrow(0);
    grid.setId("grid-basic-renderers");
    addCard("Using renderers", "Using basic renderers", grid);
}
Also used : ListDataProvider(com.vaadin.flow.data.provider.ListDataProvider) LocalDateRenderer(com.vaadin.flow.data.renderer.LocalDateRenderer) Grid(com.vaadin.flow.component.grid.Grid) FormatStyle(java.time.format.FormatStyle) ItemGenerator(com.vaadin.flow.data.bean.ItemGenerator) IconRenderer(com.vaadin.flow.data.renderer.IconRenderer) Route(com.vaadin.flow.router.Route) NumberRenderer(com.vaadin.flow.data.renderer.NumberRenderer) LocalDateTimeRenderer(com.vaadin.flow.data.renderer.LocalDateTimeRenderer) List(java.util.List) Item(com.vaadin.flow.data.bean.Item) NativeButtonRenderer(com.vaadin.flow.data.renderer.NativeButtonRenderer) Locale(java.util.Locale) DateTimeFormatter(java.time.format.DateTimeFormatter) Span(com.vaadin.flow.component.html.Span) Item(com.vaadin.flow.data.bean.Item) ListDataProvider(com.vaadin.flow.data.provider.ListDataProvider) Grid(com.vaadin.flow.component.grid.Grid) LocalDateRenderer(com.vaadin.flow.data.renderer.LocalDateRenderer) Span(com.vaadin.flow.component.html.Span) NumberRenderer(com.vaadin.flow.data.renderer.NumberRenderer)

Aggregations

IconRenderer (com.vaadin.flow.data.renderer.IconRenderer)3 Label (com.vaadin.flow.component.html.Label)2 Span (com.vaadin.flow.component.html.Span)2 Route (com.vaadin.flow.router.Route)2 Component (com.vaadin.flow.component.Component)1 Grid (com.vaadin.flow.component.grid.Grid)1 Anchor (com.vaadin.flow.component.html.Anchor)1 Div (com.vaadin.flow.component.html.Div)1 H2 (com.vaadin.flow.component.html.H2)1 Hr (com.vaadin.flow.component.html.Hr)1 Image (com.vaadin.flow.component.html.Image)1 NativeButton (com.vaadin.flow.component.html.NativeButton)1 VerticalLayout (com.vaadin.flow.component.orderedlayout.VerticalLayout)1 RadioButtonGroup (com.vaadin.flow.component.radiobutton.RadioButtonGroup)1 RadioGroupVariant (com.vaadin.flow.component.radiobutton.RadioGroupVariant)1 Item (com.vaadin.flow.data.bean.Item)1 ItemGenerator (com.vaadin.flow.data.bean.ItemGenerator)1 ListDataProvider (com.vaadin.flow.data.provider.ListDataProvider)1 ComponentRenderer (com.vaadin.flow.data.renderer.ComponentRenderer)1 LocalDateRenderer (com.vaadin.flow.data.renderer.LocalDateRenderer)1