Search in sources :

Example 11 with Node

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);
            }*/
    }
}
Also used : Node(io.jmix.core.common.datastruct.Node) MetaPropertyPath(io.jmix.core.metamodel.model.MetaPropertyPath) MetaClass(io.jmix.core.metamodel.model.MetaClass) KeyValueMetaClass(io.jmix.core.impl.keyvalue.KeyValueMetaClass) MetaProperty(io.jmix.core.metamodel.model.MetaProperty)

Example 12 with Node

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();
}
Also used : Node(io.jmix.core.common.datastruct.Node) ArrayList(java.util.ArrayList) AbstractCondition(com.haulmont.cuba.gui.components.filter.condition.AbstractCondition)

Example 13 with Node

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);
        }
    });
}
Also used : TreeGridDragSource(com.vaadin.ui.components.grid.TreeGridDragSource) Node(io.jmix.core.common.datastruct.Node) TreeGridDropTarget(com.vaadin.ui.components.grid.TreeGridDropTarget) GroupCondition(com.haulmont.cuba.gui.components.filter.condition.GroupCondition) JmixTree(io.jmix.ui.widget.JmixTree) AbstractCondition(com.haulmont.cuba.gui.components.filter.condition.AbstractCondition) DropLocation(com.vaadin.shared.ui.grid.DropLocation)

Aggregations

Node (io.jmix.core.common.datastruct.Node)13 AbstractCondition (com.haulmont.cuba.gui.components.filter.condition.AbstractCondition)7 ConditionsTree (com.haulmont.cuba.gui.components.filter.ConditionsTree)4 MetaClass (io.jmix.core.metamodel.model.MetaClass)3 MetaProperty (io.jmix.core.metamodel.model.MetaProperty)3 ListComponent (com.haulmont.cuba.gui.components.ListComponent)2 GroupCondition (com.haulmont.cuba.gui.components.filter.condition.GroupCondition)2 GroupConditionDescriptor (com.haulmont.cuba.gui.components.filter.descriptor.GroupConditionDescriptor)2 KeyValueMetaClass (io.jmix.core.impl.keyvalue.KeyValueMetaClass)2 MetaPropertyPath (io.jmix.core.metamodel.model.MetaPropertyPath)2 Component (io.jmix.ui.component.Component)2 ArrayList (java.util.ArrayList)2 Element (org.dom4j.Element)2 CubaProperties (com.haulmont.cuba.CubaProperties)1 com.haulmont.cuba.core.global (com.haulmont.cuba.core.global)1 Messages (com.haulmont.cuba.core.global.Messages)1 Op (com.haulmont.cuba.core.global.filter.Op)1 AbstractWindow (com.haulmont.cuba.gui.components.AbstractWindow)1 Filter (com.haulmont.cuba.gui.components.Filter)1 GridLayout (com.haulmont.cuba.gui.components.GridLayout)1