Search in sources :

Example 1 with ScreenSettingsFacet

use of io.jmix.ui.settings.facet.ScreenSettingsFacet in project jmix by jmix-framework.

the class FilterEditor method init.

@Override
public void init(Map<String, Object> params) {
    super.init(params);
    if (Boolean.TRUE.equals(useShortConditionForm)) {
        setCaption(messages.getMessage("filter.editor.captionShortForm"));
    }
    getDialogOptions().setWidth(theme.get("cuba.gui.filterEditor.dialog.width")).setHeight(theme.get("cuba.gui.filterEditor.dialog.height")).setResizable(true);
    filterEntity = (FilterEntity) params.get("filterEntity");
    if (filterEntity == null) {
        throw new RuntimeException("Filter entity was not passed to filter editor");
    }
    filter = (Filter) params.get("filter");
    ConditionsTree paramConditions = (ConditionsTree) params.get("conditionsTree");
    conditions = paramConditions.createCopy();
    refreshConditionsDs();
    conditionsTree.expandTree();
    MetaProperty property = metadata.getClassNN(FilterEntity.class).getProperty("name");
    Map<String, Object> annotations = property.getAnnotations();
    Integer maxLength = (Integer) annotations.get("length");
    if (maxLength != null) {
        filterName.setMaxLength(maxLength);
    }
    if (!messages.getMessage("filter.adHocFilter").equals(filterEntity.getName())) {
        filterName.setValue(filterEntity.getName());
    }
    availableForAllCb.setValue(filterEntity.getUsername() == null);
    defaultCb.setValue(filterEntity.getIsDefault());
    applyDefaultCb.setValue(filterEntity.getApplyDefault());
    globalDefaultCb.setValue(filterEntity.getGlobalDefault());
    if (filterEntity.getUsername() != null) {
        globalDefaultCb.setEnabled(false);
    }
    if (!security.isSpecificPermitted(GLOBAL_FILTER_PERMISSION)) {
        availableForAllCb.setVisible(false);
        availableForAllLabel.setVisible(false);
        globalDefaultCb.setVisible(false);
        globalDefaultLabel.setVisible(false);
    }
    availableForAllCb.addValueChangeListener(e -> {
        Boolean isFilterAvailableForAll = e.getValue();
        globalDefaultCb.setEnabled(isFilterAvailableForAll);
        if (!isFilterAvailableForAll) {
            globalDefaultCb.setValue(null);
        }
    });
    boolean manualApplyRequired = filter.getManualApplyRequired() != null ? filter.getManualApplyRequired() : AppBeans.get(CubaProperties.class).isGenericFilterManualApplyRequired();
    if (!manualApplyRequired) {
        applyDefaultCb.setVisible(manualApplyRequired);
        applyDefaultLabel.setVisible(manualApplyRequired);
    }
    if (!(filter.getFrame().getFrameOwner() instanceof LegacyFrame)) {
        ScreenSettingsFacet settingsFacet = UiControllerUtils.getFacet(filter.getFrame(), ScreenSettingsFacet.class);
        if (settingsFacet == null) {
            defaultCb.setVisible(false);
            defaultLabel.setVisible(false);
        }
    }
    if (filterEntity.getFolder() != null) {
        availableForAllCb.setVisible(false);
        availableForAllLabel.setVisible(false);
        globalDefaultCb.setVisible(false);
        globalDefaultLabel.setVisible(false);
        defaultCb.setVisible(false);
        defaultLabel.setVisible(false);
    }
    conditionsDs.addItemChangeListener(e -> {
        if (!treeItemChangeListenerEnabled) {
            return;
        }
        // commit previously selected condition
        if (activeConditionFrame != null) {
            List<Validatable> validatables = new ArrayList<>();
            Collection<Component> frameComponents = ComponentsHelper.getComponents(activeConditionFrame);
            for (Component frameComponent : frameComponents) {
                if (frameComponent instanceof Validatable) {
                    validatables.add((Validatable) frameComponent);
                }
            }
            if (validate(validatables)) {
                activeConditionFrame.commit();
            } else {
                treeItemChangeListenerEnabled = false;
                conditionsTree.setSelected(e.getPrevItem());
                treeItemChangeListenerEnabled = true;
                return;
            }
        }
        if (e.getItem() == null) {
            activeConditionFrame = null;
        } else {
            if (e.getItem() instanceof PropertyCondition) {
                activeConditionFrame = propertyConditionFrame;
            } else if (e.getItem() instanceof DynamicAttributesCondition) {
                activeConditionFrame = dynamicAttributesConditionFrame;
            } else if (e.getItem() instanceof CustomCondition) {
                activeConditionFrame = customConditionFrame;
            } else if (e.getItem() instanceof GroupCondition) {
                activeConditionFrame = groupConditionFrame;
            } else if (e.getItem() instanceof FtsCondition) {
                activeConditionFrame = ftsConditionFrame;
            } else {
                log.warn("Conditions frame for condition with type " + e.getItem().getClass().getSimpleName() + " not found");
            }
        }
        propertyConditionFrame.setVisible(false);
        customConditionFrame.setVisible(false);
        dynamicAttributesConditionFrame.setVisible(false);
        groupConditionFrame.setVisible(false);
        ftsConditionFrame.setVisible(false);
        if (activeConditionFrame != null) {
            activeConditionFrame.setVisible(true);
            activeConditionFrame.setCondition(e.getItem());
            if (Boolean.TRUE.equals(useShortConditionForm)) {
                for (String componentName : componentsToHideInShortForm) {
                    Component component = activeConditionFrame.getComponent(componentName);
                    if (component != null) {
                        if (BooleanUtils.isTrue(showConditionHiddenOption) && componentsForHiddenOption.contains(componentName)) {
                            continue;
                        }
                        component.setVisible(false);
                    }
                }
            }
        }
    });
    addConditionHelper = new AddConditionHelper(filter, BooleanUtils.isTrue(hideDynamicAttributes), BooleanUtils.isTrue(hideCustomConditions), condition -> {
        AbstractCondition item = conditionsDs.getItem();
        if (item != null && item instanceof GroupCondition) {
            Node<AbstractCondition> newNode = new Node<>(condition);
            Node<AbstractCondition> selectedNode = conditions.getNode(item);
            selectedNode.addChild(newNode);
            refreshConditionsDs();
            conditionsTree.expand(item);
        } else {
            conditions.getRootNodes().add(new Node<>(condition));
            refreshConditionsDs();
        }
        conditionsTree.setSelected(condition);
    });
    FilterHelper filterHelper = AppBeans.get(FilterHelper.class);
    filterHelper.initConditionsDragAndDrop(conditionsTree, conditions);
    if (Boolean.TRUE.equals(useShortConditionForm)) {
        filterPropertiesGrid.setVisible(false);
    }
}
Also used : Node(io.jmix.core.common.datastruct.Node) AddConditionHelper(com.haulmont.cuba.gui.components.filter.AddConditionHelper) java.util(java.util) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) CubaProperties(com.haulmont.cuba.CubaProperties) BooleanUtils(org.apache.commons.lang3.BooleanUtils) com.haulmont.cuba.core.global(com.haulmont.cuba.core.global) GroupType(com.haulmont.cuba.gui.components.filter.GroupType) AbstractWindow(com.haulmont.cuba.gui.components.AbstractWindow) com.haulmont.cuba.gui.components.filter.condition(com.haulmont.cuba.gui.components.filter.condition) Action(io.jmix.ui.action.Action) Filter(com.haulmont.cuba.gui.components.Filter) DialogAction(io.jmix.ui.action.DialogAction) LegacyFrame(com.haulmont.cuba.gui.screen.compatibility.LegacyFrame) Logger(org.slf4j.Logger) FilterEntity(com.haulmont.cuba.security.entity.FilterEntity) ThemeConstants(io.jmix.ui.theme.ThemeConstants) FetchPlan(io.jmix.core.FetchPlan) Collectors(java.util.stream.Collectors) GroupConditionDescriptor(com.haulmont.cuba.gui.components.filter.descriptor.GroupConditionDescriptor) WindowParam(io.jmix.ui.WindowParam) UiControllerUtils(io.jmix.ui.screen.UiControllerUtils) ScreenSettingsFacet(io.jmix.ui.settings.facet.ScreenSettingsFacet) ConditionsTree(com.haulmont.cuba.gui.components.filter.ConditionsTree) FilterHelper(com.haulmont.cuba.gui.components.filter.FilterHelper) Entity(io.jmix.core.Entity) MetaProperty(io.jmix.core.metamodel.model.MetaProperty) io.jmix.ui.component(io.jmix.ui.component) ScreenSettingsFacet(io.jmix.ui.settings.facet.ScreenSettingsFacet) Node(io.jmix.core.common.datastruct.Node) LegacyFrame(com.haulmont.cuba.gui.screen.compatibility.LegacyFrame) AddConditionHelper(com.haulmont.cuba.gui.components.filter.AddConditionHelper) MetaProperty(io.jmix.core.metamodel.model.MetaProperty) ConditionsTree(com.haulmont.cuba.gui.components.filter.ConditionsTree) FilterEntity(com.haulmont.cuba.security.entity.FilterEntity) FilterHelper(com.haulmont.cuba.gui.components.filter.FilterHelper)

