Search in sources :

Example 1 with GroupInfo

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

the class ExcelExporter method createGroupRow.

protected int createGroupRow(GroupTable table, List<Table.Column> columns, int rowNumber, GroupInfo groupInfo, int groupNumber) {
    GroupDatasource ds = table.getDatasource();
    HSSFRow row = sheet.createRow(rowNumber);
    Map<Object, Object> aggregations = table.isAggregatable() ? table.getAggregationResults(groupInfo) : Collections.emptyMap();
    int i = 0;
    int initialGroupNumber = groupNumber;
    for (Table.Column column : columns) {
        if (i == initialGroupNumber) {
            HSSFCell cell = row.createCell(i);
            Object val = groupInfo.getValue();
            if (val == null) {
                val = messages.getMessage(getClass(), "excelExporter.empty");
            }
            Collection children = table.getDatasource().getGroupItemIds(groupInfo);
            if (children.isEmpty()) {
                return rowNumber;
            }
            Integer groupChildCount = null;
            if (table.isShowItemsCountForGroup()) {
                groupChildCount = children.size();
            }
            Object captionValue = val;
            Element xmlDescriptor = column.getXmlDescriptor();
            if (xmlDescriptor != null && StringUtils.isNotEmpty(xmlDescriptor.attributeValue("captionProperty"))) {
                String captionProperty = xmlDescriptor.attributeValue("captionProperty");
                Object itemId = children.iterator().next();
                Instance item = ds.getItem(itemId);
                captionValue = item.getValueEx(captionProperty);
            }
            @SuppressWarnings("unchecked") GroupTable.GroupCellValueFormatter<Entity> groupCellValueFormatter = table.getGroupCellValueFormatter();
            if (groupCellValueFormatter != null) {
                // disable separate "(N)" printing
                groupChildCount = null;
                List<Entity> groupItems = ((Collection<Object>) ds.getGroupItemIds(groupInfo)).stream().map((Function<Object, Entity>) ds::getItem).collect(Collectors.toList());
                GroupTable.GroupCellContext<Entity> cellContext = new GroupTable.GroupCellContext<>(groupInfo, captionValue, metadataTools.format(captionValue), groupItems);
                captionValue = groupCellValueFormatter.format(cellContext);
            }
            MetaPropertyPath columnId = (MetaPropertyPath) column.getId();
            formatValueCell(cell, captionValue, columnId, groupNumber++, rowNumber, 0, groupChildCount);
        } else {
            AggregationInfo agr = column.getAggregation();
            if (agr != null) {
                Object aggregationResult = aggregations.get(agr.getPropertyPath());
                if (aggregationResult != null) {
                    HSSFCell cell = row.createCell(i);
                    formatValueCell(cell, aggregationResult, null, i, rowNumber, 0, null);
                }
            }
        }
        i++;
    }
    int oldRowNumber = rowNumber;
    List<GroupInfo> children = ds.getChildren(groupInfo);
    if (children.size() > 0) {
        for (GroupInfo child : children) {
            rowNumber = createGroupRow(table, columns, ++rowNumber, child, groupNumber);
        }
    } else {
        Collection<Object> itemIds = ds.getGroupItemIds(groupInfo);
        for (Object itemId : itemIds) {
            createRow(table, columns, groupNumber, ++rowNumber, itemId);
        }
    }
    sheet.groupRow(oldRowNumber + 1, rowNumber);
    return rowNumber;
}
Also used : Entity(com.haulmont.cuba.core.entity.Entity) Instance(com.haulmont.chile.core.model.Instance) Element(org.dom4j.Element) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath) Function(java.util.function.Function) GroupInfo(com.haulmont.cuba.gui.data.GroupInfo) GroupDatasource(com.haulmont.cuba.gui.data.GroupDatasource)

Example 2 with GroupInfo

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

the class GroupDelegate method getGroupItemsCount.

public int getGroupItemsCount(GroupInfo groupId) {
    if (containsGroup(groupId)) {
        List<K> itemIds;
        if ((itemIds = groupItems.get(groupId)) == null) {
            int count = 0;
            final List<GroupInfo> children = getChildren(groupId);
            for (final GroupInfo child : children) {
                count += getGroupItemsCount(child);
            }
            return count;
        } else {
            return itemIds.size();
        }
    }
    return 0;
}
Also used : GroupInfo(com.haulmont.cuba.gui.data.GroupInfo)

Example 3 with GroupInfo

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

the class GroupDelegate method doGroupSort.

protected void doGroupSort(CollectionDatasource.Sortable.SortInfo<MetaPropertyPath>[] sortInfo) {
    if (hasGroups()) {
        final MetaPropertyPath propertyPath = sortInfo[0].getPropertyPath();
        final boolean asc = CollectionDatasource.Sortable.Order.ASC.equals(sortInfo[0].getOrder());
        final int index = Arrays.asList(groupProperties).indexOf(propertyPath);
        if (index > -1) {
            if (index == 0) {
                // Sort roots
                roots.sort(new GroupInfoComparator(asc));
            } else {
                final Object parentProperty = groupProperties[index - 1];
                for (final Map.Entry<GroupInfo, List<GroupInfo>> entry : children.entrySet()) {
                    Object property = entry.getKey().getProperty();
                    if (property.equals(parentProperty)) {
                        entry.getValue().sort(new GroupInfoComparator(asc));
                    }
                }
            }
        } else {
            final Set<GroupInfo> groups = parents.keySet();
            for (final GroupInfo groupInfo : groups) {
                List<K> items = groupItems.get(groupInfo);
                if (items != null) {
                    items.sort(new EntityByIdComparator<>(propertyPath, datasource, asc));
                }
            }
        }
    }
}
Also used : GroupInfo(com.haulmont.cuba.gui.data.GroupInfo) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) LinkedMap(org.apache.commons.collections4.map.LinkedMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 4 with GroupInfo

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

the class GroupDelegate method getGroupItemIds.

public List<K> getGroupItemIds(GroupInfo group) {
    if (containsGroup(group)) {
        List<K> itemIds;
        if ((itemIds = groupItems.get(group)) == null) {
            itemIds = new LinkedList<>();
            final List<GroupInfo> children = getChildren(group);
            for (final GroupInfo child : children) {
                itemIds.addAll(getGroupItemIds(child));
            }
        }
        return Collections.unmodifiableList(itemIds);
    }
    return Collections.emptyList();
}
Also used : GroupInfo(com.haulmont.cuba.gui.data.GroupInfo)

Example 5 with GroupInfo

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

the class CubaGroupTable method getItemIdsInRange.

@Override
protected LinkedHashSet<Object> getItemIdsInRange(Object startItemId, final int length) {
    Set<Object> rootIds = super.getItemIdsInRange(startItemId, length);
    LinkedHashSet<Object> ids = new LinkedHashSet<>();
    for (Object itemId : rootIds) {
        if (itemId instanceof GroupInfo) {
            if (!isExpanded(itemId)) {
                Collection<?> itemIds = getGroupItemIds(itemId);
                ids.addAll(itemIds);
                expand(itemId, true);
            }
            List<GroupInfo> children = (List<GroupInfo>) getChildren(itemId);
            for (GroupInfo groupInfo : children) {
                if (!isExpanded(groupInfo)) {
                    expand(groupInfo, true);
                }
            }
        } else {
            ids.add(itemId);
        }
    }
    return ids;
}
Also used : GroupInfo(com.haulmont.cuba.gui.data.GroupInfo)

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