Tuesday, February 12, 2013

Expand all the nodes of a tree table component adf

   // treeTable
 private RichTreeTable treeTable;

    public void setTreeTable(RichTreeTable treeTable) {
        this.treeTable= treeTable;
    }

    public RichTreeTable getTreeTable() {
        return treeTable;
    }


// on Expand nodes
    private void expandTreeTable() {
         if (this.treeTable!= null) {
             disclosedTreeRowKeySet = new RowKeySetImpl();
             CollectionModel model = (CollectionModel)treeTable.getValue();
             JUCtrlHierBinding treeBinding = (JUCtrlHierBinding)model.getWrappedData();
             JUCtrlHierNodeBinding rootNode = treeBinding.getRootNodeBinding();
             disclosedTreeRowKeySet = treeTable.getDisclosedRowKeys();
             if (disclosedTreeRowKeySet == null) {
                 disclosedTreeRowKeySet = new RowKeySetImpl();
             }
             List<JUCtrlHierNodeBinding> firstLevelChildren = rootNode.getChildren();
             for (JUCtrlHierNodeBinding node : firstLevelChildren) {
                 ArrayList list = new ArrayList();
                 list.add(node.getRowKey());
                 disclosedTreeRowKeySet.add(list);
//to expand children nodes
expandTreeChildrenNode(soTreeTableBind, node, list);

             }
             treeTable.setDisclosedRowKeys(disclosedTreeRowKeySet);
         }
     AdfFacesContext.getCurrentInstance().addPartialTarget(treeTable);
}



//to expand children nodes
 private void expandTreeChildrenNode(RichTreeTable rt, JUCtrlHierNodeBinding node, List<Key> parentRowKey) {
        ArrayList children = node.getChildren();
        List<Key> rowKey;
        if (children != null) {
            for (int i = 0; i < children.size(); i++) {
                rowKey = new ArrayList<Key>();
                rowKey.addAll(parentRowKey);
                rowKey.add(((JUCtrlHierNodeBinding)children.get(i)).getRowKey());
                disclosedTreeRowKeySet.add(rowKey);
                if (((JUCtrlHierNodeBinding)(children.get(i))).getChildren() == null)
                    continue;
                expandTreeChildrenNode(rt, (JUCtrlHierNodeBinding)(node.getChildren().get(i)), rowKey);
            }
        }
    }

// on Collapse nodes  

    public String onCollapse() {
        treeTable.getDisclosedRowKeys().clear();
        AdfFacesContext.getCurrentInstance().addPartialTarget(treeTable);
        return null;
    }

// make sure you don't have immediate property set for the treeTable

No comments: