Search in sources :

Example 1 with EntityTreeNode

use of io.jmix.reports.entity.wizard.EntityTreeNode in project jmix by jmix-framework.

the class EntityTreeModelBuilder method buildEntityTree.

public EntityTree buildEntityTree(MetaClass metaClass) {
    EntityTreeStructureInfo entityTreeStructureInfo = new EntityTreeStructureInfo();
    EntityTreeNode root = createRootNode(metaClass);
    fillChildNodes(root, 1, new HashSet<>(), entityTreeStructureInfo);
    return new EntityTree(root, entityTreeStructureInfo);
}
Also used : EntityTreeNode(io.jmix.reports.entity.wizard.EntityTreeNode) EntityTreeStructureInfo(io.jmix.reports.app.EntityTreeStructureInfo) EntityTree(io.jmix.reports.app.EntityTree)

Example 2 with EntityTreeNode

use of io.jmix.reports.entity.wizard.EntityTreeNode in project jmix by jmix-framework.

the class EntityTreeModelBuilder method createRootNode.

protected EntityTreeNode createRootNode(MetaClass metaClass) {
    EntityTreeNode root = metadata.create(EntityTreeNode.class);
    root.setName(metaClass.getName());
    root.setEntityClassName(metaClass.getJavaClass().getSimpleName());
    root.setLocalizedName(StringUtils.defaultIfEmpty(messageTools.getEntityCaption(metaClass), metaClass.getName()));
    root.setMetaClassName(metaClass.getName());
    return root;
}
Also used : EntityTreeNode(io.jmix.reports.entity.wizard.EntityTreeNode)

Example 3 with EntityTreeNode

use of io.jmix.reports.entity.wizard.EntityTreeNode in project jmix by jmix-framework.

the class EntityTreeModelBuilder method fillChildNodes.

protected void fillChildNodes(final EntityTreeNode parentNode, int depth, final Set<String> alreadyAddedMetaProps, final EntityTreeStructureInfo treeStructureInfo) {
    if (depth > getEntityTreeModelMaxDepth()) {
        return;
    }
    MetaClass parentMetaClass = metadata.getClass(parentNode.getMetaClassName());
    for (MetaProperty metaProperty : parentMetaClass.getProperties()) {
        if (!reportsWizard.isPropertyAllowedForReportWizard(parentMetaClass, metaProperty)) {
            continue;
        }
        if (metaProperty.getRange().isClass()) {
            MetaClass propertyMetaClass = metaProperty.getRange().asClass();
            MetaClass effectiveMetaClass = extendedEntities.getEffectiveMetaClass(propertyMetaClass);
            if (!metadataTools.isSystemLevel(effectiveMetaClass) && !metadataTools.isSystemLevel(metaProperty)) {
                int newDepth = depth + 1;
                EntityTreeNode childNode = createEntityTreeNode(metaProperty, parentNode, parentMetaClass, effectiveMetaClass);
                if (alreadyAddedMetaProps.contains(getTreeNodeInfo(parentNode) + "|" + getTreeNodeInfo(childNode))) {
                    // avoid parent-child-parent-... infinite loops
                    continue;
                }
                alreadyAddedMetaProps.add(getTreeNodeInfo(childNode) + "|" + getTreeNodeInfo(parentNode));
                if (!treeStructureInfo.isEntityTreeRootHasCollections() && isMany(metaProperty) && depth == 1) {
                    treeStructureInfo.setEntityTreeRootHasCollections(true);
                }
                fillChildNodes(childNode, newDepth, alreadyAddedMetaProps, treeStructureInfo);
                parentNode.getChildren().add(childNode);
            }
        } else {
            if (!treeStructureInfo.isEntityTreeHasSimpleAttrs()) {
                treeStructureInfo.setEntityTreeHasSimpleAttrs(true);
            }
            EntityTreeNode child = createEntityTreeNode(metaProperty, parentNode, parentMetaClass, null);
            parentNode.getChildren().add(child);
        }
    }
}
Also used : MetaClass(io.jmix.core.metamodel.model.MetaClass) EntityTreeNode(io.jmix.reports.entity.wizard.EntityTreeNode) MetaProperty(io.jmix.core.metamodel.model.MetaProperty)

