Search in sources :

Example 46 with Component

use of io.jmix.ui.component.Component in project jmix by jmix-framework.

the class FileUploadFieldLoader method loadDropZone.

protected void loadDropZone(UploadField uploadField, Element element) {
    String dropZoneId = element.attributeValue("dropZone");
    if (StringUtils.isNotEmpty(dropZoneId)) {
        Component dropZone = findComponent(dropZoneId);
        if (dropZone instanceof BoxLayout) {
            uploadField.setDropZone(new UploadField.DropZone((BoxLayout) dropZone));
        } else if (dropZone != null) {
            throw new GuiDevelopmentException("Unsupported dropZone class " + dropZone.getClass().getName(), context);
        } else {
            throw new GuiDevelopmentException("Unable to find dropZone component with id: " + dropZoneId, context);
        }
    }
    String dropZonePrompt = element.attributeValue("dropZonePrompt");
    if (StringUtils.isNotEmpty(dropZonePrompt)) {
        uploadField.setDropZonePrompt(loadResourceString(dropZonePrompt));
    }
}
Also used : BoxLayout(io.jmix.ui.component.BoxLayout) SingleFileUploadField(io.jmix.ui.component.SingleFileUploadField) UploadField(io.jmix.ui.component.UploadField) FileUploadField(io.jmix.ui.component.FileUploadField) GuiDevelopmentException(io.jmix.ui.GuiDevelopmentException) Component(io.jmix.ui.component.Component)

Example 47 with Component

use of io.jmix.ui.component.Component in project jmix by jmix-framework.

the class JpqlFilterLoader method createValueComponent.

@SuppressWarnings("rawtypes")
@Override
protected Component createValueComponent(List<Element> elements) {
    return elements.stream().filter(valueComponentElement -> !"condition".equals(valueComponentElement.getName())).map(valueComponentElement -> {
        ComponentLoader valueComponentLoader = getLayoutLoader().createComponent(valueComponentElement);
        valueComponentLoader.loadComponent();
        return valueComponentLoader.getResultComponent();
    }).findFirst().orElseGet(this::generateValueComponent);
}
Also used : GuiDevelopmentException(io.jmix.ui.GuiDevelopmentException) Component(io.jmix.ui.component.Component) HasValue(io.jmix.ui.component.HasValue) MetaClass(io.jmix.core.metamodel.model.MetaClass) List(java.util.List) JpqlFilter(io.jmix.ui.component.JpqlFilter) ComponentLoader(io.jmix.ui.xml.layout.ComponentLoader) JpqlFilterSupport(io.jmix.ui.component.jpqlfilter.JpqlFilterSupport) Element(org.dom4j.Element) ComponentLoader(io.jmix.ui.xml.layout.ComponentLoader)

Example 48 with Component

use of io.jmix.ui.component.Component 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)

Example 49 with Component

use of io.jmix.ui.component.Component in project jmix by jmix-framework.

the class FilterDelegateImpl method createGroupConditionBox.

protected Component createGroupConditionBox(AbstractCondition condition, Node<AbstractCondition> node, ConditionsFocusType conditionsFocusType, boolean focusSet, int level) {
    Component groupCellContent;
    GroupBoxLayout groupBox = uiComponents.create(GroupBoxLayout.class);
    groupBox.setStyleName("conditions-group");
    groupBox.setWidth("100%");
    groupBox.setCaption(condition.getLocCaption());
    if (!node.getChildren().isEmpty()) {
        recursivelyCreateConditionsLayout(conditionsFocusType, focusSet, node.getChildren(), groupBox, level);
    }
    groupCellContent = groupBox;
    return groupCellContent;
}
Also used : GroupBoxLayout(io.jmix.ui.component.GroupBoxLayout) ListComponent(com.haulmont.cuba.gui.components.ListComponent) Component(io.jmix.ui.component.Component)

Example 50 with Component

use of io.jmix.ui.component.Component in project jmix by jmix-framework.

the class FilterDelegateImpl method createParamEditor.

protected ParamEditor createParamEditor(final AbstractCondition condition, FilterDataContext filterDataContext) {
    boolean conditionRemoveEnabled = !initialConditions.contains(condition);
    ParamEditor paramEditor = new ParamEditor(condition, filterDataContext, conditionRemoveEnabled, isParamEditorOperationEditable());
    AbstractAction removeConditionAction = new AbstractAction("") {

        @Override
        public void actionPerform(Component component) {
            conditions.removeCondition(condition);
            fillConditionsLayout(ConditionsFocusType.NONE);
            updateFilterModifiedIndicator();
            applyWithImmediateMode();
        }
    };
    removeConditionAction.setVisible(conditionRemoveEnabled);
    paramEditor.setRemoveButtonAction(removeConditionAction);
    return paramEditor;
}
Also used : ListComponent(com.haulmont.cuba.gui.components.ListComponent) Component(io.jmix.ui.component.Component) AbstractAction(io.jmix.ui.action.AbstractAction)

Aggregations

Component (io.jmix.ui.component.Component)81 GuiDevelopmentException (io.jmix.ui.GuiDevelopmentException)16 Datasource (com.haulmont.cuba.gui.data.Datasource)12 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)11 Test (org.junit.jupiter.api.Test)11 Element (org.dom4j.Element)10 Consumer (java.util.function.Consumer)9 ListComponent (com.haulmont.cuba.gui.components.ListComponent)8 MetaClass (io.jmix.core.metamodel.model.MetaClass)7 Action (io.jmix.ui.action.Action)7 HasValue (io.jmix.ui.component.HasValue)7 FrameOwner (io.jmix.ui.screen.FrameOwner)7 ArrayList (java.util.ArrayList)7 DatasourceImpl (com.haulmont.cuba.gui.data.impl.DatasourceImpl)6 FetchPlan (io.jmix.core.FetchPlan)6 UUID (java.util.UUID)6 Nullable (javax.annotation.Nullable)6 User (com.haulmont.cuba.core.model.common.User)5 DsBuilder (com.haulmont.cuba.gui.data.DsBuilder)5 Entity (io.jmix.core.Entity)5