Search in sources :

Example 1 with TreeNode

use of org.eclipse.scout.rt.ui.html.json.tree.fixtures.TreeNode in project scout.rt by eclipse.

the class JsonTreeTest method testNodeFilter.

@Test
public void testNodeFilter() throws JSONException {
    TreeNode nodeToFilter = new TreeNode();
    nodeToFilter.setEnabled(false);
    List<ITreeNode> nodes = new ArrayList<ITreeNode>();
    nodes.add(nodeToFilter);
    nodes.add(new TreeNode());
    nodes.add(new TreeNode());
    nodes.add(new TreeNode());
    ITree tree = createTree(nodes);
    JsonTree<ITree> jsonTree = m_uiSession.createJsonAdapter(tree, null);
    String node0Id = jsonTree.getOrCreateNodeId(nodes.get(0));
    assertNotNull(node0Id);
    assertNotNull(jsonTree.optTreeNodeForNodeId(node0Id));
    tree.addNodeFilter(new ITreeNodeFilter() {

        @Override
        public boolean accept(ITreeNode node, int level) {
            return node.isEnabled();
        }
    });
    JsonTestUtility.processBufferedEvents(m_uiSession);
    assertNull(jsonTree.optNodeId(nodes.get(0)));
    assertNull(jsonTree.optTreeNodeForNodeId(node0Id));
}
Also used : ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode) ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode) TreeNode(org.eclipse.scout.rt.ui.html.json.tree.fixtures.TreeNode) ITreeNodeFilter(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNodeFilter) ArrayList(java.util.ArrayList) ITree(org.eclipse.scout.rt.client.ui.basic.tree.ITree) Test(org.junit.Test)

Example 2 with TreeNode

use of org.eclipse.scout.rt.ui.html.json.tree.fixtures.TreeNode in project scout.rt by eclipse.

the class JsonTreeTest method testWrongEventOrder.

/**
 * Tests that events are ignored when nodes are not yet inserted.
 */
@Test
public void testWrongEventOrder() throws JSONException {
    List<ITreeNode> nodes = new ArrayList<ITreeNode>();
    nodes.add(new TreeNode());
    nodes.add(new TreeNode());
    nodes.add(new TreeNode());
    ITree tree = createTree(nodes);
    JsonTree<ITree> jsonTree = m_uiSession.createJsonAdapter(tree, null);
    TreeNode newNode = new TreeNode();
    jsonTree.handleModelTreeEvent(new TreeEvent(tree, TreeEvent.TYPE_NODE_EXPANDED, newNode));
    jsonTree.handleModelTreeEvent(new TreeEvent(tree, TreeEvent.TYPE_NODES_INSERTED, nodes.get(0), Collections.singletonList(newNode)));
    JsonTestUtility.processBufferedEvents(m_uiSession);
    List<JsonEvent> events = m_uiSession.currentJsonResponse().getEventList();
    assertEquals(1, events.size());
    assertEquals("nodesInserted", events.get(0).getType());
}
Also used : TreeEvent(org.eclipse.scout.rt.client.ui.basic.tree.TreeEvent) ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode) ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode) TreeNode(org.eclipse.scout.rt.ui.html.json.tree.fixtures.TreeNode) ArrayList(java.util.ArrayList) JsonEvent(org.eclipse.scout.rt.ui.html.json.JsonEvent) ITree(org.eclipse.scout.rt.client.ui.basic.tree.ITree) Test(org.junit.Test)

Example 3 with TreeNode

use of org.eclipse.scout.rt.ui.html.json.tree.fixtures.TreeNode in project scout.rt by eclipse.

the class JsonTreeTest method testNodeDisposal.

/**
 * Tests whether the node gets removed from the maps after deletion (m_treeNodes, m_treeNodeIds)
 */
@Test
public void testNodeDisposal() throws JSONException {
    List<ITreeNode> nodes = new ArrayList<ITreeNode>();
    nodes.add(new TreeNode());
    nodes.add(new TreeNode());
    nodes.add(new TreeNode());
    ITree tree = createTree(nodes);
    JsonTree<ITree> jsonTree = m_uiSession.createJsonAdapter(tree, null);
    String node0Id = jsonTree.getOrCreateNodeId(nodes.get(0));
    assertNotNull(node0Id);
    assertNotNull(jsonTree.optTreeNodeForNodeId(node0Id));
    tree.removeNode(nodes.get(0));
    JsonTestUtility.processBufferedEvents(m_uiSession);
    assertNull(jsonTree.optNodeId(nodes.get(0)));
    assertNull(jsonTree.optTreeNodeForNodeId(node0Id));
    assertNull(jsonTree.getParentNode(nodes.get(0)));
    assertEquals(0, jsonTree.getChildNodes(nodes.get(0)).size());
}
Also used : ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode) ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode) TreeNode(org.eclipse.scout.rt.ui.html.json.tree.fixtures.TreeNode) ArrayList(java.util.ArrayList) ITree(org.eclipse.scout.rt.client.ui.basic.tree.ITree) Test(org.junit.Test)

