Search in sources :

Example 1 with FilterHelper

use of com.haulmont.cuba.gui.components.filter.FilterHelper in project cuba by cuba-platform.

the class AddConditionWindow method init.

@Override
public void init(Map<String, Object> params) {
    super.init(params);
    ThemeConstants theme = themeConstantsManager.getConstants();
    getDialogOptions().setHeight(theme.get("cuba.gui.addFilterCondition.dialog.height")).setWidth(theme.get("cuba.gui.addFilterCondition.dialog.width")).setResizable(true);
    conditionDescriptorsDs.refresh(params);
    expandTreeRoots();
    tree.setItemClickAction(new AbstractAction("select") {

        @Override
        public void actionPerform(Component component) {
            select();
        }
    });
    FilterHelper filterHelper = AppBeans.get(FilterHelper.class);
    filterHelper.addTextChangeListener(treeFilter, new FilterHelper.TextChangeListener() {

        @Override
        public void textChanged(String text) {
            _search(text);
        }
    });
    filterHelper.addShortcutListener(treeFilter, new FilterHelper.ShortcutListener("search", new KeyCombination(Key.ENTER)) {

        @Override
        public void handleShortcutPressed() {
            search();
        }
    });
}
Also used : ThemeConstants(com.haulmont.cuba.gui.theme.ThemeConstants) FilterHelper(com.haulmont.cuba.gui.components.filter.FilterHelper)

Example 2 with FilterHelper

use of com.haulmont.cuba.gui.components.filter.FilterHelper in project cuba by cuba-platform.

the class FilterEditor method init.

