Search in sources :

Example 36 with Grid

use of com.vaadin.flow.component.grid.Grid in project furms by unity-idm.

the class ProjectsView method createProjectGrid.

private Grid<ProjectGridModel> createProjectGrid() {
    Grid<ProjectGridModel> grid = new DenseGrid<>(ProjectGridModel.class);
    Grid.Column<ProjectGridModel> firstColumn = grid.addComponentColumn(project -> {
        Component component = new Span(project.name);
        if (project.status.equals(ACTIVE))
            component = new RouterLink(project.name, ProjectView.class, project.id);
        return component;
    }).setHeader(getTranslation("view.user-settings.projects.grid.column.1")).setSortable(true).setComparator(comparing(project -> project.name)).setComparator(project -> project.name.toLowerCase());
    grid.addColumn(project -> project.description).setHeader(getTranslation("view.user-settings.projects.grid.column.2")).setSortable(true);
    grid.addColumn(project -> getTranslation(project.status.gridText)).setHeader(getTranslation("view.user-settings.projects.grid.column.3")).setTextAlign(ColumnTextAlign.END).setSortable(true);
    grid.addComponentColumn(this::createLastColumnContent).setHeader(getTranslation("view.user-settings.projects.grid.column.4")).setTextAlign(ColumnTextAlign.END);
    grid.sort(ImmutableList.of(new GridSortOrder<>(firstColumn, SortDirection.ASCENDING)));
    return grid;
}
Also used : VaadinExceptionHandler.handleExceptions(io.imunity.furms.ui.utils.VaadinExceptionHandler.handleExceptions) SortDirection(com.vaadin.flow.data.provider.SortDirection) Component(com.vaadin.flow.component.Component) NotificationUtils.showErrorNotification(io.imunity.furms.ui.utils.NotificationUtils.showErrorNotification) HorizontalLayout(com.vaadin.flow.component.orderedlayout.HorizontalLayout) FurmsDialog(io.imunity.furms.ui.components.FurmsDialog) MenuButton(io.imunity.furms.ui.components.MenuButton) PageTitle(io.imunity.furms.ui.components.PageTitle) Route(com.vaadin.flow.router.Route) FlexComponent(com.vaadin.flow.component.orderedlayout.FlexComponent) HashSet(java.util.HashSet) PLUS_CIRCLE(com.vaadin.flow.component.icon.VaadinIcon.PLUS_CIRCLE) ImmutableList(com.google.common.collect.ImmutableList) DenseGrid(io.imunity.furms.ui.components.DenseGrid) FurmsViewComponent(io.imunity.furms.ui.components.FurmsViewComponent) PIE_CHART(com.vaadin.flow.component.icon.VaadinIcon.PIE_CHART) RouterLink(com.vaadin.flow.router.RouterLink) UserSettingsMenu(io.imunity.furms.ui.views.user_settings.UserSettingsMenu) Comparator.comparing(java.util.Comparator.comparing) TextField(com.vaadin.flow.component.textfield.TextField) SEARCH(com.vaadin.flow.component.icon.VaadinIcon.SEARCH) ValueChangeMode(com.vaadin.flow.data.value.ValueChangeMode) CheckboxGroupVariant(com.vaadin.flow.component.checkbox.CheckboxGroupVariant) MINUS_CIRCLE(com.vaadin.flow.component.icon.VaadinIcon.MINUS_CIRCLE) REQUESTED(io.imunity.furms.ui.views.user_settings.projects.UserStatus.REQUESTED) Grid(com.vaadin.flow.component.grid.Grid) ApplicationNotExistingException(io.imunity.furms.api.validation.exceptions.ApplicationNotExistingException) TRASH(com.vaadin.flow.component.icon.VaadinIcon.TRASH) RouterGridLink(io.imunity.furms.ui.components.RouterGridLink) ACTIVE(io.imunity.furms.ui.views.user_settings.projects.UserStatus.ACTIVE) Set(java.util.Set) GridActionMenu(io.imunity.furms.ui.components.GridActionMenu) GridActionsButtonLayout(io.imunity.furms.ui.components.GridActionsButtonLayout) ProjectApplicationsService(io.imunity.furms.api.applications.ProjectApplicationsService) GridSortOrder(com.vaadin.flow.component.grid.GridSortOrder) UserAlreadyInvitedException(io.imunity.furms.api.validation.exceptions.UserAlreadyInvitedException) Tooltip(com.vaadin.componentfactory.Tooltip) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) ColumnTextAlign(com.vaadin.flow.component.grid.ColumnTextAlign) ProjectService(io.imunity.furms.api.projects.ProjectService) CheckboxGroup(com.vaadin.flow.component.checkbox.CheckboxGroup) UserWithoutFenixIdValidationError(io.imunity.furms.api.validation.exceptions.UserWithoutFenixIdValidationError) Dialog(com.vaadin.flow.component.dialog.Dialog) Collections(java.util.Collections) Span(com.vaadin.flow.component.html.Span) ViewHeaderLayout(io.imunity.furms.ui.components.ViewHeaderLayout) NotificationUtils.showSuccessNotification(io.imunity.furms.ui.utils.NotificationUtils.showSuccessNotification) RouterLink(com.vaadin.flow.router.RouterLink) GridSortOrder(com.vaadin.flow.component.grid.GridSortOrder) DenseGrid(io.imunity.furms.ui.components.DenseGrid) DenseGrid(io.imunity.furms.ui.components.DenseGrid) Grid(com.vaadin.flow.component.grid.Grid) Component(com.vaadin.flow.component.Component) FlexComponent(com.vaadin.flow.component.orderedlayout.FlexComponent) FurmsViewComponent(io.imunity.furms.ui.components.FurmsViewComponent) Span(com.vaadin.flow.component.html.Span)

