use of org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode in project scout.rt by eclipse.
the class JsonTreeTest method testDeletionOfAllChildrenOfUnknownNode.
@Test
public void testDeletionOfAllChildrenOfUnknownNode() throws Exception {
IOutline outline = new Outline(new ArrayList<IPage<?>>());
ITreeNode parent = new TablePage(0);
ITreeNode node1 = new TablePage(0);
node1.setParentNodeInternal(parent);
ITreeNode node2 = new TablePage(0);
node2.setParentNodeInternal(parent);
ITreeNode node3 = new TablePage(0);
node3.setParentNodeInternal(parent);
outline.addChildNode(outline.getRootNode(), parent);
outline.addChildNode(parent, node1);
outline.addChildNode(parent, node2);
outline.addChildNode(parent, node3);
JsonOutline<IOutline> jsonOutline = m_uiSession.createJsonAdapter(outline, null);
List<ITreeNode> allChildren = CollectionUtility.arrayList(node1, node2, node3);
jsonOutline.bufferModelEvent(new TreeEvent(outline, TreeEvent.TYPE_ALL_CHILD_NODES_DELETED, parent, allChildren));
try {
jsonOutline.processBufferedEvents();
} catch (UiException e) {
fail("Regression of ticket 210096: Tree does not contain node whose children are to be deleted.");
}
}
use of org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode 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"));
}
}
use of org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode 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"));
}
use of org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode 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);
}
use of org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode in project scout.rt by eclipse.
the class JsonTreeTest method testMenuDisposalOnPropertyChange.
@Test
public void testMenuDisposalOnPropertyChange() throws JSONException {
ITree tree = createTreeWithOneNode();
ITreeNode node = tree.getRootNode().getChildNode(0);
assertFalse(node.isSelectedNode());
JsonTree<ITree> jsonTree = m_uiSession.createJsonAdapter(tree, null);
Menu menu1 = new Menu();
tree.getContextMenu().addChildAction(menu1);
assertNotNull(jsonTree.getAdapter(menu1));
assertTrue(jsonTree.getAdapter(menu1).isInitialized());
tree.getContextMenu().removeChildAction(menu1);
assertNull(jsonTree.getAdapter(menu1));
}
Aggregations