Search in sources :

Example 1 with ValueSourceProvider

use of com.haulmont.cuba.gui.components.data.ValueSourceProvider in project cuba by cuba-platform.

the class FormLoader method loadColumns.

protected void loadColumns(Form resultComponent, Element element) {
    ValueSourceProvider valueSourceProvider = resultComponent.getValueSourceProvider();
    if (element.elements("column").isEmpty()) {
        Iterable<ComponentPosition> rootComponents = loadComponents(element, null, null);
        Iterable<ComponentPosition> dynamicAttributeComponents = loadDynamicAttributeComponents(valueSourceProvider, null);
        for (ComponentPosition component : Iterables.concat(rootComponents, dynamicAttributeComponents)) {
            resultComponent.add(component.getComponent(), 0, component.getColSpan(), component.getRowSpan());
        }
    } else {
        List<Element> columnElements = element.elements("column");
        if (element.elements().size() > columnElements.size()) {
            String fieldGroupId = resultComponent.getId();
            Map<String, Object> params = Strings.isNullOrEmpty(fieldGroupId) ? Collections.emptyMap() : ParamsMap.of("Form ID", fieldGroupId);
            throw new GuiDevelopmentException("Form component elements have to be placed within its column.", context, params);
        }
        resultComponent.setColumns(columnElements.size());
        int colIndex = 0;
        for (Element columnElement : columnElements) {
            String columnWidth = loadThemeString(columnElement.attributeValue("width"));
            String flexAttr = columnElement.attributeValue("flex");
            Float flex = null;
            if (!Strings.isNullOrEmpty(flexAttr)) {
                flex = Float.parseFloat(flexAttr);
                resultComponent.setColumnFlex(colIndex, flex);
            }
            Iterable<ComponentPosition> columnComponents = loadComponents(columnElement, columnWidth, flex);
            if (colIndex == 0) {
                columnComponents = Iterables.concat(columnComponents, loadDynamicAttributeComponents(valueSourceProvider, columnWidth));
            }
            for (ComponentPosition component : columnComponents) {
                resultComponent.add(component.getComponent(), colIndex, component.getColSpan(), component.getRowSpan());
            }
            loadChildrenCaptionAlignment(resultComponent, columnElement, colIndex);
            loadChildrenCaptionWidth(resultComponent, columnElement, colIndex);
            colIndex++;
        }
    }
}
Also used : ValueSourceProvider(com.haulmont.cuba.gui.components.data.ValueSourceProvider) ContainerValueSourceProvider(com.haulmont.cuba.gui.components.data.value.ContainerValueSourceProvider) ComponentPosition(com.haulmont.cuba.gui.components.form.ComponentPosition) Element(org.dom4j.Element) GuiDevelopmentException(com.haulmont.cuba.gui.GuiDevelopmentException)

Aggregations

GuiDevelopmentException (com.haulmont.cuba.gui.GuiDevelopmentException)1 ValueSourceProvider (com.haulmont.cuba.gui.components.data.ValueSourceProvider)1 ContainerValueSourceProvider (com.haulmont.cuba.gui.components.data.value.ContainerValueSourceProvider)1 ComponentPosition (com.haulmont.cuba.gui.components.form.ComponentPosition)1 Element (org.dom4j.Element)1