Search in sources :

Example 6 with TreeNode

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

the class JsonTreeTest method testInsertAndDeleteInSameRequest.

@Test
public void testInsertAndDeleteInSameRequest() throws Exception {
    // Note: A test for the same problem (but without a real tree) can be found here:
    // org.eclipse.scout.rt.client.ui.basic.tree.TreeEventBufferTest.testInsertAndRemoveInSameRequest()
    ITree tree = new Tree();
    tree.setRootNode(new TreeNode("Root"));
    final List<TreeEvent> treeEventCollector = new ArrayList<>();
    tree.addTreeListener(new TreeAdapter() {

        @Override
        public void treeChanged(TreeEvent e) {
            treeEventCollector.add(e);
        }
    });
    IJsonAdapter<? super ITree> jsonTree = m_uiSession.createJsonAdapter(tree, null);
    m_uiSession.currentJsonResponse().addAdapter(jsonTree);
    JSONObject response = m_uiSession.currentJsonResponse().toJson();
    System.out.println("Response #1: " + response);
    JsonTestUtility.endRequest(m_uiSession);
    // ----------------
    // (root)
    // +-[A]
    // +-[B]
    ITreeNode nodeA = new TreeNode("A");
    ITreeNode nodeB = new TreeNode("B");
    // Insert A and B in one "tree changing" batch
    // -> TreeEventBuffer should remove the second event (because B is a sub-node of A)
    tree.setTreeChanging(true);
    tree.addChildNode(tree.getRootNode(), nodeA);
    tree.addChildNode(nodeA, nodeB);
    tree.setTreeChanging(false);
    assertEquals(1, treeEventCollector.size());
    treeEventCollector.clear();
    // Remove B, then A (in two separate calls)
    // -> TreeEventBuffer should remove the second event (because B is a sub-node of A), altough
    // only an insertion event for A exists (and A.getChildNodes() returns nothing)
    tree.removeAllChildNodes(nodeA);
    tree.removeAllChildNodes(tree.getRootNode());
    assertEquals(2, treeEventCollector.size());
    treeEventCollector.clear();
    assertEquals(0, nodeA.getChildNodeCount());
    assertEquals(0, tree.getRootNode().getChildNodeCount());
    // Process the buffer
    // -> TreeEventBuffer should remove all events
    JsonTestUtility.processBufferedEvents(m_uiSession);
    List<JsonEvent> events = m_uiSession.currentJsonResponse().getEventList();
    assertEquals(0, events.size());
    response = m_uiSession.currentJsonResponse().toJson();
    System.out.println("Response #2: " + response);
    JsonTestUtility.endRequest(m_uiSession);
}
Also used : ArrayList(java.util.ArrayList) JsonEvent(org.eclipse.scout.rt.ui.html.json.JsonEvent) ITree(org.eclipse.scout.rt.client.ui.basic.tree.ITree) TreeAdapter(org.eclipse.scout.rt.client.ui.basic.tree.TreeAdapter) TreeEvent(org.eclipse.scout.rt.client.ui.basic.tree.TreeEvent) ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode) JSONObject(org.json.JSONObject) ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode) TreeNode(org.eclipse.scout.rt.ui.html.json.tree.fixtures.TreeNode) Tree(org.eclipse.scout.rt.ui.html.json.tree.fixtures.Tree) ITree(org.eclipse.scout.rt.client.ui.basic.tree.ITree) Test(org.junit.Test)

Example 7 with TreeNode

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

the class JsonTreeTest method testChildNodeDisposal.

@Test
public void testChildNodeDisposal() throws JSONException {
    List<ITreeNode> nodes = new ArrayList<ITreeNode>();
    nodes.add(new TreeNode());
    nodes.add(new TreeNode());
    nodes.add(new TreeNode());
    TreeNode child0 = new TreeNode();
    TreeNode child1 = new TreeNode();
    ITree tree = createTree(nodes);
    tree.addChildNode(nodes.get(0), child0);
    tree.addChildNode(nodes.get(0), child1);
    JsonTree<ITree> jsonTree = m_uiSession.createJsonAdapter(tree, null);
    String child0Id = jsonTree.getOrCreateNodeId(child0);
    assertNotNull(child0Id);
    assertNotNull(jsonTree.optTreeNodeForNodeId(child0Id));
    assertEquals(nodes.get(0), jsonTree.getParentNode(child0));
    assertEquals(2, jsonTree.getChildNodes(nodes.get(0)).size());
    tree.removeNode(child0);
    JsonTestUtility.processBufferedEvents(m_uiSession);
    assertNull(jsonTree.optNodeId(child0));
    assertNull(jsonTree.optTreeNodeForNodeId(child0Id));
    assertNull(jsonTree.getParentNode(child0));
    assertEquals(1, 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 8 with TreeNode

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

the class JsonTreeTest method testAllNodesUnchecked.

/**
 * Test for ticket 218516. When autoCheckChildNodes is set to true the JSON layer should send the state of all child
 * nodes for a given parent node.
 */
@Test
public void testAllNodesUnchecked() throws Exception {
    ITree tree = new Tree();
    tree.setRootNode(new TreeNode("Root"));
    tree.setAutoCheckChildNodes(true);
    tree.setCheckable(true);
    ITreeNode parent = new TreeNode("Parent");
    parent.setParentNodeInternal(tree.getRootNode());
    ITreeNode child1 = new TreeNode("Child1");
    child1.setParentNodeInternal(parent);
    ITreeNode child2 = new TreeNode("Child2");
    child2.setParentNodeInternal(parent);
    tree.addChildNode(tree.getRootNode(), parent);
    tree.addChildNode(parent, child1);
    tree.addChildNode(parent, child2);
    // set tree state before we start with the test case
    m_uiSession.createJsonAdapter(tree, null);
    tree.setNodeChecked(parent, true);
    assertTrue(child1.isChecked());
    assertTrue(child2.isChecked());
    JsonTestUtility.endRequest(m_uiSession);
    // <-- test case
    tree.setNodeChecked(parent, false);
    JsonTestUtility.processBufferedEvents(m_uiSession);
    List<JsonEvent> events = m_uiSession.currentJsonResponse().getEventList();
    assertEquals(1, events.size());
    JsonEvent event = events.get(0);
    assertEquals("nodesChecked", event.getType());
    JSONArray nodes = event.getData().getJSONArray("nodes");
    assertEquals(3, nodes.length());
    for (int i = 0; i < nodes.length(); i++) {
        JSONObject jsonNode = (JSONObject) nodes.get(i);
        assertFalse(jsonNode.getBoolean("checked"));
    }
}
Also used : ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode) JSONObject(org.json.JSONObject) ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode) TreeNode(org.eclipse.scout.rt.ui.html.json.tree.fixtures.TreeNode) JSONArray(org.json.JSONArray) Tree(org.eclipse.scout.rt.ui.html.json.tree.fixtures.Tree) ITree(org.eclipse.scout.rt.client.ui.basic.tree.ITree) JsonEvent(org.eclipse.scout.rt.ui.html.json.JsonEvent) ITree(org.eclipse.scout.rt.client.ui.basic.tree.ITree) Test(org.junit.Test)