@Override
public void init(Map<String, Object> params) {
    super.init(params);
    if (Boolean.TRUE.equals(useShortConditionForm)) {
        setCaption(messages.getMainMessage("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("conditions");
    conditions = paramConditions.createCopy();
    refreshConditionsDs();
    conditionsTree.expandTree();
    if (!messages.getMainMessage("filter.adHocFilter").equals(filterEntity.getName())) {
        filterName.setValue(filterEntity.getName());
    }
    availableForAllCb.setValue(filterEntity.getUser() == null);
    defaultCb.setValue(filterEntity.getIsDefault());
    applyDefaultCb.setValue(filterEntity.getApplyDefault());
    globalDefaultCb.setValue(filterEntity.getGlobalDefault());
    if (filterEntity.getUser() != null) {
        globalDefaultCb.setEnabled(false);
    }
    if (!userSessionSource.getUserSession().isSpecificPermitted(GLOBAL_FILTER_PERMISSION)) {
        availableForAllCb.setVisible(false);
        availableForAllLabel.setVisible(false);
        globalDefaultCb.setVisible(false);
        globalDefaultLabel.setVisible(false);
    }
    availableForAllCb.addValueChangeListener(e -> {
        Boolean isFilterAvailableForAll = (Boolean) e.getValue();
        globalDefaultCb.setEnabled(isFilterAvailableForAll);
        if (!isFilterAvailableForAll) {
            globalDefaultCb.setValue(null);
        }
    });
    Configuration configuration = AppBeans.get(Configuration.NAME);
    boolean manualApplyRequired = filter.getManualApplyRequired() != null ? filter.getManualApplyRequired() : configuration.getConfig(ClientConfig.class).getGenericFilterManualApplyRequired();
    if (!manualApplyRequired) {
        applyDefaultCb.setVisible(manualApplyRequired);
        applyDefaultLabel.setVisible(manualApplyRequired);
    }
    if (filterEntity.getFolder() != null) {
        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.getId());
        } 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 : AddConditionHelper(com.haulmont.cuba.gui.components.filter.AddConditionHelper) java.util(java.util) WindowManager(com.haulmont.cuba.gui.WindowManager) Logger(org.slf4j.Logger) FilterEntity(com.haulmont.cuba.security.entity.FilterEntity) LoggerFactory(org.slf4j.LoggerFactory) Collectors(java.util.stream.Collectors) com.haulmont.cuba.core.global(com.haulmont.cuba.core.global) GroupConditionDescriptor(com.haulmont.cuba.gui.components.filter.descriptor.GroupConditionDescriptor) GroupType(com.haulmont.cuba.gui.components.filter.GroupType) BooleanUtils(org.apache.commons.lang.BooleanUtils) Inject(javax.inject.Inject) ConditionsTree(com.haulmont.cuba.gui.components.filter.ConditionsTree) FilterHelper(com.haulmont.cuba.gui.components.filter.FilterHelper) com.haulmont.cuba.gui.components.filter.condition(com.haulmont.cuba.gui.components.filter.condition) WindowParam(com.haulmont.cuba.gui.WindowParam) Node(com.haulmont.bali.datastruct.Node) ThemeConstants(com.haulmont.cuba.gui.theme.ThemeConstants) ClientConfig(com.haulmont.cuba.client.ClientConfig) ComponentsHelper(com.haulmont.cuba.gui.ComponentsHelper) com.haulmont.cuba.gui.components(com.haulmont.cuba.gui.components) Entity(com.haulmont.cuba.core.entity.Entity) Node(com.haulmont.bali.datastruct.Node) AddConditionHelper(com.haulmont.cuba.gui.components.filter.AddConditionHelper) FilterHelper(com.haulmont.cuba.gui.components.filter.FilterHelper) ConditionsTree(com.haulmont.cuba.gui.components.filter.ConditionsTree)

Example 3 with FilterHelper

use of com.haulmont.cuba.gui.components.filter.FilterHelper in project cuba by cuba-platform.

the class FilterSelectWindow method init.

@SuppressWarnings("unchecked")
@Override
public void init(Map<String, Object> params) {
    ThemeConstants theme = themeConstantsManager.getConstants();
    getDialogOptions().setHeight(theme.get("cuba.gui.filterSelect.dialog.height")).setWidth(theme.get("cuba.gui.filterSelect.dialog.width")).setResizable(true);
    filterEntitiesTable.addGeneratedColumn("name", new Table.ColumnGenerator<FilterEntity>() {

        @Override
        public Component generateCell(FilterEntity entity) {
            Label label = componentsFactory.createComponent(Label.class);
            String caption;
            if (Strings.isNullOrEmpty(entity.getCode())) {
                caption = InstanceUtils.getInstanceName(entity);
            } else {
                caption = messages.getMainMessage(entity.getCode());
            }
            label.setValue(caption);
            captionsMap.put(entity, caption);
            return label;
        }
    });
    filterEntities = (List<FilterEntity>) params.get("filterEntities");
    fillDatasource(null);
    filterEntitiesTable.setItemClickAction(new AbstractAction("selectByDblClk") {

        @Override
        public void actionPerform(Component component) {
            select();
        }

        @Override
        public String getCaption() {
            return messages.getMainMessage("filter.filterSelect.select");
        }
    });
    FilterHelper filterHelper = AppBeans.get(FilterHelper.class);
    filterHelper.addTextChangeListener(nameFilterField, new FilterHelper.TextChangeListener() {

        @Override
        public void textChanged(String text) {
            fillDatasource(text);
        }
    });
}
Also used : ThemeConstants(com.haulmont.cuba.gui.theme.ThemeConstants) FilterEntity(com.haulmont.cuba.security.entity.FilterEntity) FilterHelper(com.haulmont.cuba.gui.components.filter.FilterHelper)

Example 4 with FilterHelper

use of com.haulmont.cuba.gui.components.filter.FilterHelper in project cuba by cuba-platform.

the class ConditionFrame method initComponents.

protected void initComponents() {
    required = (CheckBox) getComponent("required");
    hidden = (CheckBox) getComponent("hidden");
    width = (LookupField) getComponent("width");
    if (width != null) {
        List<Integer> widthValues = new ArrayList<>();
        int conditionsColumnsCount = filter != null ? filter.getColumnsCount() : clientConfig.getGenericFilterColumnsCount();
        for (int i = 1; i <= conditionsColumnsCount; i++) {
            widthValues.add(i);
        }
        width.setOptionsList(widthValues);
        FilterHelper filterHelper = AppBeans.get(FilterHelper.class);
        filterHelper.setLookupNullSelectionAllowed(width, false);
    }
}
Also used : ArrayList(java.util.ArrayList) FilterHelper(com.haulmont.cuba.gui.components.filter.FilterHelper)

Aggregations

FilterHelper (com.haulmont.cuba.gui.components.filter.FilterHelper)4 ThemeConstants (com.haulmont.cuba.gui.theme.ThemeConstants)3 FilterEntity (com.haulmont.cuba.security.entity.FilterEntity)2 Node (com.haulmont.bali.datastruct.Node)1 ClientConfig (com.haulmont.cuba.client.ClientConfig)1 Entity (com.haulmont.cuba.core.entity.Entity)1 com.haulmont.cuba.core.global (com.haulmont.cuba.core.global)1 ComponentsHelper (com.haulmont.cuba.gui.ComponentsHelper)1 WindowManager (com.haulmont.cuba.gui.WindowManager)1 WindowParam (com.haulmont.cuba.gui.WindowParam)1 com.haulmont.cuba.gui.components (com.haulmont.cuba.gui.components)1 AddConditionHelper (com.haulmont.cuba.gui.components.filter.AddConditionHelper)1 ConditionsTree (com.haulmont.cuba.gui.components.filter.ConditionsTree)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 java.util (java.util)1 ArrayList (java.util.ArrayList)1 Collectors (java.util.stream.Collectors)1 Inject (javax.inject.Inject)1