@Override public boolean hasChildren(Object itemId) { Entity currentItem = getItem(itemId); if (currentItem == null) return false; if (hierarchyProperty != null) { Collection ids = getItemIds(); for (Object id : ids) { Entity item = getItemNN(id); Entity parentItem = item.getValue(hierarchyProperty); if (parentItem != null && parentItem.getId().equals(itemId)) return true; } } return false; }
@Override public Object firstItemId() { Collection<?> rootItemIds = getRootItemIds(); return rootItemIds.isEmpty() ? null : rootItemIds.iterator().next(); } }
@Override public Collection<?> getRootItemIds() { Collection<?> ids = getItemIds(); if (hierarchyProperty != null) { Set<Object> result = new LinkedHashSet<>(); for (Object id : ids) { Entity item = getItemNN(id); Entity parentItem = item.getValue(hierarchyProperty); if (parentItem == null || (container.getItemOrNull(parentItem.getId()) == null)) result.add(item.getId()); } return result; } else { return new LinkedHashSet<>(ids); } }
@Override public Object getParent(Object itemId) { if (hierarchyProperty != null) { Instance item = getItem(itemId); if (item == null) return null; else { Entity parentItem = item.getValue(hierarchyProperty); return parentItem == null ? null : parentItem.getId(); } } return null; }
@SuppressWarnings("unchecked") @Override protected ContainerTableItems createContainerTableSource(CollectionContainer container) { Element rowsEl = element.element("rows"); String hierarchyProperty = element.attributeValue("hierarchyProperty"); if (hierarchyProperty == null && rowsEl != null) { hierarchyProperty = rowsEl.attributeValue("hierarchyProperty"); } if (Strings.isNullOrEmpty(hierarchyProperty)) { throw new GuiDevelopmentException("TreeTable doesn't have 'hierarchyProperty' attribute", context.getCurrentFrameId(), "TreeTable ID", element.attributeValue("id")); } return new ContainerTreeTableItems(container, hierarchyProperty); } }
@Override public boolean isRoot(Object itemId) { Instance item = getItem(itemId); if (item == null) return false; if (hierarchyProperty != null) { Entity parentItem = item.getValue(hierarchyProperty); return (parentItem == null || (container.getItemOrNull(parentItem.getId()) == null)); } else { return true; } }
@Override public Collection<?> getChildren(Object itemId) { if (hierarchyProperty != null) { Entity currentItem = getItem(itemId); if (currentItem == null) return Collections.emptyList(); List<Object> res = new ArrayList<>(); Collection ids = getItemIds(); for (Object id : ids) { Entity item = getItemNN(id); Entity parentItem = item.getValue(hierarchyProperty); if (parentItem != null && parentItem.getId().equals(itemId)) res.add(item.getId()); } return res; } return Collections.emptyList(); }