Example 37 with Grid

use of com.vaadin.flow.component.grid.Grid in project furms by unity-idm.

the class PendingRequestsView method createPendingMessagesGrid.

private Grid<PendingMessageGridModel> createPendingMessagesGrid(Map<CorrelationId, Checkbox> checkboxes, Component mainContextMenu) {
    Grid<PendingMessageGridModel> grid;
    grid = new DenseGrid<>(PendingMessageGridModel.class);
    grid.addComponentColumn(pendingMessageGridModel -> {
        Checkbox checkbox = new Checkbox();
        checkboxes.put(pendingMessageGridModel.id, checkbox);
        HorizontalLayout horizontalLayout = new HorizontalLayout(checkbox, grid.isDetailsVisible(pendingMessageGridModel) ? ANGLE_DOWN.create() : ANGLE_RIGHT.create(), new Paragraph(getTranslationOrDefault("view.site-admin.pending-requests.page.grid.operation-type." + pendingMessageGridModel.operationType, pendingMessageGridModel.operationType)));
        horizontalLayout.setAlignItems(CENTER);
        return horizontalLayout;
    }).setHeader(new HorizontalLayout(mainContextMenu, new Label(getTranslation("view.site-admin.pending-requests.page.grid.1")))).setFlexGrow(2);
    grid.addColumn(model -> model.status).setHeader(getTranslation("view.site-admin.pending-requests.page.grid.2")).setSortable(true);
    grid.addColumn(model -> model.sentAt.format(dateTimeFormatter)).setHeader(getTranslation("view.site-admin.pending-requests.page.grid.3")).setSortable(true);
    grid.addColumn(model -> Optional.ofNullable(model.ackAt).map(ackTime -> ackTime.format(dateTimeFormatter)).orElse("")).setHeader(getTranslation("view.site-admin.pending-requests.page.grid.4")).setSortable(true);
    grid.addColumn(model -> model.retryAmount).setHeader(getTranslation("view.site-admin.pending-requests.page.grid.5")).setSortable(true);
    grid.addComponentColumn(this::createContextMenu).setHeader(getTranslation("view.site-admin.pending-requests.page.grid.6")).setTextAlign(ColumnTextAlign.END);
    grid.setItemDetailsRenderer(new ComponentRenderer<>(data -> {
        Paragraph json = new Paragraph(data.json);
        json.getStyle().set("font-family", "monospace");
        json.getStyle().set("word-wrap", "break-word");
        json.getElement().getStyle().set("white-space", "pre-wrap");
        return json;
    }));
    return grid;
}
Also used : ComponentRenderer(com.vaadin.flow.data.renderer.ComponentRenderer) UTCTimeUtils.convertToZoneTime(io.imunity.furms.utils.UTCTimeUtils.convertToZoneTime) Component(com.vaadin.flow.component.Component) PLAY(com.vaadin.flow.component.icon.VaadinIcon.PLAY) HorizontalLayout(com.vaadin.flow.component.orderedlayout.HorizontalLayout) LoggerFactory(org.slf4j.LoggerFactory) Label(com.vaadin.flow.component.html.Label) MenuButton(io.imunity.furms.ui.components.MenuButton) PageTitle(io.imunity.furms.ui.components.PageTitle) Route(com.vaadin.flow.router.Route) DenseGrid(io.imunity.furms.ui.components.DenseGrid) SiteAgentConnectionService(io.imunity.furms.api.site_agent_pending_message.SiteAgentConnectionService) Map(java.util.Map) UI(com.vaadin.flow.component.UI) ANGLE_RIGHT(com.vaadin.flow.component.icon.VaadinIcon.ANGLE_RIGHT) Paragraph(com.vaadin.flow.component.html.Paragraph) SiteAdminMenu(io.imunity.furms.ui.views.site.SiteAdminMenu) CorrelationId(io.imunity.furms.domain.site_agent.CorrelationId) MethodHandles(java.lang.invoke.MethodHandles) MissingResourceException(java.util.MissingResourceException) Set(java.util.Set) SearchLayout(io.imunity.furms.ui.components.administrators.SearchLayout) Collectors(java.util.stream.Collectors) ZoneId(java.time.ZoneId) ANGLE_DOWN(com.vaadin.flow.component.icon.VaadinIcon.ANGLE_DOWN) Checkbox(com.vaadin.flow.component.checkbox.Checkbox) ColumnTextAlign(com.vaadin.flow.component.grid.ColumnTextAlign) Optional(java.util.Optional) Dialog(com.vaadin.flow.component.dialog.Dialog) ViewHeaderLayout(io.imunity.furms.ui.components.ViewHeaderLayout) VaadinExceptionHandler.handleExceptions(io.imunity.furms.ui.utils.VaadinExceptionHandler.handleExceptions) ResourceGetter.getCurrentResourceId(io.imunity.furms.ui.utils.ResourceGetter.getCurrentResourceId) IconButton(io.imunity.furms.ui.components.IconButton) NotificationUtils.showErrorNotification(io.imunity.furms.ui.utils.NotificationUtils.showErrorNotification) FurmsDialog(io.imunity.furms.ui.components.FurmsDialog) HashMap(java.util.HashMap) REFRESH(com.vaadin.flow.component.icon.VaadinIcon.REFRESH) FurmsViewComponent(io.imunity.furms.ui.components.FurmsViewComponent) Grid(com.vaadin.flow.component.grid.Grid) UIContext(io.imunity.furms.ui.user_context.UIContext) Logger(org.slf4j.Logger) CENTER(com.vaadin.flow.component.orderedlayout.FlexComponent.Alignment.CENTER) ProgressBar(com.vaadin.flow.component.progressbar.ProgressBar) SiteId(io.imunity.furms.domain.sites.SiteId) TRASH(com.vaadin.flow.component.icon.VaadinIcon.TRASH) VerticalLayout(com.vaadin.flow.component.orderedlayout.VerticalLayout) GridActionMenu(io.imunity.furms.ui.components.GridActionMenu) GridActionsButtonLayout(io.imunity.furms.ui.components.GridActionsButtonLayout) Consumer(java.util.function.Consumer) Button(com.vaadin.flow.component.button.Button) DateTimeFormatter(java.time.format.DateTimeFormatter) Checkbox(com.vaadin.flow.component.checkbox.Checkbox) Label(com.vaadin.flow.component.html.Label) HorizontalLayout(com.vaadin.flow.component.orderedlayout.HorizontalLayout) Paragraph(com.vaadin.flow.component.html.Paragraph)

