use of com.vaadin.flow.data.renderer.ComponentRenderer in project furms by unity-idm.
the class ProjectAllocationComponent method createCommunityGrid.
private Grid<ProjectAllocationGridModel> createCommunityGrid() {
Grid<ProjectAllocationGridModel> grid = new DenseGrid<>(ProjectAllocationGridModel.class);
grid.addComponentColumn(model -> {
Icon icon = grid.isDetailsVisible(model) ? ANGLE_DOWN.create() : ANGLE_RIGHT.create();
return new Div(icon, new Text(model.siteName));
}).setHeader(getTranslation("view.community-admin.project-allocation.grid.column.1")).setSortable(true);
grid.addComponentColumn(model -> {
if (hasTerminalStatus(model))
return new RouterLink(model.name, ProjectAllocationFormView.class, model.id);
return new Text(model.name);
}).setHeader(getTranslation("view.community-admin.project-allocation.grid.column.2")).setSortable(true).setComparator(model -> model.name.toLowerCase());
grid.addColumn(model -> model.resourceTypeName).setHeader(getTranslation("view.community-admin.project-allocation.grid.column.3")).setSortable(true);
grid.addColumn(model -> model.amountWithUnit).setHeader(getTranslation("view.community-admin.project-allocation.grid.column.4")).setSortable(true).setComparator(comparing(c -> c.amountWithUnit.amount));
grid.addColumn(model -> model.consumedWithUnit).setHeader(getTranslation("view.community-admin.project-allocation.grid.column.5")).setSortable(true).setComparator(comparing(c -> c.consumedWithUnit.amount));
grid.addColumn(model -> model.remainingWithUnit).setHeader(getTranslation("view.community-admin.project-allocation.grid.column.6")).setSortable(true).setComparator(comparing(c -> c.remainingWithUnit.amount));
grid.addComponentColumn(c -> {
Optional<ProjectAllocationInstallation> projectAllocationInstallations = projectDataSnapshot.getAllocation(c.id);
Optional<ProjectDeallocation> deallocation = projectDataSnapshot.getDeallocationStatus(c.id);
if (deallocation.isPresent()) {
int statusId = deallocation.get().status.getPersistentId();
return new StatusLayout(getTranslation("view.community-admin.project-allocation.deallocation-status." + statusId), deallocation.flatMap(x -> x.errorMessage).map(x -> x.message).orElse(null), getContent());
}
return projectAllocationInstallations.map(installation -> {
final int statusId = installation.status.getPersistentId();
return new StatusLayout(getTranslation("view.community-admin.project-allocation.status." + statusId), installation.errorMessage.map(x -> x.message).orElse(null), getContent());
}).orElseGet(StatusLayout::new);
}).setHeader(getTranslation("view.community-admin.project-allocation.grid.column.7")).setSortable(true);
grid.addComponentColumn(model -> new ResourceProgressBar(model.amountWithUnit.amount, model.consumedWithUnit.amount, 0)).setHeader(getTranslation("view.community-admin.project-allocation.grid.column.8")).setTextAlign(ColumnTextAlign.CENTER);
grid.addComponentColumn(this::createLastColumnContent).setHeader(getTranslation("view.community-admin.project-allocation.grid.column.9")).setTextAlign(ColumnTextAlign.END);
grid.setItemDetailsRenderer(new ComponentRenderer<>(x -> new Div(AllocationDetailsComponentFactory.create(x.creationTime, x.validFrom, x.validTo), AllocationDetailsComponentFactory.create(projectDataSnapshot.getChunks(x.id), x.amountWithUnit.unit))));
grid.setSelectionMode(Grid.SelectionMode.NONE);
return grid;
}
use of com.vaadin.flow.data.renderer.ComponentRenderer in project furms by unity-idm.
the class ResourceAllocationsView method createCommunityGrid.
private Grid<ProjectAllocationGridModel> createCommunityGrid() {
Grid<ProjectAllocationGridModel> grid = new DenseGrid<>(ProjectAllocationGridModel.class);
grid.addComponentColumn(allocation -> {
Icon icon = grid.isDetailsVisible(allocation) ? ANGLE_DOWN.create() : ANGLE_RIGHT.create();
return new Div(icon, new Label(allocation.siteName));
}).setHeader(getTranslation("view.project-admin.resource-allocations.grid.column.1")).setSortable(true);
grid.addColumn(model -> model.name).setHeader(getTranslation("view.project-admin.resource-allocations.grid.column.2")).setSortable(true).setComparator(model -> model.name.toLowerCase());
grid.addColumn(model -> model.resourceTypeName).setHeader(getTranslation("view.project-admin.resource-allocations.grid.column.3")).setSortable(true);
grid.addColumn(model -> model.amountWithUnit).setHeader(getTranslation("view.project-admin.resource-allocations.grid.column.4")).setSortable(true).setComparator(comparing(model -> model.amountWithUnit.amount));
grid.addColumn(model -> model.consumedWithUnit).setHeader(getTranslation("view.project-admin.resource-allocations.grid.column.5")).setSortable(true).setComparator(comparing(model -> model.consumedWithUnit.amount));
grid.addColumn(model -> model.remainingWithUnit).setHeader(getTranslation("view.project-admin.resource-allocations.grid.column.6")).setSortable(true).setComparator(comparing(model -> model.remainingWithUnit.amount));
grid.addComponentColumn(c -> {
Optional<ProjectAllocationInstallation> projectAllocationInstallations = projectDataSnapshot.getAllocation(c.id);
Optional<ProjectDeallocation> deallocation = projectDataSnapshot.getDeallocationStatus(c.id);
if (deallocation.isPresent()) {
int statusId = deallocation.get().status.getPersistentId();
return new StatusLayout(getTranslation("view.community-admin.project-allocation.deallocation-status." + statusId), deallocation.flatMap(x -> x.errorMessage).map(x -> x.message).orElse(null), getContent());
}
return projectAllocationInstallations.map(installation -> {
final int statusId = installation.status.getPersistentId();
return new StatusLayout(getTranslation("view.community-admin.project-allocation.status." + statusId), installation.errorMessage.map(x -> x.message).orElse(null), getContent());
}).orElseGet(StatusLayout::new);
}).setHeader(getTranslation("view.project-admin.resource-allocations.grid.column.7")).setSortable(true);
grid.addComponentColumn(model -> new ResourceProgressBar(model.amountWithUnit.amount, model.consumedWithUnit.amount, projectDataSnapshot.getAlarmThreshold(model.id))).setHeader(getTranslation("view.project-admin.resource-allocations.grid.column.8")).setTextAlign(ColumnTextAlign.CENTER);
grid.addComponentColumn(this::createLastColumnContent).setHeader(getTranslation("view.project-admin.resource-allocations.grid.column.9")).setTextAlign(ColumnTextAlign.END);
grid.setItemDetailsRenderer(new ComponentRenderer<>(c -> AllocationDetailsComponentFactory.create(projectDataSnapshot.getChunks(c.id), c.amountWithUnit.unit)));
grid.setSelectionMode(Grid.SelectionMode.NONE);
return grid;
}
use of com.vaadin.flow.data.renderer.ComponentRenderer in project furms by unity-idm.
the class ProjectView method createCommunityGrid.
private Grid<ProjectAllocationGridModel> createCommunityGrid() {
Grid<ProjectAllocationGridModel> grid = new DenseGrid<>(ProjectAllocationGridModel.class);
grid.addComponentColumn(allocation -> {
Icon icon = grid.isDetailsVisible(allocation) ? ANGLE_DOWN.create() : ANGLE_RIGHT.create();
return new Div(icon, new Label(allocation.siteName));
}).setHeader(getTranslation("view.user-settings.project-allocation.grid.column.1")).setSortable(true);
grid.addColumn(model -> model.name).setHeader(getTranslation("view.user-settings.project-allocation.grid.column.2")).setSortable(true).setComparator(model -> model.name.toLowerCase());
grid.addColumn(model -> model.resourceTypeName).setHeader(getTranslation("view.user-settings.project-allocation.grid.column.3")).setSortable(true);
grid.addColumn(model -> model.amountWithUnit).setHeader(getTranslation("view.user-settings.project-allocation.grid.column.4")).setSortable(true).setComparator(comparing(model -> model.amountWithUnit.amount));
grid.addColumn(model -> model.consumedWithUnit).setHeader(getTranslation("view.user-settings.project-allocation.grid.column.5")).setSortable(true).setComparator(comparing(model -> model.consumedWithUnit.amount));
grid.addColumn(model -> model.remainingWithUnit).setHeader(getTranslation("view.user-settings.project-allocation.grid.column.6")).setSortable(true).setComparator(comparing(model -> model.remainingWithUnit.amount));
grid.addComponentColumn(c -> {
Optional<ProjectAllocationInstallation> projectAllocationInstallations = projectDataSnapshot.getParent().getAllocation(c.id);
Optional<ProjectDeallocation> deallocation = projectDataSnapshot.getParent().getDeallocationStatus(c.id);
if (deallocation.isPresent()) {
int statusId = deallocation.get().status.getPersistentId();
return new StatusLayout(getTranslation("view.community-admin.project-allocation.deallocation-status." + statusId), deallocation.flatMap(x -> x.errorMessage).map(x -> x.message).orElse(null), getContent());
}
return projectAllocationInstallations.map(installation -> {
final int statusId = installation.status.getPersistentId();
return new StatusLayout(getTranslation("view.community-admin.project-allocation.status." + statusId), installation.errorMessage.map(x -> x.message).orElse(null), getContent());
}).orElseGet(StatusLayout::new);
}).setHeader(getTranslation("view.user-settings.project-allocation.grid.column.7")).setSortable(true);
grid.addColumn(x -> getEnabledValue(x.id, x.accessibleForAllProjectMembers)).setHeader(getTranslation("view.user-settings.project-allocation.grid.column.8")).setSortable(true);
grid.addComponentColumn(model -> new ResourceProgressBar(model.amountWithUnit.amount, model.consumedWithUnit.amount, projectDataSnapshot.projectAllocationDataSnapshot.getAlarmThreshold(model.id))).setHeader(getTranslation("view.user-settings.project-allocation.grid.column.9")).setTextAlign(ColumnTextAlign.CENTER);
grid.addComponentColumn(this::createLastColumnContent).setHeader(getTranslation("view.user-settings.project-allocation.grid.column.10")).setTextAlign(ColumnTextAlign.END);
grid.setItemDetailsRenderer(new ComponentRenderer<>(c -> AllocationDetailsComponentFactory.create(projectDataSnapshot.getParent().getChunks(c.id), c.amountWithUnit.unit)));
grid.setSelectionMode(Grid.SelectionMode.NONE);
return grid;
}
use of com.vaadin.flow.data.renderer.ComponentRenderer 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;
}
use of com.vaadin.flow.data.renderer.ComponentRenderer 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);
}
Aggregations