Search in sources :

Example 11 with TreeNode

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

the class JsonTreeTest method testTreeExpandedRecursive.

@Test
public void testTreeExpandedRecursive() 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());
    tree.addChildNode(tree.getRootNode().getChildNode(0).getChildNode(0), new TreeNode());
    tree.addChildNode(tree.getRootNode().getChildNode(0).getChildNode(0), new TreeNode());
    tree.addChildNode(tree.getRootNode().getChildNode(1), new TreeNode());
    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);
    // --------------------------------------
    tree.expandAll(tree.getRootNode());
    response = m_uiSession.currentJsonResponse().toJson();
    System.out.println("Response #2: " + response);
    List<JsonEvent> events = m_uiSession.currentJsonResponse().getEventList();
    assertEquals(3, events.size());
    assertEquals("nodeExpanded", events.get(0).getType());
    assertEquals(true, events.get(0).getData().optBoolean("expanded"));
    assertEquals(true, events.get(0).getData().optBoolean("recursive"));
    assertEquals("nodeExpanded", events.get(1).getType());
    assertEquals(true, events.get(1).getData().optBoolean("expanded"));
    assertEquals(true, events.get(1).getData().optBoolean("recursive"));
    assertEquals("nodeExpanded", events.get(2).getType());
    assertEquals(true, events.get(2).getData().optBoolean("expanded"));
    assertEquals(true, events.get(2).getData().optBoolean("recursive"));
    JsonTestUtility.endRequest(m_uiSession);
    // --------------------------------------
    tree.collapseAll(tree.getRootNode().getChildNode(0));
    response = m_uiSession.currentJsonResponse().toJson();
    System.out.println("Response #3: " + response);
    events = m_uiSession.currentJsonResponse().getEventList();
    assertEquals(1, events.size());
    assertEquals("nodeExpanded", events.get(0).getType());
    assertEquals(false, events.get(0).getData().optBoolean("expanded"));
    assertEquals(true, events.get(0).getData().optBoolean("recursive"));
}
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) 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 12 with TreeNode

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

the class JsonTreeTest method testNodesDeletedEvent.

/**
 * Tests whether a deletion event with correct node id gets sent whenever a node gets deleted.
 */
@Test
public void testNodesDeletedEvent() 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 node1Id = jsonTree.getOrCreateNodeId(nodes.get(1));
    tree.removeNode(nodes.get(1));
    List<JsonEvent> responseEvents = JsonTestUtility.extractEventsFromResponse(m_uiSession.currentJsonResponse(), JsonTree.EVENT_NODES_DELETED);
    assertTrue(responseEvents.size() == 1);
    assertEventTypeAndNodeIds(responseEvents.get(0), "nodesDeleted", node1Id);
}
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 13 with TreeNode

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

the class JsonTreeTest method testGetVsOpt.

@Test
public void testGetVsOpt() {
    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);
    assertEquals(node0Id, jsonTree.optNodeId(nodes.get(0)));
    assertEquals(node0Id, jsonTree.getNodeId(nodes.get(0)));
    assertNotNull(jsonTree.optTreeNodeForNodeId(node0Id));
    assertNotNull(jsonTree.getTreeNodeForNodeId(node0Id));
    String nonExistingNodeId = "bla";
    ITreeNode nonExistingTreeNode = new TreeNode();
    assertNull(jsonTree.optNodeId(nonExistingTreeNode));
    try {
        jsonTree.getNodeId(nonExistingTreeNode);
        fail("Expected UiException");
    } catch (UiException e) {
    // ok
    }
    assertNull(jsonTree.optTreeNodeForNodeId(nonExistingNodeId));
    try {
        jsonTree.getTreeNodeForNodeId(nonExistingNodeId);
        fail("Expected UiException");
    } catch (UiException e) {
    // ok
    }
}
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) UiException(org.eclipse.scout.rt.ui.html.UiException) 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