Example 2 with ScreenSettingsFacet

use of io.jmix.ui.settings.facet.ScreenSettingsFacet in project jmix by jmix-framework.

the class FilterDelegateImpl method isScreenSettingsEnabled.

protected boolean isScreenSettingsEnabled() {
    Frame frame = filter.getFrame();
    if (frame == null) {
        return false;
    }
    if (frame.getFrameOwner() instanceof LegacyFrame) {
        return true;
    }
    ScreenSettingsFacet settingsFacet = UiControllerUtils.getFacet(frame, ScreenSettingsFacet.class);
    return settingsFacet != null;
}
Also used : LegacyFrame(com.haulmont.cuba.gui.screen.compatibility.LegacyFrame) Frame(io.jmix.ui.component.Frame) ScreenSettingsFacet(io.jmix.ui.settings.facet.ScreenSettingsFacet) LegacyFrame(com.haulmont.cuba.gui.screen.compatibility.LegacyFrame)

Example 3 with ScreenSettingsFacet

use of io.jmix.ui.settings.facet.ScreenSettingsFacet in project jmix by jmix-framework.

the class FilterDelegateImpl method getDefaultFilterFromScreenSettings.

@Nullable
protected FilterEntity getDefaultFilterFromScreenSettings(List<FilterEntity> filters) {
    if (filter.getFrame() == null || StringUtils.isBlank(filter.getId())) {
        return null;
    }
    ScreenSettingsFacet settingsFacet = UiControllerUtils.getFacet(filter.getFrame(), ScreenSettingsFacet.class);
    if (settingsFacet == null || settingsFacet.getSettings() == null) {
        return null;
    }
    CubaFilterSettings cubaFilterSettings = settingsFacet.getSettings().getSettings(filter.getId(), CubaFilterSettings.class).orElse(null);
    if (cubaFilterSettings == null) {
        return null;
    }
    String settingsDefaultId = cubaFilterSettings.getDefaultFilterId();
    if (StringUtils.isBlank(settingsDefaultId)) {
        return null;
    }
    UUID defaultId = null;
    try {
        defaultId = UUID.fromString(settingsDefaultId);
    } catch (IllegalArgumentException ex) {
    // do nothing
    }
    if (defaultId != null) {
        for (FilterEntity filter : filters) {
            if (defaultId.equals(filter.getId())) {
                filter.setIsDefault(true);
                filter.setApplyDefault(cubaFilterSettings.getApplyDefault());
                return filter;
            }
        }
    }
    return null;
}
Also used : ScreenSettingsFacet(io.jmix.ui.settings.facet.ScreenSettingsFacet) FilterEntity(com.haulmont.cuba.security.entity.FilterEntity) CubaFilterSettings(com.haulmont.cuba.settings.component.CubaFilterSettings) Nullable(javax.annotation.Nullable)

