Search in sources :

Example 6 with WTree

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

the class WTreeRenderer_Test method testRendererCorrectlyConfigured.

@Test
public void testRendererCorrectlyConfigured() {
    WTree tree = new WTree();
    Assert.assertTrue("Incorrect renderer supplied", getWebXmlRenderer(tree) instanceof WTreeRenderer);
}
Also used : WTree(com.github.bordertech.wcomponents.WTree) Test(org.junit.Test)

Example 7 with WTree

use of com.github.bordertech.wcomponents.WTree 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 8 with WTree

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

the class SelectExampleAction method execute.

/**
 * {@inheritDoc}
 */
@Override
public void execute(final ActionEvent event) {
    ExampleData data = (ExampleData) event.getActionObject();
    WComponent source = (WComponent) event.getSource();
    TreePicker picker = WebUtilities.getAncestorOfClass(TreePicker.class, source);
    picker.selectExample(data);
    MenuPanel panel = WebUtilities.getAncestorOfClass(MenuPanel.class, source);
    if (panel != null) {
        WTree tree = panel.getTree();
        if (tree != null) {
            // null);
            tree.setSelectedRows(new HashSet<String>());
        }
    }
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) WTree(com.github.bordertech.wcomponents.WTree)

Example 9 with WTree

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

the class WTreeRenderer_Test method testXssEscaping.

@Test
public void testXssEscaping() throws IOException, SAXException, XpathException {
    List<MockTreeItemData.MyBean> data = new ArrayList<>();
    // Invalid chars
    data.add(new MockTreeItemData.MyBean(getInvalidCharSequence(), "X"));
    // Malicious
    data.add(new MockTreeItemData.MyBean(getMaliciousContent(), "Y"));
    MockTreeItemData.MyTestModel model = new MockTreeItemData.MyTestModel(data);
    WTree tree = new WTree();
    tree.setTreeModel(model);
    assertSafeContent(tree);
}
Also used : WTree(com.github.bordertech.wcomponents.WTree) ArrayList(java.util.ArrayList) MockTreeItemData(com.github.bordertech.wcomponents.MockTreeItemData) Test(org.junit.Test)

Example 10 with WTree

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

the class WTreeRenderer_Test method testDoPaintWhenEmpty.

@Test
public void testDoPaintWhenEmpty() throws IOException, SAXException, XpathException {
    WTree tree = new WTree();
    setActiveContext(createUIContext());
    assertSchemaMatch(tree);
}
Also used : WTree(com.github.bordertech.wcomponents.WTree) Test(org.junit.Test)

Aggregations

WTree (com.github.bordertech.wcomponents.WTree)11 Test (org.junit.Test)5 TreeItemModel (com.github.bordertech.wcomponents.TreeItemModel)4 TreeItemIdNode (com.github.bordertech.wcomponents.TreeItemIdNode)3 HashSet (java.util.HashSet)3 ArrayList (java.util.ArrayList)2 MockTreeItemData (com.github.bordertech.wcomponents.MockTreeItemData)1 WComponent (com.github.bordertech.wcomponents.WComponent)1 XmlStringBuilder (com.github.bordertech.wcomponents.XmlStringBuilder)1