Search in sources :

Example 6 with GroupInfo

use of com.haulmont.cuba.gui.data.GroupInfo in project cuba by cuba-platform.

the class GroupDelegate method getChildItems.

public List<Entity> getChildItems(GroupInfo groupId) {
    if (groupItems == null) {
        return Collections.emptyList();
    }
    if (containsGroup(groupId)) {
        List<Entity> entities = new ArrayList<>();
        // if current group contains other groups
        if (hasChildren(groupId)) {
            List<GroupInfo> children = getChildren(groupId);
            for (GroupInfo childGroup : children) {
                entities.addAll(getChildItems(childGroup));
            }
        }
        // if current group contains only items
        List<K> idsList = groupItems.get(groupId);
        if (CollectionUtils.isNotEmpty(idsList)) {
            entities.addAll(idsList.stream().map(id -> datasource.getItem(id)).collect(Collectors.toList()));
        }
        return entities;
    }
    return Collections.emptyList();
}
Also used : Entity(com.haulmont.cuba.core.entity.Entity) GroupInfo(com.haulmont.cuba.gui.data.GroupInfo) ArrayList(java.util.ArrayList)

Example 7 with GroupInfo

use of com.haulmont.cuba.gui.data.GroupInfo in project cuba by cuba-platform.

the class GroupDelegate method groupItems.

protected GroupInfo<MetaPropertyPath> groupItems(int propertyIndex, GroupInfo parent, List<GroupInfo> children, T item, final LinkedMap groupValues) {
    final MetaPropertyPath property = (MetaPropertyPath) groupProperties[propertyIndex++];
    Object itemValue = getValueByProperty(item, property);
    groupValues.put(property, itemValue);
    GroupInfo<MetaPropertyPath> groupInfo = new GroupInfo<>(groupValues);
    itemGroups.put(item.getId(), groupInfo);
    if (!parents.containsKey(groupInfo)) {
        parents.put(groupInfo, parent);
    }
    if (!children.contains(groupInfo)) {
        children.add(groupInfo);
    }
    List<GroupInfo> groupChildren = this.children.computeIfAbsent(groupInfo, k -> new ArrayList<>());
    if (propertyIndex < groupProperties.length) {
        groupInfo = groupItems(propertyIndex, groupInfo, groupChildren, item, groupValues);
    }
    return groupInfo;
}
Also used : GroupInfo(com.haulmont.cuba.gui.data.GroupInfo) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath)

Example 8 with GroupInfo

use of com.haulmont.cuba.gui.data.GroupInfo in project cuba by cuba-platform.

the class GroupDelegate method getGroupPath.

@SuppressWarnings({ "SuspiciousMethodCalls", "unchecked" })
public List<GroupInfo> getGroupPath(Entity entity) {
    K id = (K) entity.getId();
    if (!datasource.containsItem(id)) {
        throw new IllegalArgumentException("Datasource doesn't contain passed entity");
    }
    if (itemGroups == null) {
        return Collections.emptyList();
    }
    GroupInfo groupInfo = itemGroups.get(entity.getId());
    if (groupInfo == null) {
        return Collections.emptyList();
    }
    List<GroupInfo> parentGroups = new LinkedList<>();
    parentGroups.add(groupInfo);
    GroupInfo parent = parents.get(groupInfo);
    while (parent != null) {
        parentGroups.add(0, parent);
        parent = parents.get(parent);
    }
    return parentGroups;
}
Also used : GroupInfo(com.haulmont.cuba.gui.data.GroupInfo) LinkedList(java.util.LinkedList)

Aggregations

GroupInfo (com.haulmont.cuba.gui.data.GroupInfo)8 MetaPropertyPath (com.haulmont.chile.core.model.MetaPropertyPath)3 Entity (com.haulmont.cuba.core.entity.Entity)2 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 Instance (com.haulmont.chile.core.model.Instance)1 GroupDatasource (com.haulmont.cuba.gui.data.GroupDatasource)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 Function (java.util.function.Function)1 LinkedMap (org.apache.commons.collections4.map.LinkedMap)1 Element (org.dom4j.Element)1