Example 4 with TreeNode

use of org.eclipse.scout.rt.ui.html.json.tree.fixtures.TreeNode in project scout.rt by eclipse.

the class JsonTreeTest method testInsertionOrderWithExpandEvent.

/**
 * Expected: adding two nodes to a common parent node and actively expanding one node should result in just one event.
 */
@Test
public void testInsertionOrderWithExpandEvent() {
    ITree tree = createTreeWithOneNode();
    tree.getRootNode().setExpanded(true);
    JsonTree<ITree> jsonTree = m_uiSession.createJsonAdapter(tree, null);
    tree.setTreeChanging(true);
    TreeNode child = new TreeNode();
    tree.addChildNode(tree.getRootNode(), child);
    child.setExpanded(true);
    tree.addChildNode(0, tree.getRootNode(), new TreeNode());
    tree.setTreeChanging(false);
    assertEquals(1, jsonTree.eventBuffer().consumeAndCoalesceEvents().size());
}
Also used : ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode) TreeNode(org.eclipse.scout.rt.ui.html.json.tree.fixtures.TreeNode) ITree(org.eclipse.scout.rt.client.ui.basic.tree.ITree) Test(org.junit.Test)

Example 5 with TreeNode

use of org.eclipse.scout.rt.ui.html.json.tree.fixtures.TreeNode in project scout.rt by eclipse.

the class JsonTreeTest method testNodeFilter_events.

@Test
public void testNodeFilter_events() throws JSONException {
    TreeNode nodeToFilter = new TreeNode();
    nodeToFilter.setEnabled(false);
    List<ITreeNode> nodes = new ArrayList<ITreeNode>();
    nodes.add(nodeToFilter);
    nodes.add(new TreeNode());
    nodes.add(new TreeNode());
    nodes.add(new TreeNode());
    ITree tree = createTree(nodes);
    JsonTree<ITree> jsonTree = m_uiSession.createJsonAdapter(tree, null);
    jsonTree.toJson();
    String node0Id = jsonTree.getOrCreateNodeId(nodes.get(0));
    assertNotNull(node0Id);
    assertNotNull(jsonTree.optTreeNodeForNodeId(node0Id));
    tree.addNodeFilter(new ITreeNodeFilter() {

        @Override
        public boolean accept(ITreeNode node, int level) {
            return node.isEnabled();
        }
    });
    JsonTestUtility.processBufferedEvents(m_uiSession);
    assertNull(jsonTree.optNodeId(nodes.get(0)));
    assertNull(jsonTree.optTreeNodeForNodeId(node0Id));
    List<JsonEvent> events = m_uiSession.currentJsonResponse().getEventList();
    assertEquals(1, events.size());
    assertEventTypeAndNodeIds(events.get(0), "nodesDeleted", node0Id);
}
Also used : ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode) ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode) TreeNode(org.eclipse.scout.rt.ui.html.json.tree.fixtures.TreeNode) ITreeNodeFilter(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNodeFilter) ArrayList(java.util.ArrayList) JsonEvent(org.eclipse.scout.rt.ui.html.json.JsonEvent) ITree(org.eclipse.scout.rt.client.ui.basic.tree.ITree) Test(org.junit.Test)

Aggregations

ITree (org.eclipse.scout.rt.client.ui.basic.tree.ITree)13 ITreeNode (org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode)13 TreeNode (org.eclipse.scout.rt.ui.html.json.tree.fixtures.TreeNode)13 Test (org.junit.Test)13 ArrayList (java.util.ArrayList)11 JsonEvent (org.eclipse.scout.rt.ui.html.json.JsonEvent)8 JSONObject (org.json.JSONObject)4 ITreeNodeFilter (org.eclipse.scout.rt.client.ui.basic.tree.ITreeNodeFilter)3 TreeEvent (org.eclipse.scout.rt.client.ui.basic.tree.TreeEvent)2 Tree (org.eclipse.scout.rt.ui.html.json.tree.fixtures.Tree)2 TreeAdapter (org.eclipse.scout.rt.client.ui.basic.tree.TreeAdapter)1 UiException (org.eclipse.scout.rt.ui.html.UiException)1 JSONArray (org.json.JSONArray)1