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);
}
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;
}
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);
}
}
}
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;
}
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);
}
}
Aggregations