use of com.vaadin.flow.router.OptionalParameter in project flow-components by vaadin.
the class TreeGridPreloadPage method setParameter.
@Override
public void setParameter(BeforeEvent event, @OptionalParameter String parameter) {
Location location = event.getLocation();
QueryParameters queryParameters = location.getQueryParameters();
// query parameter: pageSize
List<String> pageSize = queryParameters.getParameters().get("pageSize");
if (pageSize != null) {
grid.setPageSize(Integer.parseInt(pageSize.get(0)));
}
// query parameter: nodesPerLevel
List<String> nodesPerLevel = queryParameters.getParameters().get("nodesPerLevel");
// query parameter: depth
List<String> depth = queryParameters.getParameters().get("depth");
int dpNodesPerLevel = nodesPerLevel == null ? 3 : Integer.parseInt(nodesPerLevel.get(0));
int dpDepth = depth == null ? 4 : Integer.parseInt(depth.get(0));
setDataProvider(dpNodesPerLevel, dpDepth);
// query parameter: expandedRootIndexes
List<String> expandedRootIndexes = queryParameters.getParameters().get("expandedRootIndexes");
if (expandedRootIndexes != null) {
List<HierarchicalTestBean> expandedRootItems = Arrays.stream(expandedRootIndexes.get(0).split(",")).map(Integer::parseInt).map(expandedRootIndex -> new HierarchicalTestBean(null, 0, expandedRootIndex)).collect(java.util.stream.Collectors.toList());
grid.expandRecursively(expandedRootItems, Integer.MAX_VALUE);
}
// query parameter: sortDirection
List<String> sortDirection = queryParameters.getParameters().get("sortDirection");
if (sortDirection != null) {
SortDirection direction = SortDirection.valueOf(sortDirection.get(0).toUpperCase());
GridSortOrderBuilder<HierarchicalTestBean> sorting = new GridSortOrderBuilder<HierarchicalTestBean>();
Column<HierarchicalTestBean> column = grid.getColumns().get(0);
if (direction == SortDirection.ASCENDING) {
grid.sort(sorting.thenAsc(column).build());
} else {
grid.sort(sorting.thenDesc(column).build());
}
}
}
use of com.vaadin.flow.router.OptionalParameter in project furms by unity-idm.
the class ProjectAllocationFormView method setParameter.
@Override
public void setParameter(BeforeEvent event, @OptionalParameter String parameter) {
ProjectAllocationViewModel projectAllocationModel = ofNullable(parameter).flatMap(id -> handleExceptions(() -> projectAllocationService.findByIdWithRelatedObjects(communityId, id))).flatMap(Function.identity()).map(ProjectAllocationModelsMapper::map).orElseGet(() -> {
String projectId = event.getLocation().getQueryParameters().getParameters().get("projectId").iterator().next();
Project project = projectService.findById(projectId).get();
return new ProjectAllocationViewModel(projectId, project.getName());
});
this.projectId = projectAllocationModel.getProjectId();
String trans = parameter == null ? "view.community-admin.project-allocation.form.parameter.new" : "view.community-admin.project-allocation.form.parameter.update";
breadCrumbParameter = new BreadCrumbParameter(parameter, getTranslation(trans));
projectAllocationFormComponent.setFormPools(projectAllocationModel, () -> projectAllocationService.getOccupiedNames(communityId, projectId));
}
use of com.vaadin.flow.router.OptionalParameter in project furms by unity-idm.
the class AlarmFormView method setParameter.
@Override
public void setParameter(BeforeEvent event, @OptionalParameter String parameter) {
AlarmFormModel alarm = ofNullable(parameter).map(UUID::fromString).flatMap(id -> handleExceptions(() -> alarmService.find(projectId, new AlarmId(id)))).flatMap(Function.identity()).map(AlarmFormModelMapper::map).orElseGet(AlarmFormModel::new);
String trans = parameter == null ? "view.project-admin.alarms.form.parameter.new" : "view.project-admin.alarms.form.parameter.update";
breadCrumbParameter = new BreadCrumbParameter(parameter, getTranslation(trans));
binder.setBean(alarm);
addCreateButtons();
if (alarm.id != null) {
setComboBoxInReadOnlyMode(alarm);
}
}
use of com.vaadin.flow.router.OptionalParameter in project furms by unity-idm.
the class CommunityAllocationFormView method setParameter.
@Override
public void setParameter(BeforeEvent event, @OptionalParameter String parameter) {
CommunityAllocationViewModel serviceViewModel = ofNullable(parameter).flatMap(id -> handleExceptions(() -> communityAllocationService.findByIdWithRelatedObjects(id))).flatMap(Function.identity()).map(CommunityAllocationModelsMapper::map).orElseGet(() -> {
String communityId = event.getLocation().getQueryParameters().getParameters().get("communityId").iterator().next();
return new CommunityAllocationViewModel(communityId, communityService.findById(communityId).get().getName());
});
this.communityId = serviceViewModel.getCommunityId();
String trans = parameter == null ? "view.fenix-admin.resource-credits-allocation.form.parameter.new" : "view.fenix-admin.resource-credits-allocation.form.parameter.update";
breadCrumbParameter = new BreadCrumbParameter(parameter, getTranslation(trans));
communityAllocationFormComponent.setModelObject(serviceViewModel, () -> communityAllocationService.getOccupiedNames(communityId));
}
use of com.vaadin.flow.router.OptionalParameter in project furms by unity-idm.
the class ProjectAllocationsDetailsView method setParameter.
@Override
public void setParameter(BeforeEvent event, @OptionalParameter String parameter) {
Optional<String> projectId = event.getLocation().getQueryParameters().getParameters().getOrDefault("projectId", List.of()).stream().findAny();
Optional<ProjectAllocation> projectAllocation = ofNullable(parameter).filter(id -> projectId.isPresent()).flatMap(id -> handleExceptions(() -> projectAllocationService.findByProjectIdAndId(projectId.get(), id))).flatMap(Function.identity());
if (projectAllocation.isPresent()) {
getContent().removeAll();
breadCrumbParameter = new BreadCrumbParameter(parameter, projectAllocation.get().name, getTranslation("view.user-settings.projects.page.details.bread-crumb"));
ResourceAllocationChart resourceAllocationChart = new ResourceAllocationChart(chartPowerService.getChartDataForProjectAlloc(projectAllocation.get().projectId, projectAllocation.get().id), jsonExporter.getJsonForProjectAllocation(projectAllocation.get().projectId, projectAllocation.get().id), csvExporter.getCsvForProjectAllocation(projectAllocation.get().projectId, projectAllocation.get().id), true);
getContent().add(resourceAllocationChart);
}
}
Aggregations