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