protected HierarchicalDatasource createHierarchicalPropertyDatasource() { return new HierarchicalPropertyDatasourceImpl(); }
@SuppressWarnings("unchecked") @Override public boolean isRoot(K itemId) { Instance item = getItem(itemId); if (item == null) return false; if (hierarchyPropertyName != null) { Object value = item.getValue(hierarchyPropertyName); return (value == null || !containsItem(((T) value).getId())); } else { return true; } }
@Override public boolean hasChildren(K itemId) { final Entity item = getItem(itemId); if (item == null) return false; if (hierarchyPropertyName != null) { for (T currentItem : getItems()) { Object parentItem = currentItem.getValue(hierarchyPropertyName); if (parentItem != null && parentItem.equals(item)) return true; } } return false; }
@SuppressWarnings("unchecked") @Override public Collection<K> getRootItemIds() { Collection<K> ids = getItemIds(); if (hierarchyPropertyName != null) { Set<K> result = new LinkedHashSet<>(); for (K id : ids) { Entity<K> item = getItemNN(id); Object value = item.getValue(hierarchyPropertyName); if (value == null || !containsItem(((T) value).getId())) result.add(item.getId()); } return result; } else { return new LinkedHashSet<>(ids); } }
public Collection<K> getChildren(K itemId) { if (hierarchyPropertyName != null) { Entity item = getItem(itemId); if (item == null) { return Collections.emptyList(); Collection<K> ids = getItemIds(); for (K id : ids) { Entity<K> currentItem = getItemNN(id); Object parentItem = currentItem.getValue(hierarchyPropertyName); if (parentItem != null && parentItem.equals(item)) Entity item1 = getItemNN(o1); Entity item2 = getItemNN(o2);
@Override public K getParent(K itemId) { if (hierarchyPropertyName != null) { Instance item = getItem(itemId); if (item == null) return null; else { Entity<K> value = item.getValue(hierarchyPropertyName); return value == null ? null : value.getId(); } } return null; }
@Override public void committed(Set<Entity> entities) { super.committed(entities); if (State.VALID.equals(masterDs.getState())) { Collection<T> collection = getCollection(); if (item != null && collection != null) { for (T entity : collection) { if (entity.equals(item)) { item = entity; } } } } } }
((HierarchicalPropertyDatasourceImpl) treeDs).setSortPropertyName("position");