Example 38 with Grid

use of com.vaadin.flow.component.grid.Grid in project furms by unity-idm.

the class InvitationsView method createInvitationGrid.

private Grid<InvitationGridModel> createInvitationGrid(Map<InvitationId, Checkbox> checkboxes, Component mainContextMenu) {
    final Grid<InvitationGridModel> grid;
    grid = new DenseGrid<>(InvitationGridModel.class);
    grid.addComponentColumn(invitationGridModel -> {
        Checkbox checkbox = new Checkbox();
        checkboxes.put(invitationGridModel.id, checkbox);
        return new HorizontalLayout(checkbox, new Label(invitationGridModel.resourceName));
    }).setHeader(new HorizontalLayout(mainContextMenu, new Label(getTranslation("view.user-settings.invitations.grid.1"))));
    grid.addColumn(x -> x.role).setHeader(getTranslation("view.user-settings.invitations.grid.2")).setSortable(true);
    grid.addColumn(x -> x.originator).setHeader(getTranslation("view.user-settings.invitations.grid.3")).setSortable(true);
    grid.addColumn(x -> x.expiration.format(dateTimeFormatter)).setHeader(getTranslation("view.user-settings.invitations.grid.4")).setSortable(true);
    grid.addComponentColumn(x -> createContextMenu(x.id)).setHeader(getTranslation("view.user-settings.invitations.grid.5")).setTextAlign(ColumnTextAlign.END);
    return grid;
}
Also used : UTCTimeUtils.convertToZoneTime(io.imunity.furms.utils.UTCTimeUtils.convertToZoneTime) Component(com.vaadin.flow.component.Component) NotificationUtils.showErrorNotification(io.imunity.furms.ui.utils.NotificationUtils.showErrorNotification) HorizontalLayout(com.vaadin.flow.component.orderedlayout.HorizontalLayout) LoggerFactory(org.slf4j.LoggerFactory) Label(com.vaadin.flow.component.html.Label) FurmsDialog(io.imunity.furms.ui.components.FurmsDialog) MenuButton(io.imunity.furms.ui.components.MenuButton) HashMap(java.util.HashMap) InvitationNotExistingException(io.imunity.furms.api.validation.exceptions.InvitationNotExistingException) PageTitle(io.imunity.furms.ui.components.PageTitle) Route(com.vaadin.flow.router.Route) DenseGrid(io.imunity.furms.ui.components.DenseGrid) FurmsViewComponent(io.imunity.furms.ui.components.FurmsViewComponent) Map(java.util.Map) UserSettingsMenu(io.imunity.furms.ui.views.user_settings.UserSettingsMenu) Grid(com.vaadin.flow.component.grid.Grid) UIContext(io.imunity.furms.ui.user_context.UIContext) Logger(org.slf4j.Logger) MethodHandles(java.lang.invoke.MethodHandles) Set(java.util.Set) GridActionMenu(io.imunity.furms.ui.components.GridActionMenu) Collectors(java.util.stream.Collectors) ZoneId(java.time.ZoneId) Checkbox(com.vaadin.flow.component.checkbox.Checkbox) DateTimeFormatter(java.time.format.DateTimeFormatter) ColumnTextAlign(com.vaadin.flow.component.grid.ColumnTextAlign) InvitationId(io.imunity.furms.domain.invitations.InvitationId) Optional(java.util.Optional) CLOSE_CIRCLE(com.vaadin.flow.component.icon.VaadinIcon.CLOSE_CIRCLE) CHECK_CIRCLE(com.vaadin.flow.component.icon.VaadinIcon.CHECK_CIRCLE) Dialog(com.vaadin.flow.component.dialog.Dialog) InviteeService(io.imunity.furms.api.invitations.InviteeService) ViewHeaderLayout(io.imunity.furms.ui.components.ViewHeaderLayout) Checkbox(com.vaadin.flow.component.checkbox.Checkbox) Label(com.vaadin.flow.component.html.Label) HorizontalLayout(com.vaadin.flow.component.orderedlayout.HorizontalLayout)

