Search in sources :

Example 1 with LocalDateTimeRenderer

use of com.vaadin.flow.data.renderer.LocalDateTimeRenderer in project komunumo-server by komunumo.

the class RegistrationsDialog method configureGrid.

private void configureGrid() {
    grid.setSelectionMode(Grid.SelectionMode.NONE);
    grid.addThemeVariants(GridVariant.LUMO_NO_BORDER, GridVariant.LUMO_ROW_STRIPES);
    grid.addClassName("registration-dialog");
    grid.addColumn(new ComponentRenderer<>(registrationListEntity -> new Anchor("mailto:" + registrationListEntity.email(), registrationListEntity.fullName()))).setHeader("Attendee").setAutoWidth(true).setFlexGrow(0);
    grid.addColumn(new LocalDateTimeRenderer<>(RegistrationListEntity::date, FormatterUtil.dateTimeFormatter())).setHeader("Registration date").setAutoWidth(true).setFlexGrow(0);
    grid.addColumn(RegistrationListEntity::source).setHeader("Source").setAutoWidth(true).setFlexGrow(0);
    if (event.getDate().isBefore(LocalDateTime.now())) {
        grid.addColumn(new ComponentRenderer<>(registrationListEntity -> new Icon(registrationListEntity.noShow() ? VaadinIcon.CLOSE_CIRCLE_O : VaadinIcon.CHECK_CIRCLE_O))).setHeader("No show").setTextAlign(ColumnTextAlign.CENTER).setAutoWidth(true).setFlexGrow(0);
    }
    grid.addColumn(new ComponentRenderer<>(registrationListEntity -> {
        final var deregisterButton = new EnhancedButton(new Icon(VaadinIcon.TRASH), clickEvent -> deregister(registrationListEntity));
        deregisterButton.setTitle("Deregister this attendee");
        deregisterButton.setEnabled(event.getDate() != null && event.getDate().isAfter(LocalDateTime.now()));
        return deregisterButton;
    })).setHeader("Actions").setAutoWidth(true).setFlexGrow(0);
    grid.setWidthFull();
    grid.setHeightFull();
}
Also used : ImageBanner(ar.com.fdvs.dj.domain.ImageBanner) ComponentRenderer(com.vaadin.flow.data.renderer.ComponentRenderer) Event(org.komunumo.data.entity.Event) CssImport(com.vaadin.flow.component.dependency.CssImport) HorizontalLayout(com.vaadin.flow.component.orderedlayout.HorizontalLayout) PrintPreviewReport(org.vaadin.reports.PrintPreviewReport) LocalDateTime(java.time.LocalDateTime) EnhancedButton(org.komunumo.ui.component.EnhancedButton) FormatterUtil.formatDate(org.komunumo.util.FormatterUtil.formatDate) RegistrationListEntity(org.komunumo.data.entity.RegistrationListEntity) RegistrationListEntityWrapper(org.komunumo.data.entity.reports.RegistrationListEntityWrapper) ByteArrayInputStream(java.io.ByteArrayInputStream) UI(com.vaadin.flow.component.UI) EnhancedDialog(org.komunumo.ui.component.EnhancedDialog) Icon(com.vaadin.flow.component.icon.Icon) TextField(com.vaadin.flow.component.textfield.TextField) StreamRegistration(com.vaadin.flow.server.StreamRegistration) FormatterUtil(org.komunumo.util.FormatterUtil) VaadinSession(com.vaadin.flow.server.VaadinSession) Grid(com.vaadin.flow.component.grid.Grid) Anchor(com.vaadin.flow.component.html.Anchor) GridVariant(com.vaadin.flow.component.grid.GridVariant) UTF_8(java.nio.charset.StandardCharsets.UTF_8) StringWriter(java.io.StringWriter) VaadinIcon(com.vaadin.flow.component.icon.VaadinIcon) CSVWriter(com.opencsv.CSVWriter) LocalDateTimeRenderer(com.vaadin.flow.data.renderer.LocalDateTimeRenderer) Nullable(org.jetbrains.annotations.Nullable) DatabaseService(org.komunumo.data.service.DatabaseService) ColumnTextAlign(com.vaadin.flow.component.grid.ColumnTextAlign) StreamResource(com.vaadin.flow.server.StreamResource) ConfirmDialog(com.vaadin.flow.component.confirmdialog.ConfirmDialog) NotNull(org.jetbrains.annotations.NotNull) Callback(org.komunumo.Callback) FilterField(org.komunumo.ui.component.FilterField) RegistrationListEntity(org.komunumo.data.entity.RegistrationListEntity) EnhancedButton(org.komunumo.ui.component.EnhancedButton) Anchor(com.vaadin.flow.component.html.Anchor) ComponentRenderer(com.vaadin.flow.data.renderer.ComponentRenderer) Icon(com.vaadin.flow.component.icon.Icon) VaadinIcon(com.vaadin.flow.component.icon.VaadinIcon) LocalDateTimeRenderer(com.vaadin.flow.data.renderer.LocalDateTimeRenderer)

Example 2 with LocalDateTimeRenderer

use of com.vaadin.flow.data.renderer.LocalDateTimeRenderer 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

Grid (com.vaadin.flow.component.grid.Grid)2 LocalDateTimeRenderer (com.vaadin.flow.data.renderer.LocalDateTimeRenderer)2 ImageBanner (ar.com.fdvs.dj.domain.ImageBanner)1 CSVWriter (com.opencsv.CSVWriter)1 UI (com.vaadin.flow.component.UI)1 ConfirmDialog (com.vaadin.flow.component.confirmdialog.ConfirmDialog)1 CssImport (com.vaadin.flow.component.dependency.CssImport)1 ColumnTextAlign (com.vaadin.flow.component.grid.ColumnTextAlign)1 GridVariant (com.vaadin.flow.component.grid.GridVariant)1 Anchor (com.vaadin.flow.component.html.Anchor)1 Span (com.vaadin.flow.component.html.Span)1 Icon (com.vaadin.flow.component.icon.Icon)1 VaadinIcon (com.vaadin.flow.component.icon.VaadinIcon)1 HorizontalLayout (com.vaadin.flow.component.orderedlayout.HorizontalLayout)1 TextField (com.vaadin.flow.component.textfield.TextField)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 IconRenderer (com.vaadin.flow.data.renderer.IconRenderer)1