Example 9 with TreeNode

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

the class JsonTreeTest method testAllNodesDeletedEvent.

/**
 * Tests whether an all nodes deleted event gets sent whenever all children of a node get deleted.
 */
@Test
public void testAllNodesDeletedEvent() throws JSONException {
    List<ITreeNode> nodes = new ArrayList<ITreeNode>();
    nodes.add(new TreeNode());
    nodes.add(new TreeNode());
    nodes.add(new TreeNode());
    ITree tree = createTree(nodes);
    m_uiSession.createJsonAdapter(tree, null);
    tree.removeChildNodes(tree.getRootNode(), tree.getRootNode().getChildNodes());
    List<JsonEvent> responseEvents = JsonTestUtility.extractEventsFromResponse(m_uiSession.currentJsonResponse(), JsonTree.EVENT_ALL_CHILD_NODES_DELETED);
    JsonEvent event = responseEvents.get(0);
    assertNull(event.getData().optJSONArray("nodeIds"));
}
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) JsonEvent(org.eclipse.scout.rt.ui.html.json.JsonEvent) ITree(org.eclipse.scout.rt.client.ui.basic.tree.ITree) Test(org.junit.Test)

Example 10 with TreeNode

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

the class JsonTreeTest method testMultipleFilterChanged.

@Test
public void testMultipleFilterChanged() throws Exception {
    // (root)
    // +-(node)
    // |   +-(node)
    // |   |   +-(node)
    // |   |   +-(node)
    // |   +-(node)
    // +-(node)
    // |   +-(node)
    // +-(node)
    List<ITreeNode> nodes = new ArrayList<ITreeNode>();
    nodes.add(new TreeNode());
    nodes.add(new TreeNode());
    nodes.add(new TreeNode());
    ITree tree = createTree(nodes);
    tree.addChildNode(tree.getRootNode().getChildNode(0), new TreeNode());
    tree.addChildNode(tree.getRootNode().getChildNode(0), new TreeNode());
    TreeNode node0000 = new TreeNode();
    node0000.setEnabled(false);
    tree.addChildNode(tree.getRootNode().getChildNode(0).getChildNode(0), node0000);
    tree.addChildNode(tree.getRootNode().getChildNode(0).getChildNode(0), new TreeNode());
    tree.addChildNode(tree.getRootNode().getChildNode(1), new TreeNode());
    JsonTree<ITree> jsonTree = m_uiSession.createJsonAdapter(tree, null);
    m_uiSession.currentJsonResponse().addAdapter(jsonTree);
    JSONObject response = m_uiSession.currentJsonResponse().toJson();
    System.out.println("Response #1: " + response);
    String node0000Id = jsonTree.getNodeId(node0000);
    JsonTestUtility.endRequest(m_uiSession);
    // --------------------------------------
    // 3 events: filterChanged, nodeChanged, filterChanged
    // filterChanged events are converted to nodesDeleted event in JsonTree.
    // Because of coalesce the nodeChanged event will be removed (it is obsolete, because nodes are deleted and re-inserted later).
    tree.addNodeFilter(new ITreeNodeFilter() {

        @Override
        public boolean accept(ITreeNode node, int level) {
            return node.isEnabled();
        }
    });
    node0000.getCellForUpdate().setText("Test-Text");
    tree.applyNodeFilters();
    response = m_uiSession.currentJsonResponse().toJson();
    System.out.println("Response #2: " + response);
    List<JsonEvent> events = m_uiSession.currentJsonResponse().getEventList();
    assertEquals(1, events.size());
    assertEventTypeAndNodeIds(events.get(0), "nodesDeleted", node0000Id);
}
Also used : 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) ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode) JSONObject(org.json.JSONObject) ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode) TreeNode(org.eclipse.scout.rt.ui.html.json.tree.fixtures.TreeNode) 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