Example 39 with Grid

use of com.vaadin.flow.component.grid.Grid in project linkki by linkki-framework.

the class TestUiUtil method getColumnHeaders.

public static List<String> getColumnHeaders(Grid<?> grid) {
    Method getHeaderRendererMethod;
    Field templateField;
    try {
        getHeaderRendererMethod = Column.class.getSuperclass().getDeclaredMethod("getHeaderRenderer");
        getHeaderRendererMethod.setAccessible(true);
        templateField = Renderer.class.getDeclaredField("template");
        templateField.setAccessible(true);
    } catch (NoSuchMethodException | NoSuchFieldException | SecurityException | IllegalArgumentException e) {
        throw new RuntimeException(e);
    }
    return grid.getColumns().stream().map(c -> getColumnHeader(c, getHeaderRendererMethod, templateField)).collect(Collectors.toList());
}
Also used : AbstractFieldSupport(com.vaadin.flow.component.internal.AbstractFieldSupport) LinkkiSection(org.linkki.core.vaadin.component.section.LinkkiSection) BindingContext(org.linkki.core.binding.BindingContext) Grid(com.vaadin.flow.component.grid.Grid) Component(com.vaadin.flow.component.Component) AbstractSinglePropertyField(com.vaadin.flow.component.AbstractSinglePropertyField) Div(com.vaadin.flow.component.html.Div) Label(com.vaadin.flow.component.html.Label) HasListDataView(com.vaadin.flow.data.provider.HasListDataView) Field(java.lang.reflect.Field) Collectors(java.util.stream.Collectors) UiCreator(org.linkki.core.uicreation.UiCreator) FormItem(com.vaadin.flow.component.formlayout.FormLayout.FormItem) InvocationTargetException(java.lang.reflect.InvocationTargetException) Objects(java.util.Objects) List(java.util.List) Column(com.vaadin.flow.component.grid.Grid.Column) AbstractField(com.vaadin.flow.component.AbstractField) ListDataView(com.vaadin.flow.data.provider.ListDataView) PmoBasedSectionFactory(org.linkki.core.ui.creation.section.PmoBasedSectionFactory) WrapperType(org.linkki.core.binding.wrapper.WrapperType) Renderer(com.vaadin.flow.data.renderer.Renderer) Method(java.lang.reflect.Method) NoLabelComponentWrapper(org.linkki.core.ui.wrapper.NoLabelComponentWrapper) AbstractSinglePropertyField(com.vaadin.flow.component.AbstractSinglePropertyField) Field(java.lang.reflect.Field) AbstractField(com.vaadin.flow.component.AbstractField) Renderer(com.vaadin.flow.data.renderer.Renderer) Method(java.lang.reflect.Method)