Example 4 with ScreenSettingsFacet

use of io.jmix.ui.settings.facet.ScreenSettingsFacet in project jmix by jmix-framework.

the class FilterMakeDefaultAction method execute.

@Override
public void execute() {
    if (filter.getFrame() == null) {
        throw new IllegalStateException("Filter component is not attached to the Frame");
    }
    ScreenSettingsFacet screenSettingsFacet = UiControllerUtils.getFacet(filter.getFrame(), ScreenSettingsFacet.class);
    if (screenSettingsFacet == null) {
        throw new IllegalStateException("The Frame does no contain ScreenSettingsFacet");
    }
    ScreenSettings settings = screenSettingsFacet.getSettings();
    if (settings == null) {
        throw new IllegalStateException("ScreenSettingsFacet is not attached to the frame");
    }
    FilterSettings filterSettings = new FilterSettings();
    filterSettings.setId(filter.getId());
    filterSettings.setDefaultConfigurationId(filter.getCurrentConfiguration().getId());
    settings.put(filterSettings);
}
Also used : ScreenSettingsFacet(io.jmix.ui.settings.facet.ScreenSettingsFacet) ScreenSettings(io.jmix.ui.settings.ScreenSettings) FilterSettings(io.jmix.ui.settings.component.FilterSettings)

