Search in sources :

Example 1 with Node

use of com.haulmont.bali.datastruct.Node in project cuba by cuba-platform.

the class ConditionDescriptorsTreeBuilder method build.

@Override
public Tree<AbstractConditionDescriptor> build() {
    Messages messages = AppBeans.get(Messages.class);
    String messagesPack = filter.getFrame().getMessagesPack();
    CollectionDatasource datasource = filter.getDatasource();
    Tree<AbstractConditionDescriptor> tree = new Tree<>();
    List<AbstractConditionDescriptor> propertyDescriptors = new ArrayList<>();
    List<AbstractConditionDescriptor> customDescriptors = new ArrayList<>();
    boolean propertiesExplicitlyDefined = false;
    if (filter.getXmlDescriptor() != null) {
        for (Element element : Dom4j.elements(filter.getXmlDescriptor())) {
            AbstractConditionDescriptor conditionDescriptor;
            if ("properties".equals(element.getName())) {
                addMultiplePropertyDescriptors(element, propertyDescriptors, filter);
                propertiesExplicitlyDefined = true;
            } else if ("property".equals(element.getName())) {
                conditionDescriptor = new PropertyConditionDescriptor(element, messagesPack, filterComponentName, datasource);
                propertyDescriptors.add(conditionDescriptor);
                propertiesExplicitlyDefined = true;
            } else if ("custom".equals(element.getName())) {
                conditionDescriptor = new CustomConditionDescriptor(element, messagesPack, filterComponentName, datasource);
                customDescriptors.add(conditionDescriptor);
                propertiesExplicitlyDefined = true;
            } else {
                throw new UnsupportedOperationException("Element not supported: " + element.getName());
            }
        }
    }
    if (!propertiesExplicitlyDefined) {
        addMultiplePropertyDescriptors(".*", "", propertyDescriptors, filter);
    }
    propertyDescriptors.sort(new ConditionDescriptorComparator());
    customDescriptors.sort(new ConditionDescriptorComparator());
    HeaderConditionDescriptor propertyHeaderDescriptor = new HeaderConditionDescriptor("propertyConditions", messages.getMainMessage("filter.addCondition.propertyConditions"), filterComponentName, datasource);
    HeaderConditionDescriptor customHeaderDescriptor = new HeaderConditionDescriptor("customConditions", messages.getMainMessage("filter.addCondition.customConditions"), filterComponentName, datasource);
    Node<AbstractConditionDescriptor> propertyHeaderNode = new Node<>(propertyHeaderDescriptor);
    Node<AbstractConditionDescriptor> customHeaderNode = new Node<>(customHeaderDescriptor);
    int currentDepth = 0;
    for (AbstractConditionDescriptor propertyDescriptor : propertyDescriptors) {
        MetaClass propertyDsMetaClass = propertyDescriptor.getDatasourceMetaClass();
        MetaPropertyPath propertyPath = propertyDsMetaClass.getPropertyPath(propertyDescriptor.getName());
        if (propertyPath == null) {
            log.error("Property path for {} of metaClass {} not found", propertyDescriptor.getName(), propertyDsMetaClass.getName());
            continue;
        }
        MetaProperty metaProperty = propertyPath.getMetaProperty();
        MetaClass propertyEnclosingMetaClass = metadataTools.getPropertyEnclosingMetaClass(propertyPath);
        if (isPropertyAllowed(propertyEnclosingMetaClass, metaProperty) && !excludedProperties.contains(metaProperty.getName())) {
            Node<AbstractConditionDescriptor> node = new Node<>(propertyDescriptor);
            propertyHeaderNode.addChild(node);
            if (currentDepth < hierarchyDepth) {
                recursivelyFillPropertyDescriptors(node, currentDepth);
            }
        }
    }
    for (AbstractConditionDescriptor customDescriptor : customDescriptors) {
        Node<AbstractConditionDescriptor> node = new Node<>(customDescriptor);
        customHeaderNode.addChild(node);
    }
    List<Node<AbstractConditionDescriptor>> rootNodes = new ArrayList<>();
    rootNodes.add(propertyHeaderNode);
    if (!customDescriptors.isEmpty())
        rootNodes.add(customHeaderNode);
    if (!hideCustomConditions && security.isSpecificPermitted(CUSTOM_CONDITIONS_PERMISSION)) {
        rootNodes.add(new Node<>(new CustomConditionCreator(filterComponentName, datasource)));
    }
    if (!hideDynamicAttributes && !dynamicAttributes.getAttributesForMetaClass(datasource.getMetaClass()).isEmpty()) {
        rootNodes.add(new Node<>(new DynamicAttributesConditionCreator(filterComponentName, datasource, "")));
    }
    if (FtsConfigHelper.getEnabled()) {
        rootNodes.add(new Node<>(new FtsConditionDescriptor(filterComponentName, datasource)));
    }
    tree.setRootNodes(rootNodes);
    return tree;
}
Also used : CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) Element(org.dom4j.Element) Node(com.haulmont.bali.datastruct.Node) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath) ConditionsTree(com.haulmont.cuba.gui.components.filter.ConditionsTree) Tree(com.haulmont.bali.datastruct.Tree) MetaProperty(com.haulmont.chile.core.model.MetaProperty) MetaClass(com.haulmont.chile.core.model.MetaClass)

