Search in sources :

Example 81 with ITreeNode

use of org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode 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 82 with ITreeNode

use of org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode in project scout.rt by eclipse.

the class JsonTreeTest method testNodeDisposalRec.

// @Test
// public void testNodeAndUserFilter() throws JSONException {
// TreeNode node0 = new TreeNode();
// TreeNode node1 = new TreeNode();
// TreeNode node2 = new TreeNode();
// List<ITreeNode> nodes = new ArrayList<ITreeNode>();
// nodes.add(node0);
// nodes.add(node1);
// nodes.add(node2);
// 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.getNode(node0Id));
// 
// node0.setEnabled(false);
// tree.addNodeFilter(new ITreeNodeFilter() {
// 
// @Override
// public boolean accept(ITreeNode node, int level) {
// return node.isEnabled();
// }
// });
// 
// JsonEvent event = createJsonRowsFilteredEvent(row0Id, row2Id);
// jsonTree.handleUiEvent(event);
// 
// JsonTestUtility.processBufferedEvents(m_uiSession);
// assertNull(jsonTree.getNodeId(nodes.get(0)));
// assertNull(jsonTree.getNode(node0Id));
// 
// List<JsonEvent> events = m_uiSession.currentJsonResponse().getEventList();
// assertEquals(1, events.size());
// assertEventTypeAndNodeIds(events.get(0), "nodesDeleted", node0Id);
// }
/**
 * Tests whether the child nodes gets removed from the maps after deletion (m_treeNodes, m_treeNodeIds)
 */
@Test
public void testNodeDisposalRec() throws JSONException {
    ITree tree = new TreeWith3Levels();
    tree.initTree();
    List<ITreeNode> allNodes = getAllTreeNodes(tree);
    List<String> allNodeIds = new LinkedList<String>();
    JsonTree<ITree> jsonTree = m_uiSession.createJsonAdapter(tree, null);
    for (ITreeNode node : allNodes) {
        String nodeId = jsonTree.getOrCreateNodeId(node);
        allNodeIds.add(nodeId);
        assertNotNull(nodeId);
        assertNotNull(jsonTree.optTreeNodeForNodeId(nodeId));
        assertNotNull(jsonTree.getParentNode(node));
    }
    tree.removeNode(allNodes.get(0));
    JsonTestUtility.processBufferedEvents(m_uiSession);
    for (ITreeNode node : allNodes) {
        assertNull(jsonTree.optNodeId(node));
        assertNull(jsonTree.getParentNode(node));
        assertEquals(0, jsonTree.getChildNodes(node).size());
    }
    for (String nodeId : allNodeIds) {
        assertNull(jsonTree.optTreeNodeForNodeId(nodeId));
    }
}
Also used : ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode) ITree(org.eclipse.scout.rt.client.ui.basic.tree.ITree) TreeWith3Levels(org.eclipse.scout.rt.ui.html.json.tree.fixtures.TreeWith3Levels) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 83 with ITreeNode

use of org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode in project scout.rt by eclipse.

the class JsonTreeTest method testSelectionEvent.

/**
 * Tests whether the model node gets correctly selected
 */
@Test
public void testSelectionEvent() throws JSONException {
    ITree tree = createTreeWithOneNode();
    ITreeNode node = tree.getRootNode().getChildNode(0);
    assertFalse(node.isSelectedNode());
    JsonTree<ITree> jsonTree = m_uiSession.createJsonAdapter(tree, null);
    JsonEvent event = createJsonSelectedEvent(jsonTree.getOrCreateNodeId(node));
    jsonTree.handleUiEvent(event);
    assertTrue(node.isSelectedNode());
}
Also used : ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode) JsonEvent(org.eclipse.scout.rt.ui.html.json.JsonEvent) ITree(org.eclipse.scout.rt.client.ui.basic.tree.ITree) Test(org.junit.Test)

Example 84 with ITreeNode

use of org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode in project scout.rt by eclipse.

the class JsonTreeTest method testIgnorableExpansionEvent.

/**
 * If the selection event triggers the selection of another node, the selection event must not be ignored.
 */
