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