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