Search in sources :

Example 1 with ITreeContainer

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);
    }
}
Also used : IBeanRelationNodeModel(org.jowidgets.cap.ui.api.tree.IBeanRelationNodeModel) ITreeNode(org.jowidgets.api.widgets.ITreeNode) ITreeContainer(org.jowidgets.api.widgets.ITreeContainer) IBeanRelationTreeBluePrint(org.jowidgets.cap.ui.api.widgets.IBeanRelationTreeBluePrint) IBeanProxy(org.jowidgets.cap.ui.api.bean.IBeanProxy)

Aggregations

ITreeContainer (org.jowidgets.api.widgets.ITreeContainer)1 ITreeNode (org.jowidgets.api.widgets.ITreeNode)1 IBeanProxy (org.jowidgets.cap.ui.api.bean.IBeanProxy)1 IBeanRelationNodeModel (org.jowidgets.cap.ui.api.tree.IBeanRelationNodeModel)1 IBeanRelationTreeBluePrint (org.jowidgets.cap.ui.api.widgets.IBeanRelationTreeBluePrint)1