Example 2 with Node

use of com.haulmont.bali.datastruct.Node in project cuba by cuba-platform.

the class ConditionDescriptorsTreeBuilder method recursivelyFillPropertyDescriptors.

protected void recursivelyFillPropertyDescriptors(Node<AbstractConditionDescriptor> parentNode, int currentDepth) {
    currentDepth++;
    List<AbstractConditionDescriptor> descriptors = new ArrayList<>();
    MetaClass filterMetaClass = filter.getDatasource().getMetaClass();
    String propertyId = parentNode.getData().getName();
    MetaPropertyPath mpp = filterMetaClass.getPropertyPath(propertyId);
    if (mpp == null) {
        throw new RuntimeException("Unable to find property " + propertyId);
    }
    MetaProperty metaProperty = mpp.getMetaProperty();
    if (metaProperty.getRange().isClass() && (metadataTools.getCrossDataStoreReferenceIdProperty(storeName, metaProperty) == null)) {
        MetaClass childMetaClass = metaProperty.getRange().asClass();
        for (MetaProperty property : childMetaClass.getProperties()) {
            if (isPropertyAllowed(childMetaClass, property)) {
                String propertyPath = mpp.toString() + "." + property.getName();
                if (excludedProperties.contains(propertyPath))
                    continue;
                PropertyConditionDescriptor childPropertyConditionDescriptor = new PropertyConditionDescriptor(propertyPath, null, filter.getFrame().getMessagesPack(), filterComponentName, filter.getDatasource());
                descriptors.add(childPropertyConditionDescriptor);
            }
        }
    }
    descriptors.sort(new ConditionDescriptorComparator());
    for (AbstractConditionDescriptor descriptor : descriptors) {
        Node<AbstractConditionDescriptor> newNode = new Node<>(descriptor);
        parentNode.addChild(newNode);
        if (currentDepth < hierarchyDepth) {
            recursivelyFillPropertyDescriptors(newNode, currentDepth);
        }
    }
    if (metaProperty.getRange().isClass()) {
        MetaClass childMetaClass = metaProperty.getRange().asClass();
        if (!dynamicAttributes.getAttributesForMetaClass(childMetaClass).isEmpty()) {
            DynamicAttributesConditionCreator descriptor = new DynamicAttributesConditionCreator(filterComponentName, filter.getDatasource(), propertyId);
            Node<AbstractConditionDescriptor> newNode = new Node<>(descriptor);
            parentNode.addChild(newNode);
        }
    }
}
Also used : Node(com.haulmont.bali.datastruct.Node) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath) MetaClass(com.haulmont.chile.core.model.MetaClass) MetaProperty(com.haulmont.chile.core.model.MetaProperty)