Example 4 with EntityTreeNode

use of io.jmix.reports.entity.wizard.EntityTreeNode in project jmix by jmix-framework.

the class EntityTreeModelBuilder method createEntityTreeNode.

protected EntityTreeNode createEntityTreeNode(MetaProperty metaProperty, EntityTreeNode parent, MetaClass parentMetaClass, @Nullable MetaClass propertyMetaClass) {
    EntityTreeNode node = metadata.create(EntityTreeNode.class);
    node.setName(metaProperty.getName());
    node.setLocalizedName(StringUtils.defaultIfEmpty(messageTools.getPropertyCaption(parentMetaClass, metaProperty.getName()), metaProperty.getName()));
    if (propertyMetaClass != null) {
        node.setMetaClassName(propertyMetaClass.getName());
        node.setEntityClassName(propertyMetaClass.getJavaClass().getSimpleName());
    }
    node.setMetaPropertyName(metaProperty.getName());
    node.setParent(parent);
    return node;
}
Also used : EntityTreeNode(io.jmix.reports.entity.wizard.EntityTreeNode)

Example 5 with EntityTreeNode

use of io.jmix.reports.entity.wizard.EntityTreeNode in project jmix by jmix-framework.

the class RegionEditor method addProperty.

protected void addProperty() {
    @SuppressWarnings("unchecked") List<EntityTreeNode> nodesList = CollectionUtils.transform(reportRegionPropertiesTableDc.getItems(), o -> ((RegionProperty) o).getEntityTreeNode());
    Set<EntityTreeNode> alreadyAddedNodes = new HashSet<>(nodesList);
    Set<EntityTreeNode> selectedItems = entityTree.getSelected();
    List<RegionProperty> addedItems = new ArrayList<>();
    boolean alreadyAdded = false;
    for (EntityTreeNode entityTreeNode : selectedItems) {
        if (entityTreeNode.getMetaClassName() != null) {
            continue;
        }
        if (!alreadyAddedNodes.contains(entityTreeNode)) {
            RegionProperty regionProperty = metadata.create(RegionProperty.class);
            regionProperty.setEntityTreeNode(entityTreeNode);
            // first element must be not zero cause later we do sorting by multiplying that values
            regionProperty.setOrderNum((long) reportRegionPropertiesTableDc.getItems().size() + 1);
            reportRegionPropertiesTableDc.getMutableItems().add(regionProperty);
            addedItems.add(regionProperty);
        } else {
            alreadyAdded = true;
        }
    }
    if (addedItems.isEmpty()) {
        if (alreadyAdded) {
            notifications.create(Notifications.NotificationType.TRAY).withCaption(messages.getMessage(getClass(), "elementsAlreadyAdded")).show();
        } else if (selectedItems.size() != 0) {
            notifications.create(Notifications.NotificationType.HUMANIZED).withCaption(messages.getMessage(getClass(), "selectPropertyFromEntity")).show();
        } else {
            notifications.create(Notifications.NotificationType.TRAY).withCaption(messages.getMessage(getClass(), "elementsWasNotAdded")).show();
        }
    } else {
        propertiesTable.setSelected(addedItems);
    }
}
Also used : RegionProperty(io.jmix.reports.entity.wizard.RegionProperty) EntityTreeNode(io.jmix.reports.entity.wizard.EntityTreeNode) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Aggregations

EntityTreeNode (io.jmix.reports.entity.wizard.EntityTreeNode)5 MetaClass (io.jmix.core.metamodel.model.MetaClass)1 MetaProperty (io.jmix.core.metamodel.model.MetaProperty)1 EntityTree (io.jmix.reports.app.EntityTree)1 EntityTreeStructureInfo (io.jmix.reports.app.EntityTreeStructureInfo)1 RegionProperty (io.jmix.reports.entity.wizard.RegionProperty)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1