use of io.jmix.core.common.datastruct.Node in project jmix by jmix-framework.
the class ConditionDescriptorsTreeBuilder method recursivelyFillPropertyDescriptors.
protected void recursivelyFillPropertyDescriptors(Node<AbstractConditionDescriptor> parentNode, int currentDepth) {
currentDepth++;
List<AbstractConditionDescriptor> descriptors = new ArrayList<>();
String propertyId = parentNode.getData().getName();
MetaPropertyPath mpp = entityMetaClass.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) || excludePropertiesRecursively && excludedProperties.contains(property.getName()) || filter.getPropertiesFilterPredicate() != null && !filter.getPropertiesFilterPredicate().test(entityMetaClass.getPropertyPath(propertyPath))) {
continue;
}
Class<? extends FrameOwner> controllerClass = filter.getFrame().getFrameOwner().getClass();
// todo rework
String messagesPack = UiControllerUtils.getPackage(controllerClass);
if (isKeyValueMetaClass) {
if (parentNode.data instanceof PropertyConditionDescriptor) {
PropertyConditionDescriptor parentConditionDescriptor = (PropertyConditionDescriptor) parentNode.data;
String parentPropertiesPath = parentConditionDescriptor.getPropertiesPath();
String newPropertiesPath = !Strings.isNullOrEmpty(parentPropertiesPath) ? parentPropertiesPath + "." + property.getName() : property.getName();
PropertyConditionDescriptor childPropertyConditionDescriptor = new PropertyConditionDescriptor(propertyPath, null, messagesPack, filterComponentName, entityMetaClass, parentConditionDescriptor.getEntityAlias(), newPropertiesPath);
descriptors.add(childPropertyConditionDescriptor);
}
} else {
PropertyConditionDescriptor childPropertyConditionDescriptor = new PropertyConditionDescriptor(propertyPath, null, messagesPack, filterComponentName, entityMetaClass, entityAlias);
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();
// todo dynamic attributes
/*if (!dynamicAttributes.getAttributesForMetaClass(childMetaClass).isEmpty()) {
DynamicAttributesConditionCreator descriptor = new DynamicAttributesConditionCreator(filterComponentName,
entityMetaClass, propertyId, entityAlias);
Node<AbstractConditionDescriptor> newNode = new Node<>(descriptor);
parentNode.addChild(newNode);
}*/
}
}
use of io.jmix.core.common.datastruct.Node in project jmix by jmix-framework.
the class AppliedFilter method getText.
public String getText() {
String name = filterEntity.getName();
if (StringUtils.isBlank(name)) {
name = messages.getMainMessage(filterEntity.getCode());
}
StringBuilder sb = new StringBuilder(name);
List<Node<AbstractCondition>> visibleRootNodesWithValues = new ArrayList<>();
for (Node<AbstractCondition> rootNode : conditions.getRootNodes()) {
AbstractCondition condition = rootNode.getData();
if (!condition.getHidden() && (condition.isGroup() || condition.getParam() != null && condition.getParam().getValue() != null))
visibleRootNodesWithValues.add(rootNode);
}
Iterator<Node<AbstractCondition>> iterator = visibleRootNodesWithValues.iterator();
if (iterator.hasNext())
sb.append(": ");
while (iterator.hasNext()) {
Node<AbstractCondition> rootNode = iterator.next();
recursivelyCreateConditionCaption(rootNode, sb);
if (iterator.hasNext())
sb.append(", ");
}
return sb.toString();
}
use of io.jmix.core.common.datastruct.Node in project jmix by jmix-framework.
the class WebFilterHelper method initConditionsDragAndDrop.
@SuppressWarnings("unchecked")
@Override
public void initConditionsDragAndDrop(final Tree tree, final ConditionsTree conditions) {
JmixTree vTree = tree.unwrapOrNull(JmixTree.class);
if (vTree == null) {
return;
}
TreeGridDragSource<AbstractCondition> treeGridDragSource = new TreeGridDragSource<>(vTree.getCompositionRoot());
treeGridDragSource.setDragDataGenerator(TREE_DRAGGED_ITEM_ID, item -> item.getId().toString());
TreeGridDropTarget<AbstractCondition> treeGridDropTarget = new TreeGridDropTarget<>(vTree.getCompositionRoot(), DropMode.ON_TOP_OR_BETWEEN);
treeGridDropTarget.addTreeGridDropListener(event -> {
if (!event.getDragSourceComponent().isPresent() || event.getDragSourceComponent().get() != vTree.getCompositionRoot()) {
return;
}
String sourceId = event.getDataTransferData(TREE_DRAGGED_ITEM_ID).isPresent() ? event.getDataTransferData(TREE_DRAGGED_ITEM_ID).get() : null;
if (sourceId == null) {
return;
}
Object sourceItemId = UUID.fromString(sourceId);
Object targetItemId = event.getDropTargetRow().isPresent() ? event.getDropTargetRow().get().getId() : null;
if (targetItemId == null) {
return;
}
// if we drop to itself
if (targetItemId.equals(sourceItemId)) {
return;
}
AbstractCondition sourceCondition = (AbstractCondition) tree.getItems().getItem(sourceItemId);
AbstractCondition targetCondition = (AbstractCondition) tree.getItems().getItem(targetItemId);
Node<AbstractCondition> sourceNode = conditions.getNode(sourceCondition);
Node<AbstractCondition> targetNode = conditions.getNode(targetCondition);
// if we drop parent to its child
if (isAncestorOf(targetNode, sourceNode)) {
return;
}
boolean moveToTheSameParent = Objects.equals(sourceNode.getParent(), targetNode.getParent());
DropLocation location = event.getDropLocation();
if (location == DropLocation.ON_TOP) {
// prevent drop to not group condition
if (!(targetCondition instanceof GroupCondition)) {
return;
}
if (sourceNode.getParent() == null) {
conditions.getRootNodes().remove(sourceNode);
} else {
sourceNode.getParent().getChildren().remove(sourceNode);
}
targetNode.addChild(sourceNode);
refreshConditionsDs(tree, conditions);
tree.expand(targetCondition);
} else {
List<Node<AbstractCondition>> siblings;
if (targetNode.getParent() == null)
siblings = conditions.getRootNodes();
else
siblings = targetNode.getParent().getChildren();
int targetIndex = siblings.indexOf(targetNode);
if (location == DropLocation.BELOW)
targetIndex++;
int sourceNodeIndex;
if (sourceNode.getParent() == null) {
sourceNodeIndex = conditions.getRootNodes().indexOf(sourceNode);
conditions.getRootNodes().remove(sourceNode);
} else {
sourceNodeIndex = sourceNode.getParent().getChildren().indexOf(sourceNode);
sourceNode.getParent().getChildren().remove(sourceNode);
}
// decrease drop position index if dragging from top to bottom inside the same parent node
if (moveToTheSameParent && (sourceNodeIndex < targetIndex))
targetIndex--;
// if we drop source accurate below expanded target
if (tree.isExpanded(targetItemId) && location == DropLocation.BELOW) {
targetNode.insertChildAt(0, sourceNode);
} else if (targetNode.getParent() == null) {
sourceNode.parent = null;
conditions.getRootNodes().add(targetIndex, sourceNode);
} else {
targetNode.getParent().insertChildAt(targetIndex, sourceNode);
}
refreshConditionsDs(tree, conditions);
}
});
}
Aggregations