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