Example 5 with ScreenSettingsFacet

use of io.jmix.ui.settings.facet.ScreenSettingsFacet in project jmix by jmix-framework.

the class UiDataFilterSupport method isDefaultForMeFieldVisible.

protected boolean isDefaultForMeFieldVisible(Filter.Configuration currentConfiguration, FilterConfiguration configurationModel) {
    Frame filterFrame = currentConfiguration.getOwner().getFrame();
    if (currentConfiguration.getOwner().getId() != null && filterFrame != null) {
        ScreenSettingsFacet settingsFacet = UiControllerUtils.getFacet(filterFrame, ScreenSettingsFacet.class);
        if (settingsFacet != null) {
            ScreenSettings settings = settingsFacet.getSettings();
            if (settings != null) {
                settings.getSettings(currentConfiguration.getOwner().getId(), FilterSettings.class).ifPresent(filterSettings -> {
                    String defaultConfigurationId = filterSettings.getDefaultConfigurationId();
                    if (defaultConfigurationId != null) {
                        boolean defaultForMe = defaultConfigurationId.equals(configurationModel.getConfigurationId());
                        configurationModel.setDefaultForMe(defaultForMe);
                    }
                });
            }
            return true;
        }
    }
    return false;
}
Also used : Frame(io.jmix.ui.component.Frame) ScreenSettingsFacet(io.jmix.ui.settings.facet.ScreenSettingsFacet) ScreenSettings(io.jmix.ui.settings.ScreenSettings) FilterSettings(io.jmix.ui.settings.component.FilterSettings)

Aggregations

ScreenSettingsFacet (io.jmix.ui.settings.facet.ScreenSettingsFacet)6 LegacyFrame (com.haulmont.cuba.gui.screen.compatibility.LegacyFrame)2 FilterEntity (com.haulmont.cuba.security.entity.FilterEntity)2 Frame (io.jmix.ui.component.Frame)2 ScreenSettings (io.jmix.ui.settings.ScreenSettings)2 FilterSettings (io.jmix.ui.settings.component.FilterSettings)2 CubaProperties (com.haulmont.cuba.CubaProperties)1 com.haulmont.cuba.core.global (com.haulmont.cuba.core.global)1 AbstractWindow (com.haulmont.cuba.gui.components.AbstractWindow)1 Filter (com.haulmont.cuba.gui.components.Filter)1 AddConditionHelper (com.haulmont.cuba.gui.components.filter.AddConditionHelper)1 ConditionsTree (com.haulmont.cuba.gui.components.filter.ConditionsTree)1 FilterHelper (com.haulmont.cuba.gui.components.filter.FilterHelper)1 GroupType (com.haulmont.cuba.gui.components.filter.GroupType)1 com.haulmont.cuba.gui.components.filter.condition (com.haulmont.cuba.gui.components.filter.condition)1 GroupConditionDescriptor (com.haulmont.cuba.gui.components.filter.descriptor.GroupConditionDescriptor)1 CubaFilterSettings (com.haulmont.cuba.settings.component.CubaFilterSettings)1 Entity (io.jmix.core.Entity)1 FetchPlan (io.jmix.core.FetchPlan)1 Node (io.jmix.core.common.datastruct.Node)1