Search in sources :

Example 1 with CanvasGridLayout

use of io.jmix.dashboardsui.component.impl.CanvasGridLayout in project jmix by jmix-framework.

the class DashboardModelConverter method modelToContainer.

public CanvasLayout modelToContainer(CanvasFragment fragment, DashboardLayout model) {
    CanvasLayout canvasLayout = null;
    if (model instanceof RootLayout) {
        canvasLayout = factory.createCanvasRootLayout((RootLayout) model);
        initChildren(fragment, model, (ComponentContainer) canvasLayout.getDelegate());
    } else if (model instanceof VerticalLayout) {
        canvasLayout = factory.createCanvasVerticalLayout((VerticalLayout) model);
        initChildren(fragment, model, (ComponentContainer) canvasLayout.getDelegate());
    } else if (model instanceof HorizontalLayout) {
        canvasLayout = factory.createCanvasHorizontalLayout((HorizontalLayout) model);
        initChildren(fragment, model, (ComponentContainer) canvasLayout.getDelegate());
    } else if (model instanceof CssLayout) {
        CssLayout cssLayoutModel = (CssLayout) model;
        canvasLayout = factory.createCssLayout(cssLayoutModel);
        initChildren(fragment, model, (ComponentContainer) canvasLayout.getDelegate());
    } else if (model instanceof WidgetLayout) {
        canvasLayout = factory.createCanvasWidgetLayout(fragment, ((WidgetLayout) model));
    } else if (model instanceof GridLayout) {
        GridLayout gridModel = (GridLayout) model;
        canvasLayout = factory.createCanvasGridLayout(gridModel);
        for (GridArea area : gridModel.getAreas()) {
            GridCellLayout cellLayout = area.getComponent();
            CanvasLayout childGridCanvas = modelToContainer(fragment, cellLayout);
            Integer col2 = area.getCol() + cellLayout.getColSpan();
            Integer row2 = area.getRow() + cellLayout.getRowSpan();
            ((CanvasGridLayout) canvasLayout).addComponent(childGridCanvas, area.getCol(), area.getRow(), col2, row2);
        }
    } else if (model instanceof ResponsiveLayout) {
        ResponsiveLayout respLayoutModel = (ResponsiveLayout) model;
        canvasLayout = factory.createCanvasResponsiveLayout(respLayoutModel);
        List<ResponsiveArea> sortedAreas = respLayoutModel.getAreas().stream().sorted(Comparator.comparing(ResponsiveArea::getOrder)).collect(Collectors.toList());
        for (ResponsiveArea area : sortedAreas) {
            DashboardLayout cellLayout = area.getComponent();
            CanvasLayout childGridCanvas = modelToContainer(fragment, cellLayout);
            childGridCanvas.getModel().setParent(respLayoutModel);
            canvasLayout.addComponent(childGridCanvas);
        }
    }
    if (canvasLayout == null) {
        throw new IllegalStateException("Unknown layout class: " + model.getClass());
    }
    if (model.getStyleName() != null) {
        canvasLayout.addStyleName(model.getStyleName());
    }
    canvasLayout.setWidth(model.getWidthWithUnits());
    canvasLayout.setHeight(model.getHeightWithUnits());
    if (model.getId() != null) {
        canvasLayout.setUuid(model.getId());
    }
    return canvasLayout;
}
Also used : CanvasGridLayout(io.jmix.dashboardsui.component.impl.CanvasGridLayout) ComponentContainer(io.jmix.ui.component.ComponentContainer) CanvasLayout(io.jmix.dashboardsui.component.CanvasLayout)

Aggregations

CanvasLayout (io.jmix.dashboardsui.component.CanvasLayout)1 CanvasGridLayout (io.jmix.dashboardsui.component.impl.CanvasGridLayout)1 ComponentContainer (io.jmix.ui.component.ComponentContainer)1