Search in sources :

Example 16 with OptionalParameter

use of com.vaadin.flow.router.OptionalParameter in project flow-components by vaadin.

the class GridBenchmark method setParameter.

@Override
public void setParameter(BeforeEvent event, @OptionalParameter String parameter) {
    Location location = event.getLocation();
    QueryParameters queryParameters = location.getQueryParameters();
    Map<String, List<String>> parametersMap = queryParameters.getParameters();
    if (!parametersMap.containsKey("variant") || !parametersMap.containsKey("metric")) {
        add(new Text("Provide query parameters: variant and metric"));
        return;
    }
    String metric = parametersMap.get("metric").get(0);
    String variant = parametersMap.get("variant").get(0);
    LoggerFactory.getLogger(GridBenchmark.class).info("Sample: " + variant + "-" + metric);
    switch(variant) {
        case "simple":
            grid = getGrid();
            addColumns(grid, 5, false);
            break;
        case "multicolumn":
            grid = getGrid();
            addColumns(grid, 50, false);
            break;
        case "componentrenderers":
            grid = getGrid();
            addColumns(grid, 5, true);
            break;
        case "detailsopened":
            grid = getGrid();
            addColumns(grid, 5, false);
            grid.setItemDetailsRenderer(new ComponentRenderer<>(item -> new Text(item.toString())));
            items.forEach(item -> grid.setDetailsVisible(item, true));
            break;
        case "tree":
            grid = getTreeGrid();
            ((TreeGrid<String>) grid).addHierarchyColumn(i -> i);
            addColumns(grid, 5, false);
            break;
        case "mixed":
            grid = getTreeGrid();
            ((TreeGrid<String>) grid).addHierarchyColumn(i -> i);
            addColumns(grid, 50, true);
            grid.setItemDetailsRenderer(new ComponentRenderer<>(item -> new Text(item.toString())));
            treeData.getRootItems().forEach(item -> grid.setDetailsVisible(item, true));
            break;
        default:
            break;
    }
    switch(metric) {
        case "verticalscrollframetime":
            add(grid);
            whenRendered(grid).then(v -> grid.getElement().executeJs("window.measureScrollFrameTime(this, false)"));
            break;
        case "horizontalscrollframetime":
            add(grid);
            whenRendered(grid).then(v -> grid.getElement().executeJs("window.measureScrollFrameTime(this, true)"));
            break;
        case "rendertime":
            measureRendered(grid);
            UI.getCurrent().getElement().executeJs("return window.startWhenReady()").then(v -> add(grid));
            break;
        case "expandtime":
            add(grid);
            startWhenRendered(grid).then(v -> {
                measureRendered(grid);
                TreeGrid<String> treeGrid = (TreeGrid<String>) grid;
                TreeData<String> data = ((TreeDataProvider<String>) treeGrid.getDataProvider()).getTreeData();
                treeGrid.expandRecursively(data.getRootItems(), 5);
            });
            break;
        default:
            break;
    }
}
Also used : IntStream(java.util.stream.IntStream) Text(com.vaadin.flow.component.Text) ComponentRenderer(com.vaadin.flow.data.renderer.ComponentRenderer) Grid(com.vaadin.flow.component.grid.Grid) HasUrlParameter(com.vaadin.flow.router.HasUrlParameter) TreeData(com.vaadin.flow.data.provider.hierarchy.TreeData) LoggerFactory(org.slf4j.LoggerFactory) Div(com.vaadin.flow.component.html.Div) NativeButton(com.vaadin.flow.component.html.NativeButton) Collectors(java.util.stream.Collectors) BeforeEvent(com.vaadin.flow.router.BeforeEvent) TreeGrid(com.vaadin.flow.component.treegrid.TreeGrid) TreeDataProvider(com.vaadin.flow.data.provider.hierarchy.TreeDataProvider) Route(com.vaadin.flow.router.Route) OptionalParameter(com.vaadin.flow.router.OptionalParameter) PendingJavaScriptResult(com.vaadin.flow.component.page.PendingJavaScriptResult) List(java.util.List) Map(java.util.Map) Location(com.vaadin.flow.router.Location) UI(com.vaadin.flow.component.UI) Collections(java.util.Collections) JsModule(com.vaadin.flow.component.dependency.JsModule) QueryParameters(com.vaadin.flow.router.QueryParameters) Text(com.vaadin.flow.component.Text) QueryParameters(com.vaadin.flow.router.QueryParameters) TreeDataProvider(com.vaadin.flow.data.provider.hierarchy.TreeDataProvider) TreeGrid(com.vaadin.flow.component.treegrid.TreeGrid) List(java.util.List) Location(com.vaadin.flow.router.Location)

Aggregations

BeforeEvent (com.vaadin.flow.router.BeforeEvent)16 OptionalParameter (com.vaadin.flow.router.OptionalParameter)16 Route (com.vaadin.flow.router.Route)16 FurmsViewComponent (io.imunity.furms.ui.components.FurmsViewComponent)14 PageTitle (io.imunity.furms.ui.components.PageTitle)14 BreadCrumbParameter (io.imunity.furms.ui.components.layout.BreadCrumbParameter)14 VaadinExceptionHandler.handleExceptions (io.imunity.furms.ui.utils.VaadinExceptionHandler.handleExceptions)14 Optional (java.util.Optional)14 Optional.ofNullable (java.util.Optional.ofNullable)14 Function (java.util.function.Function)13 UI (com.vaadin.flow.component.UI)11 Button (com.vaadin.flow.component.button.Button)11 Key (com.vaadin.flow.component.Key)10 ButtonVariant (com.vaadin.flow.component.button.ButtonVariant)10 BeanValidationBinder (com.vaadin.flow.data.binder.BeanValidationBinder)10 Binder (com.vaadin.flow.data.binder.Binder)10 FormButtons (io.imunity.furms.ui.components.FormButtons)10 ResourceGetter.getCurrentResourceId (io.imunity.furms.ui.utils.ResourceGetter.getCurrentResourceId)8 NotificationUtils.showErrorNotification (io.imunity.furms.ui.utils.NotificationUtils.showErrorNotification)6 DuplicatedNameValidationError (io.imunity.furms.api.validation.exceptions.DuplicatedNameValidationError)5