Example 40 with Grid

use of com.vaadin.flow.component.grid.Grid in project docs by vaadin.

the class GridDynamicHeight method setupGrid.

private void setupGrid() {
    // tag::snippet[]
    grid = new Grid<>(Person.class, false);
    grid.setAllRowsVisible(true);
    // end::snippet[]
    grid.addColumn(Person::getFullName).setHeader("Name");
    grid.addColumn(Person::getEmail).setHeader("Email");
    grid.addColumn(person -> person.getAddress().getPhone()).setHeader("Phone");
    grid.addColumn(new ComponentRenderer<>(Button::new, (button, person) -> {
        button.addThemeVariants(ButtonVariant.LUMO_ICON, ButtonVariant.LUMO_ERROR, ButtonVariant.LUMO_TERTIARY);
        button.addClickListener(e -> this.removeInvitation(person));
        button.setIcon(new Icon(VaadinIcon.TRASH));
    })).setHeader("Manage");
    grid.setItems(invitedPeople);
    hint = new Div();
    hint.setText("No invitation has been sent");
    hint.getStyle().set("padding", "var(--lumo-size-l)").set("text-align", "center").set("font-style", "italic").set("color", "var(--lumo-contrast-70pct)");
    add(hint, grid);
}
Also used : ComponentRenderer(com.vaadin.flow.data.renderer.ComponentRenderer) DemoExporter(com.vaadin.demo.DemoExporter) DataService(com.vaadin.demo.domain.DataService) Grid(com.vaadin.flow.component.grid.Grid) ButtonVariant(com.vaadin.flow.component.button.ButtonVariant) HorizontalLayout(com.vaadin.flow.component.orderedlayout.HorizontalLayout) Div(com.vaadin.flow.component.html.Div) VaadinIcon(com.vaadin.flow.component.icon.VaadinIcon) ComboBox(com.vaadin.flow.component.combobox.ComboBox) ArrayList(java.util.ArrayList) Route(com.vaadin.flow.router.Route) List(java.util.List) Button(com.vaadin.flow.component.button.Button) Icon(com.vaadin.flow.component.icon.Icon) Person(com.vaadin.demo.domain.Person) Div(com.vaadin.flow.component.html.Div) ComponentRenderer(com.vaadin.flow.data.renderer.ComponentRenderer) Button(com.vaadin.flow.component.button.Button) VaadinIcon(com.vaadin.flow.component.icon.VaadinIcon) Icon(com.vaadin.flow.component.icon.Icon) Person(com.vaadin.demo.domain.Person)

Aggregations

Grid (com.vaadin.flow.component.grid.Grid)73 Route (com.vaadin.flow.router.Route)41 Div (com.vaadin.flow.component.html.Div)38 List (java.util.List)26 NativeButton (com.vaadin.flow.component.html.NativeButton)22 Person (com.vaadin.flow.data.bean.Person)22 ComponentRenderer (com.vaadin.flow.data.renderer.ComponentRenderer)21 H2 (com.vaadin.flow.component.html.H2)17 Collections (java.util.Collections)16 Button (com.vaadin.flow.component.button.Button)15 HorizontalLayout (com.vaadin.flow.component.orderedlayout.HorizontalLayout)14 ArrayList (java.util.ArrayList)13 Collectors (java.util.stream.Collectors)13 Component (com.vaadin.flow.component.Component)12 ColumnTextAlign (com.vaadin.flow.component.grid.ColumnTextAlign)12 Column (com.vaadin.flow.component.grid.Grid.Column)12 Label (com.vaadin.flow.component.html.Label)12 Span (com.vaadin.flow.component.html.Span)11 TextField (com.vaadin.flow.component.textfield.TextField)10 DenseGrid (io.imunity.furms.ui.components.DenseGrid)10