Search in sources :

Example 1 with GridLayout

use of com.haulmont.cuba.gui.components.GridLayout in project jmix by jmix-framework.

the class FilterDelegateImpl method recursivelyCreateConditionsLayout.

protected void recursivelyCreateConditionsLayout(ConditionsFocusType conditionsFocusType, boolean initialFocusSet, List<Node<AbstractCondition>> nodes, ComponentContainer parentContainer, int level) {
    FilterDataContext filterDataContext = new FilterDataContext(filter.getFrame());
    List<Node<AbstractCondition>> visibleConditionNodes = fetchVisibleNodes(nodes);
    if (visibleConditionNodes.isEmpty()) {
        if (level == 0)
            controlsLayout.setStyleName("filter-control-no-border");
        return;
    }
    // note that this is not grid columns count, but number of conditions (label cell + value cell) in one row
    int conditionsCount = getColumnsCount();
    int row = 0;
    int nextColumnStart = 0;
    GridLayout grid = uiComponents.create(GridLayout.class);
    grid.setStyleName("conditions-grid");
    grid.setColumns(conditionsCount * 2);
    // set expand ratio only for cells with param edit components
    for (int i = 0; i < conditionsCount; i++) {
        grid.setColumnExpandRatio(i * 2 + 1, 1);
    }
    grid.setRows(1);
    grid.setSpacing(true);
    grid.setWidth("100%");
    ParamEditor firstParamEditor = null;
    ParamEditor lastParamEditor = null;
    boolean currentFocusSet = initialFocusSet;
    RuntimeException entityParamInformationException = null;
    for (int i = 0; i < visibleConditionNodes.size(); i++) {
        Node<AbstractCondition> node = visibleConditionNodes.get(i);
        final AbstractCondition condition = node.getData();
        BoxLayout labelAndOperationCellContent = null;
        Component paramEditComponentCellContent = null;
        Component groupCellContent = null;
        if (condition.isGroup()) {
            groupCellContent = createGroupConditionBox(condition, node, conditionsFocusType, currentFocusSet, level);
            level++;
        } else {
            if (condition.getParam().getJavaClass() != null) {
                Pair<ParamEditor, RuntimeException> pair = createParamEditorWithChecks(condition, filterDataContext);
                ParamEditor paramEditor = pair.getFirst();
                addParamEditor(condition, paramEditor);
                if (pair.getSecond() != null) {
                    entityParamInformationException = pair.getSecond();
                }
                if (firstParamEditor == null)
                    firstParamEditor = paramEditor;
                lastParamEditor = paramEditor;
                currentFocusSet = true;
                labelAndOperationCellContent = paramEditor.getLabelAndOperationLayout();
                paramEditComponentCellContent = paramEditor.getParamEditComponentLayout();
            } else {
                BoxLayout paramLayout = uiComponents.create(HBoxLayout.class);
                paramLayout.setSpacing(true);
                paramLayout.setMargin(false);
                labelAndOperationCellContent = paramLayout;
            }
        }
        // groupBox for group conditions must occupy the whole line in conditions grid
        Integer conditionWidth = condition.isGroup() ? (Integer) conditionsCount : condition.getWidth();
        int nextColumnEnd = nextColumnStart + conditionWidth - 1;
        if (nextColumnEnd >= conditionsCount) {
            // complete current row in grid with gaps if next cell will be on next row
            completeGridRowWithGaps(grid, row, nextColumnStart, false);
            // place cell to next row in grid
            nextColumnStart = 0;
            nextColumnEnd = conditionWidth - 1;
            row++;
            grid.setRows(row + 1);
        }
        if (groupCellContent != null) {
            grid.add(groupCellContent, nextColumnStart * 2, row, nextColumnEnd * 2 + 1, row);
        }
        if (labelAndOperationCellContent != null) {
            labelAndOperationCellContent.addStyleName("param-label-layout");
            grid.add(labelAndOperationCellContent, nextColumnStart * 2, row, nextColumnStart * 2, row);
            if (nextColumnStart != 0)
                labelAndOperationCellContent.setMargin(false, false, false, true);
        }
        if (paramEditComponentCellContent != null) {
            paramEditComponentCellContent.addStyleName("param-field-layout");
            if (condition.getParam().getType() == Param.Type.UNARY) {
                paramEditComponentCellContent.addStyleName("unary-param-type");
            }
            grid.add(paramEditComponentCellContent, nextColumnStart * 2 + 1, row, nextColumnEnd * 2 + 1, row);
        }
        nextColumnStart = nextColumnEnd + 1;
        // add next row if necessary
        if (i < visibleConditionNodes.size() - 1) {
            if (nextColumnStart >= conditionsCount) {
                nextColumnStart = 0;
                row++;
                grid.setRows(row + 1);
            }
        }
    }
    filterDataContext.loadAll();
    if (!initialFocusSet) {
        switch(conditionsFocusType) {
            case FIRST:
                if (firstParamEditor != null) {
                    paramEditComponentToFocus = firstParamEditor;
                }
                break;
            case LAST:
                if (lastParamEditor != null) {
                    paramEditComponentToFocus = lastParamEditor;
                }
                break;
            default:
                // no action
                break;
        }
    }
    // complete last row in grid with gaps
    completeGridRowWithGaps(grid, row, nextColumnStart, true);
    if (parentContainer != null) {
        parentContainer.add(grid);
    }
    if (level == 0)
        controlsLayout.setStyleName(getControlsLayoutStyleName());
    if (entityParamInformationException != null) {
        getDialogs().createExceptionDialog().withThrowable(entityParamInformationException).show();
    }
}
Also used : Node(io.jmix.core.common.datastruct.Node) BoxLayout(io.jmix.ui.component.BoxLayout) HBoxLayout(io.jmix.ui.component.HBoxLayout) GroupBoxLayout(io.jmix.ui.component.GroupBoxLayout) VBoxLayout(io.jmix.ui.component.VBoxLayout) GridLayout(com.haulmont.cuba.gui.components.GridLayout) ListComponent(com.haulmont.cuba.gui.components.ListComponent) Component(io.jmix.ui.component.Component) AbstractCondition(com.haulmont.cuba.gui.components.filter.condition.AbstractCondition)

Aggregations

GridLayout (com.haulmont.cuba.gui.components.GridLayout)1 ListComponent (com.haulmont.cuba.gui.components.ListComponent)1 AbstractCondition (com.haulmont.cuba.gui.components.filter.condition.AbstractCondition)1 Node (io.jmix.core.common.datastruct.Node)1 BoxLayout (io.jmix.ui.component.BoxLayout)1 Component (io.jmix.ui.component.Component)1 GroupBoxLayout (io.jmix.ui.component.GroupBoxLayout)1 HBoxLayout (io.jmix.ui.component.HBoxLayout)1 VBoxLayout (io.jmix.ui.component.VBoxLayout)1