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