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"));
}
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));
}
}
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());
}
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);
}
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);
}
Aggregations