Search in sources :

Example 1 with CanvasLayout

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

the class CanvasDropComponentsFactory method addLayoutClickListener.

protected void addLayoutClickListener(CanvasLayout layout) {
    layout.addLayoutClickListener(e -> {
        CanvasLayout selectedLayout = null;
        Component clickedComponent = e.getClickedComponent();
        if (clickedComponent == null) {
            HasComponents source = e.getSource();
            if (source instanceof ComponentContainer) {
                Component parent = ((ComponentContainer) source).getParent();
                if (parent instanceof CanvasLayout) {
                    selectedLayout = (CanvasLayout) parent;
                }
            }
        } else {
            selectedLayout = findCanvasLayout(clickedComponent);
        }
        if (selectedLayout != null) {
            uiEventPublisher.publishEvent(new WidgetSelectedEvent(selectedLayout.getUuid(), WidgetSelectedEvent.Target.CANVAS));
        }
    });
}
Also used : WidgetSelectedEvent(io.jmix.dashboardsui.dashboard.event.WidgetSelectedEvent) CanvasLayout(io.jmix.dashboardsui.component.CanvasLayout) AbstractComponent(com.vaadin.ui.AbstractComponent)

Example 2 with CanvasLayout

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

the class DashboardModelConverter method initChildren.

private void initChildren(CanvasFragment fragment, DashboardLayout model, ComponentContainer delegate) {
    boolean expanded = isExpanded(model);
    if (!model.getChildren().isEmpty()) {
        for (DashboardLayout childModel : model.getChildren()) {
            CanvasLayout childContainer = modelToContainer(fragment, childModel);
            delegate.add(childContainer);
            if (childModel.getId().equals(model.getExpand())) {
                if (delegate instanceof ExpandingLayout) {
                    ((ExpandingLayout) delegate).expand(childContainer);
                }
            }
            if (!expanded) {
                childContainer.setWeight(childModel.getWeight());
            }
        }
    }
}
Also used : ExpandingLayout(io.jmix.ui.component.ExpandingLayout) CanvasLayout(io.jmix.dashboardsui.component.CanvasLayout)

Example 3 with CanvasLayout

use of io.jmix.dashboardsui.component.CanvasLayout 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)3 AbstractComponent (com.vaadin.ui.AbstractComponent)1 CanvasGridLayout (io.jmix.dashboardsui.component.impl.CanvasGridLayout)1 WidgetSelectedEvent (io.jmix.dashboardsui.dashboard.event.WidgetSelectedEvent)1 ComponentContainer (io.jmix.ui.component.ComponentContainer)1 ExpandingLayout (io.jmix.ui.component.ExpandingLayout)1