use of org.jowidgets.api.widgets.ITreeContainer in project jo-client-platform by jo-source.
the class BeanRelationTreeImpl method onBeansChanged.
private void onBeansChanged(final ITreeContainer treeContainer, final IBeanRelationNodeModel<Object, Object> relationNodeModel, final IMenuModel nodeMenu) {
if (RelationRenderingPolicy.GREY_EMPTY_RELATIONS == relationRenderingPolicy || RelationRenderingPolicy.HIDE_EMPTY_READONLY_RELATIONS == relationRenderingPolicy) {
final ITreeContainer parentContainer = treeContainer.getParentContainer();
if (parentContainer != null && treeContainer instanceof ITreeNode) {
final Tuple<IBeanRelationNodeModel<Object, Object>, IBeanProxy<Object>> tuple = nodesMap.get(treeContainer);
if (tuple != null && tuple.getSecond() == null) {
if (relationNodeModel.getSize() == 0) {
if (!hasVisibleItems(nodeMenu) && relationNodeModel.getFilter(IBeanTableModel.UI_FILTER_ID) == null && relationNodeModel.getFilter(IBeanTableModel.UI_SEARCH_FILTER_ID) == null && RelationRenderingPolicy.HIDE_EMPTY_READONLY_RELATIONS == relationRenderingPolicy) {
parentContainer.removeNode((ITreeNode) treeContainer);
return;
} else {
((ITreeNode) treeContainer).setForegroundColor(Colors.DISABLED);
}
} else {
((ITreeNode) treeContainer).setForegroundColor(null);
}
}
}
}
final int oldSize = treeContainer.getChildren().size();
final int headMatching = getHeadMatchingLength(treeContainer, relationNodeModel);
final int tailMatching = getTailMatchingLength(treeContainer, relationNodeModel);
final int beansToDelete = oldSize - headMatching - tailMatching;
// add the new beans
for (int i = headMatching; i < (relationNodeModel.getSize() - tailMatching); i++) {
// get the bean at index i
final IBeanProxy<Object> bean = relationNodeModel.getBean(i);
// add the bean to tree container
addBeanToTreeContainer(bean, beansToDelete + i, treeContainer, relationNodeModel, nodeMenu);
}
// remove the old beans
for (int i = 0; i < beansToDelete; i++) {
treeContainer.removeNode(headMatching);
}
// auto expand the node if necessary
if (treeContainer.getLevel() < autoExpandLevel && treeContainer instanceof ITreeNode && treeContainer.getChildren().size() > 0) {
final ITreeNode treeNode = (ITreeNode) treeContainer;
treeNode.setExpanded(true);
}
if (treeContainer instanceof ITreeNode && expandedNodesCache.contains(new ExpandedNodeKey((ITreeNode) treeContainer))) {
final ITreeNode treeNode = (ITreeNode) treeContainer;
treeNode.setExpanded(true);
}
}
Aggregations