// TODO [7.0] cgu: Test fails due to scout model bug: selectNode puts first selection event AFTER this new selection event -> gets filtered in processEventBuffers. With table it works though.
// @Test
// public void testIgnorableSelectionEvent2() throws JSONException {
// List<ITreeNode> nodes = new LinkedList<>();
// final TreeNode firstNode = new TreeNode();
// final TreeNode secondNode = new TreeNode();
// 
// nodes.add(firstNode);
// nodes.add(secondNode);
// ITree tree = new Tree(nodes) {
// 
// @Override
// protected void execNodesSelected(TreeEvent e) {
// if (e.getNode().equals(secondNode)) {
// selectNode(firstNode);
// }
// }
// };
// tree.initTree();
// 
// JsonTree<ITree> jsonTree = m_uiSession.createJsonAdapter(tree, null);
// JsonEvent event = createJsonSelectedEvent(jsonTree.getOrCreateNodeId(secondNode));
// 
// assertFalse(firstNode.isSelectedNode());
// assertFalse(secondNode.isSelectedNode());
// 
// jsonTree.handleUiEvent(event);
// 
// assertTrue(firstNode.isSelectedNode());
// assertFalse(secondNode.isSelectedNode());
// 
// List<JsonEvent> responseEvents = JsonTestUtility.extractEventsFromResponse(
// m_uiSession.currentJsonResponse(), JsonTree.EVENT_NODES_SELECTED);
// assertTrue(responseEvents.size() == 1);
// 
// List<ITreeNode> treeNodes = jsonTree.extractTreeNodes(responseEvents.get(0).getData());
// assertEquals(firstNode, treeNodes.get(0));
// }
/**
 * Response must not contain the expansion event if the expansion was triggered by the request
 */
@Test
public void testIgnorableExpansionEvent() throws JSONException {
    ITree tree = createTreeWithOneNode();
    ITreeNode node = tree.getRootNode().getChildNode(0);
    JsonTree<ITree> jsonTree = m_uiSession.createJsonAdapter(tree, null);
    // Check expanded = true
    JsonEvent event = createJsonExpansionEvent(jsonTree.getOrCreateNodeId(node), true);
    jsonTree.handleUiEvent(event);
    List<JsonEvent> responseEvents = JsonTestUtility.extractEventsFromResponse(m_uiSession.currentJsonResponse(), JsonTree.EVENT_NODE_EXPANDED);
    assertTrue(responseEvents.size() == 0);
    // Check expanded = false
    event = createJsonExpansionEvent(jsonTree.getOrCreateNodeId(node), false);
    jsonTree.handleUiEvent(event);
    responseEvents = JsonTestUtility.extractEventsFromResponse(m_uiSession.currentJsonResponse(), JsonTree.EVENT_NODE_EXPANDED);
    assertTrue(responseEvents.size() == 0);
}
Also used : ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode) JsonEvent(org.eclipse.scout.rt.ui.html.json.JsonEvent) ITree(org.eclipse.scout.rt.client.ui.basic.tree.ITree) Test(org.junit.Test)

Example 85 with ITreeNode

use of org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode 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)

Aggregations

ITreeNode (org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode)95 Test (org.junit.Test)34 ITree (org.eclipse.scout.rt.client.ui.basic.tree.ITree)29 ArrayList (java.util.ArrayList)23 ITreeVisitor (org.eclipse.scout.rt.client.ui.basic.tree.ITreeVisitor)16 JSONObject (org.json.JSONObject)14 TreeNode (org.eclipse.scout.rt.ui.html.json.tree.fixtures.TreeNode)12 JsonEvent (org.eclipse.scout.rt.ui.html.json.JsonEvent)11 JSONArray (org.json.JSONArray)10 HashSet (java.util.HashSet)9 IPage (org.eclipse.scout.rt.client.ui.desktop.outline.pages.IPage)6 EitherOrNode (org.eclipse.scout.rt.client.ui.form.fields.composer.node.EitherOrNode)6 IMenu (org.eclipse.scout.rt.client.ui.action.menu.IMenu)5 TreeEvent (org.eclipse.scout.rt.client.ui.basic.tree.TreeEvent)5 IOutline (org.eclipse.scout.rt.client.ui.desktop.outline.IOutline)5 LinkedList (java.util.LinkedList)4 ITableRow (org.eclipse.scout.rt.client.ui.basic.table.ITableRow)4 IDesktop (org.eclipse.scout.rt.client.ui.desktop.IDesktop)4 ITreeNodeFilter (org.eclipse.scout.rt.client.ui.basic.tree.ITreeNodeFilter)3 StyleField (org.eclipse.scout.rt.client.ui.form.fields.smartfield.SmartFieldTest.TestForm.MainBox.StyleField)3