Search in sources :

Example 11 with ComponentLoader

use of io.jmix.ui.xml.layout.ComponentLoader in project jmix by jmix-framework.

the class GridLayoutLoader method createSubComponents.

protected void createSubComponents(GridLayout gridLayout, Element element, int row) {
    LayoutLoader loader = getLayoutLoader();
    int col = 0;
    for (Element subElement : element.elements()) {
        ComponentLoader componentLoader = loader.createComponent(subElement);
        pendingLoadComponents.add(componentLoader);
        Component subComponent = componentLoader.getResultComponent();
        String colspan = subElement.attributeValue("colspan");
        String rowspan = subElement.attributeValue("rowspan");
        if (col >= spanMatrix.length) {
            Map<String, Object> params = new HashMap<>();
            params.put("Grid ID", gridLayout.getId());
            String rowId = element.attributeValue("id");
            if (StringUtils.isNotEmpty(rowId)) {
                params.put("Row ID", rowId);
            } else {
                params.put("Row Index", row);
            }
            throw new GuiDevelopmentException("Grid column count is less than number of components in grid row", context, params);
        }
        while (spanMatrix[col][row]) {
            col++;
        }
        if (StringUtils.isEmpty(colspan) && StringUtils.isEmpty(rowspan)) {
            addSubComponent(gridLayout, subComponent, col, row, col, row);
        } else {
            int cSpan = 1;
            int rSpan = 1;
            if (StringUtils.isNotEmpty(colspan)) {
                cSpan = Integer.parseInt(colspan);
                if (cSpan < 1) {
                    throw new GuiDevelopmentException("GridLayout colspan can not be less than 1", context, "colspan", cSpan);
                }
                if (cSpan == 1) {
                    LoggerFactory.getLogger(GridLayoutLoader.class).warn("Do not use colspan=\"1\", it will have no effect");
                }
            }
            if (StringUtils.isNotEmpty(rowspan)) {
                rSpan = Integer.parseInt(rowspan);
                if (rSpan < 1) {
                    throw new GuiDevelopmentException("GridLayout rowspan can not be less than 1", context, "rowspan", rSpan);
                }
                if (rSpan == 1) {
                    LoggerFactory.getLogger(GridLayoutLoader.class).warn("Do not use rowspan=\"1\", it will have no effect");
                }
            }
            fillSpanMatrix(col, row, cSpan, rSpan);
            int endColumn = col + cSpan - 1;
            int endRow = row + rSpan - 1;
            addSubComponent(gridLayout, subComponent, col, row, endColumn, endRow);
        }
        col++;
    }
}
Also used : HashMap(java.util.HashMap) Element(org.dom4j.Element) GuiDevelopmentException(io.jmix.ui.GuiDevelopmentException) Component(io.jmix.ui.component.Component) ComponentLoader(io.jmix.ui.xml.layout.ComponentLoader)

Example 12 with ComponentLoader

use of io.jmix.ui.xml.layout.ComponentLoader in project jmix by jmix-framework.

the class LayoutLoader method createComponent.

public ComponentLoader createComponent(Element element) {
    ComponentLoader loader = getLoader(element);
    loader.createComponent();
    return loader;
}
Also used : ComponentLoader(io.jmix.ui.xml.layout.ComponentLoader)

Aggregations

ComponentLoader (io.jmix.ui.xml.layout.ComponentLoader)12 Element (org.dom4j.Element)7 GuiDevelopmentException (io.jmix.ui.GuiDevelopmentException)6 Component (io.jmix.ui.component.Component)5 MetaClass (io.jmix.core.metamodel.model.MetaClass)3 MetaPropertyPath (io.jmix.core.metamodel.model.MetaPropertyPath)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Nullable (javax.annotation.Nullable)2 Strings (com.google.common.base.Strings)1 Iterables (com.google.common.collect.Iterables)1 Security (com.haulmont.cuba.core.global.Security)1 UiComponents (com.haulmont.cuba.gui.UiComponents)1 FieldGroup (com.haulmont.cuba.gui.components.FieldGroup)1 FieldCaptionAlignment (com.haulmont.cuba.gui.components.FieldGroup.FieldCaptionAlignment)1 FieldGroupFieldFactory (com.haulmont.cuba.gui.components.FieldGroupFieldFactory)1 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)1 Datasource (com.haulmont.cuba.gui.data.Datasource)1 DsContext (com.haulmont.cuba.gui.data.DsContext)1 EmbeddedDatasource (com.haulmont.cuba.gui.data.EmbeddedDatasource)1 DynamicAttributesGuiTools (com.haulmont.cuba.gui.dynamicattributes.DynamicAttributesGuiTools)1