Search in sources :

Example 1 with Tree

use of com.haulmont.bali.datastruct.Tree 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 Tree

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

the class ManagedBeanInfoDatasource method loadTree.

@Override
protected Tree<ManagedBeanInfo> loadTree(Map<String, Object> params) {
    String tag = getLoggingTag("TDS");
    StopWatch sw = new Slf4JStopWatch(tag, LoggerFactory.getLogger(UIPerformanceLogger.class));
    List<Node<ManagedBeanInfo>> nodes = new ArrayList<>();
    if (jmxInstance != null) {
        List<ManagedBeanDomain> domains = jmxControlAPI.getDomains(jmxInstance);
        Map<String, Node<ManagedBeanInfo>> domainMap = new HashMap<>();
        for (ManagedBeanDomain mbd : domains) {
            ManagedBeanInfo dummy = metadata.create(ManagedBeanInfo.class);
            dummy.setDomain(mbd.getName());
            Node<ManagedBeanInfo> node = new Node<>(dummy);
            domainMap.put(mbd.getName(), node);
            nodes.add(node);
        }
        List<ManagedBeanInfo> list = loadManagedBeans(params);
        for (ManagedBeanInfo mbi : list) {
            if (mbi != null) {
                if (domainMap.containsKey(mbi.getDomain())) {
                    domainMap.get(mbi.getDomain()).addChild(new Node<>(mbi));
                }
            }
        }
        // remove root nodes that might have left without children after filtering
        for (Node<ManagedBeanInfo> rootNode : new ArrayList<>(nodes)) {
            if (rootNode.getChildren().isEmpty()) {
                nodes.remove(rootNode);
            }
        }
    }
    sw.stop();
    return new Tree<>(nodes);
}
Also used : Slf4JStopWatch(org.perf4j.slf4j.Slf4JStopWatch) UIPerformanceLogger(com.haulmont.cuba.gui.logging.UIPerformanceLogger) Node(com.haulmont.bali.datastruct.Node) ManagedBeanInfo(com.haulmont.cuba.web.jmx.entity.ManagedBeanInfo) ManagedBeanDomain(com.haulmont.cuba.web.jmx.entity.ManagedBeanDomain) Slf4JStopWatch(org.perf4j.slf4j.Slf4JStopWatch) StopWatch(org.perf4j.StopWatch) Tree(com.haulmont.bali.datastruct.Tree)

Example 3 with Tree

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

the class DiffTreeDatasource method loadTree.

@Override
protected Tree<EntityPropertyDiff> loadTree(Map params) {
    Tree<EntityPropertyDiff> diffTree = new Tree<>();
    List<Node<EntityPropertyDiff>> rootNodes = new ArrayList<>();
    if (entityDiff != null) {
        for (EntityPropertyDiff childPropertyDiff : entityDiff.getPropertyDiffs()) {
            Node<EntityPropertyDiff> childPropDiffNode = loadPropertyDiff(childPropertyDiff);
            if (childPropDiffNode != null)
                rootNodes.add(childPropDiffNode);
        }
    }
    diffTree.setRootNodes(rootNodes);
    return diffTree;
}
Also used : Node(com.haulmont.bali.datastruct.Node) ArrayList(java.util.ArrayList) Tree(com.haulmont.bali.datastruct.Tree) EntityPropertyDiff(com.haulmont.cuba.core.entity.diff.EntityPropertyDiff)

Example 4 with Tree

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

the class SpecificPermissionTreeDatasource method filterPermitted.

private Tree<BasicPermissionTarget> filterPermitted(Tree<BasicPermissionTarget> permissions) {
    UserSession session = uss.getUserSession();
    List<Node<BasicPermissionTarget>> newRootNodes = permissions.getRootNodes().stream().map(root -> filterNode(session, root)).filter(// empty nodes
    root -> root.getNumberOfChildren() > 0).collect(Collectors.toCollection(LinkedList::new));
    return new Tree<>(newRootNodes);
}
Also used : UserSession(com.haulmont.cuba.security.global.UserSession) BasicPermissionTarget(com.haulmont.cuba.gui.app.security.entity.BasicPermissionTarget) List(java.util.List) PermissionConfig(com.haulmont.cuba.gui.config.PermissionConfig) Tree(com.haulmont.bali.datastruct.Tree) Node(com.haulmont.bali.datastruct.Node) LinkedList(java.util.LinkedList) AppBeans(com.haulmont.cuba.core.global.AppBeans) UserSessionSource(com.haulmont.cuba.core.global.UserSessionSource) Collectors(java.util.stream.Collectors) UserSession(com.haulmont.cuba.security.global.UserSession) Node(com.haulmont.bali.datastruct.Node) Tree(com.haulmont.bali.datastruct.Tree)

Aggregations

Node (com.haulmont.bali.datastruct.Node)4 Tree (com.haulmont.bali.datastruct.Tree)4 MetaClass (com.haulmont.chile.core.model.MetaClass)1 MetaProperty (com.haulmont.chile.core.model.MetaProperty)1 MetaPropertyPath (com.haulmont.chile.core.model.MetaPropertyPath)1 EntityPropertyDiff (com.haulmont.cuba.core.entity.diff.EntityPropertyDiff)1 AppBeans (com.haulmont.cuba.core.global.AppBeans)1 UserSessionSource (com.haulmont.cuba.core.global.UserSessionSource)1 BasicPermissionTarget (com.haulmont.cuba.gui.app.security.entity.BasicPermissionTarget)1 ConditionsTree (com.haulmont.cuba.gui.components.filter.ConditionsTree)1 PermissionConfig (com.haulmont.cuba.gui.config.PermissionConfig)1 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)1 UIPerformanceLogger (com.haulmont.cuba.gui.logging.UIPerformanceLogger)1 UserSession (com.haulmont.cuba.security.global.UserSession)1 ManagedBeanDomain (com.haulmont.cuba.web.jmx.entity.ManagedBeanDomain)1 ManagedBeanInfo (com.haulmont.cuba.web.jmx.entity.ManagedBeanInfo)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1