Search in sources :

Example 16 with TreeItemIdNode

use of com.github.bordertech.wcomponents.TreeItemIdNode in project wcomponents by BorderTech.

the class WTreeExample method applyOptions.

/**
 * Set options for the WTree based on user input in the options field(s).
 */
private void applyOptions() {
    tree.reset();
    tree.setType(cbMakeHTree.isSelected() ? WTree.Type.HORIZONTAL : WTree.Type.VERTICAL);
    tree.setSelectMode(cbUseMultiSelect.isSelected() ? WTree.SelectMode.MULTIPLE : WTree.SelectMode.SINGLE);
    tree.setExpandMode((WTree.ExpandMode) ddExpMode.getSelected());
    control.setVisible(cbAjaxTrigger.isSelected());
    // This model holds the data so would be included on the user session.
    ExampleTreeModel data = new ExampleTreeModel(ExampleDataUtil.createExampleData(), cbUseDocuments.isSelected(), cbUseImage.isSelected());
    tree.setTreeModel(data);
    if (cbCustomTree.isSelected()) {
        TreeItemIdNode custom = new TreeItemIdNode(null);
        if (cbUseDocuments.isSelected()) {
            // Put all documents under Tom Smith (ID16)
            TreeItemIdNode node = new TreeItemIdNode("ID16");
            node.addChild(new TreeItemIdNode("11122"));
            node.addChild(new TreeItemIdNode("23456"));
            node.addChild(new TreeItemIdNode("78901"));
            node.addChild(new TreeItemIdNode("23457"));
            // Put 3 people in the custom tree
            custom.addChild(new TreeItemIdNode("ID4"));
            custom.addChild(node);
            custom.addChild(new TreeItemIdNode("ID1"));
        } else {
            // Put people under Tom SMith
            TreeItemIdNode itemID2 = new TreeItemIdNode("ID2");
            itemID2.setHasChildren(true);
            TreeItemIdNode itemID1 = new TreeItemIdNode("ID1");
            itemID1.setHasChildren(true);
            TreeItemIdNode node = new TreeItemIdNode("ID16");
            node.addChild(itemID2);
            node.addChild(new TreeItemIdNode("ID3"));
            node.addChild(new TreeItemIdNode("ID6"));
            node.addChild(new TreeItemIdNode("ID5"));
            // Take some nodes from other nodes
            node.addChild(new TreeItemIdNode("2A"));
            node.addChild(new TreeItemIdNode("1B1"));
            // Put 3 people at top level
            custom.addChild(new TreeItemIdNode("ID4"));
            custom.addChild(node);
            custom.addChild(itemID1);
        }
        tree.setCustomTree(custom);
    }
}
Also used : WTree(com.github.bordertech.wcomponents.WTree) TreeItemIdNode(com.github.bordertech.wcomponents.TreeItemIdNode)

Example 17 with TreeItemIdNode

use of com.github.bordertech.wcomponents.TreeItemIdNode in project wcomponents by BorderTech.

the class TreeItemUtil method copyTreeNode.

/**
 * @param node the node to copy
 * @return a copy of the node
 */
public static TreeItemIdNode copyTreeNode(final TreeItemIdNode node) {
    TreeItemIdNode copy = new TreeItemIdNode(node.getItemId());
    copy.setHasChildren(node.hasChildren());
    for (TreeItemIdNode childItem : node.getChildren()) {
        TreeItemIdNode childCopy = copyTreeNode(childItem);
        copy.addChild(childCopy);
    }
    return copy;
}
Also used : TreeItemIdNode(com.github.bordertech.wcomponents.TreeItemIdNode)

Aggregations

TreeItemIdNode (com.github.bordertech.wcomponents.TreeItemIdNode)17 Test (org.junit.Test)8 JsonArray (com.google.gson.JsonArray)4 JsonObject (com.google.gson.JsonObject)4 WTree (com.github.bordertech.wcomponents.WTree)3 TreeItemModel (com.github.bordertech.wcomponents.TreeItemModel)2 HashSet (java.util.HashSet)2 TreeItemImage (com.github.bordertech.wcomponents.TreeItemImage)1 Gson (com.google.gson.Gson)1 JsonParser (com.google.gson.JsonParser)1 JsonPrimitive (com.google.gson.JsonPrimitive)1