Example 3 with Node

use of com.haulmont.bali.datastruct.Node 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 4 with Node

use of com.haulmont.bali.datastruct.Node in project cuba by cuba-platform.

the class FilterEditor method addGroup.

protected void addGroup(GroupType groupType) {
    GroupConditionDescriptor conditionDescriptor = new GroupConditionDescriptor(groupType, filter.getId(), filter.getDatasource());
    AbstractCondition condition = conditionDescriptor.createCondition();
    AbstractCondition selectedCondition = conditionsDs.getItem();
    Node<AbstractCondition> newNode = new Node<>(condition);
    if (selectedCondition != null && selectedCondition instanceof GroupCondition) {
        Node<AbstractCondition> node = conditions.getNode(selectedCondition);
        if (node != null) {
            node.addChild(newNode);
            conditionsTree.expand(selectedCondition.getId());
        }
    } else {
        conditions.getRootNodes().add(newNode);
    }
    refreshConditionsDs();
    conditionsTree.setSelected(condition);
}
Also used : Node(com.haulmont.bali.datastruct.Node) GroupConditionDescriptor(com.haulmont.cuba.gui.components.filter.descriptor.GroupConditionDescriptor)

Example 5 with Node

use of com.haulmont.bali.datastruct.Node in project cuba by cuba-platform.

the class AbstractTreeDatasource method loadData.

@Override
protected void loadData(Map<String, Object> params) {
    String tag = getLoggingTag("TDS");
    StopWatch sw = new Slf4JStopWatch(tag, LoggerFactory.getLogger(UIPerformanceLogger.class));
    clear();
    this.tree = loadTree(params);
    Map<K, Node<T>> targetNodes = new HashMap<>();
    if (tree != null) {
        for (Node<T> node : tree.toList()) {
            final T entity = node.getData();
            final K id = entity.getId();
            data.put(id, entity);
            attachListener(entity);
            targetNodes.put(id, node);
        }
    }
    this.nodes = targetNodes;
    sw.stop();
}
Also used : Slf4JStopWatch(org.perf4j.slf4j.Slf4JStopWatch) UIPerformanceLogger(com.haulmont.cuba.gui.logging.UIPerformanceLogger) Node(com.haulmont.bali.datastruct.Node) StopWatch(org.perf4j.StopWatch) Slf4JStopWatch(org.perf4j.slf4j.Slf4JStopWatch)

Aggregations

Node (com.haulmont.bali.datastruct.Node)17 ConditionsTree (com.haulmont.cuba.gui.components.filter.ConditionsTree)5 AbstractCondition (com.haulmont.cuba.gui.components.filter.condition.AbstractCondition)5 Tree (com.haulmont.bali.datastruct.Tree)4 MetaClass (com.haulmont.chile.core.model.MetaClass)3 ArrayList (java.util.ArrayList)3 MetaProperty (com.haulmont.chile.core.model.MetaProperty)2 MetaPropertyPath (com.haulmont.chile.core.model.MetaPropertyPath)2 EntityPropertyDiff (com.haulmont.cuba.core.entity.diff.EntityPropertyDiff)2 BasicPermissionTarget (com.haulmont.cuba.gui.app.security.entity.BasicPermissionTarget)2 GroupCondition (com.haulmont.cuba.gui.components.filter.condition.GroupCondition)2 GroupConditionDescriptor (com.haulmont.cuba.gui.components.filter.descriptor.GroupConditionDescriptor)2 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)2 UIPerformanceLogger (com.haulmont.cuba.gui.logging.UIPerformanceLogger)2 Collectors (java.util.stream.Collectors)2 Element (org.dom4j.Element)2 StopWatch (org.perf4j.StopWatch)2 Slf4JStopWatch (org.perf4j.slf4j.Slf4JStopWatch)2 ClientConfig (com.haulmont.cuba.client.ClientConfig)1 Entity (com.haulmont.cuba.core.entity.Entity)1