use of org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode 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.client.ui.basic.tree.ITreeNode 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.client.ui.basic.tree.ITreeNode in project scout.rt by eclipse.
the class JsonTreeTest method testMenusChangedEvent.
/**
* Tests whether a menus property change event gets sent for the json tree if the context menu changes
*/
@Test
public void testMenusChangedEvent() 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);
IJsonAdapter<?> jsonMenu1 = jsonTree.getAdapter(menu1);
assertNotNull(jsonMenu1);
assertTrue(jsonMenu1.isInitialized());
JSONArray jsonMenus = JsonTestUtility.extractProperty(m_uiSession.currentJsonResponse(), jsonTree.getId(), IJsonContextMenuOwner.PROP_MENUS);
assertNotNull(jsonMenus);
assertEquals(1, jsonMenus.length());
assertEquals(jsonMenu1.getId(), jsonMenus.get(0));
}
use of org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode in project scout.rt by eclipse.
the class JsonTreeTest method getAllTreeNodes.
public static List<ITreeNode> getAllTreeNodes(final ITree tree) {
final List<ITreeNode> nodes = new LinkedList<ITreeNode>();
tree.visitTree(new ITreeVisitor() {
@Override
public boolean visit(ITreeNode node) {
if (!tree.isRootNodeVisible() && tree.getRootNode() == node) {
return true;
}
nodes.add(node);
return true;
}
});
return nodes;
}
use of org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode 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());
}
Aggregations