use of org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode in project scout.rt by eclipse.
the class JsonTreeTest method testMultipleMenuDisposallOnPropertyChange.
@Test
public void testMultipleMenuDisposallOnPropertyChange() 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();
Menu menu2 = new Menu();
tree.getContextMenu().addChildAction(menu1);
tree.getContextMenu().addChildAction(menu2);
assertNotNull(jsonTree.getAdapter(menu1));
assertTrue(jsonTree.getAdapter(menu1).isInitialized());
assertNotNull(jsonTree.getAdapter(menu2));
assertTrue(jsonTree.getAdapter(menu2).isInitialized());
tree.getContextMenu().removeChildAction(menu1);
assertNull(jsonTree.getAdapter(menu1));
assertNotNull(jsonTree.getAdapter(menu2));
assertTrue(jsonTree.getAdapter(menu2).isInitialized());
}
use of org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode 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.ITreeNode in project scout.rt by eclipse.
the class JsonTreeTest method testInsertAndDeleteInSameRequest.
@Test
public void testInsertAndDeleteInSameRequest() throws Exception {
// Note: A test for the same problem (but without a real tree) can be found here:
// org.eclipse.scout.rt.client.ui.basic.tree.TreeEventBufferTest.testInsertAndRemoveInSameRequest()
ITree tree = new Tree();
tree.setRootNode(new TreeNode("Root"));
final List<TreeEvent> treeEventCollector = new ArrayList<>();
tree.addTreeListener(new TreeAdapter() {
@Override
public void treeChanged(TreeEvent e) {
treeEventCollector.add(e);
}
});
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);
// ----------------
// (root)
// +-[A]
// +-[B]
ITreeNode nodeA = new TreeNode("A");
ITreeNode nodeB = new TreeNode("B");
// Insert A and B in one "tree changing" batch
// -> TreeEventBuffer should remove the second event (because B is a sub-node of A)
tree.setTreeChanging(true);
tree.addChildNode(tree.getRootNode(), nodeA);
tree.addChildNode(nodeA, nodeB);
tree.setTreeChanging(false);
assertEquals(1, treeEventCollector.size());
treeEventCollector.clear();
// Remove B, then A (in two separate calls)
// -> TreeEventBuffer should remove the second event (because B is a sub-node of A), altough
// only an insertion event for A exists (and A.getChildNodes() returns nothing)
tree.removeAllChildNodes(nodeA);
tree.removeAllChildNodes(tree.getRootNode());
assertEquals(2, treeEventCollector.size());
treeEventCollector.clear();
assertEquals(0, nodeA.getChildNodeCount());
assertEquals(0, tree.getRootNode().getChildNodeCount());
// Process the buffer
// -> TreeEventBuffer should remove all events
JsonTestUtility.processBufferedEvents(m_uiSession);
List<JsonEvent> events = m_uiSession.currentJsonResponse().getEventList();
assertEquals(0, events.size());
response = m_uiSession.currentJsonResponse().toJson();
System.out.println("Response #2: " + response);
JsonTestUtility.endRequest(m_uiSession);
}
use of org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode in project scout.rt by eclipse.
the class AbstractTreeBox method syncTreeToValue.
@SuppressWarnings("unchecked")
private void syncTreeToValue() {
if (m_valueTreeSyncActive) {
return;
}
boolean resync = false;
try {
m_valueTreeSyncActive = true;
getTree().setTreeChanging(true);
//
Collection<ITreeNode> checkedNodes;
if (getTree().isCheckable()) {
checkedNodes = m_tree.getCheckedNodes();
} else {
checkedNodes = m_tree.getSelectedNodes();
}
Set<T> checkedKeys = new HashSet<T>();
for (ITreeNode checkedNode : checkedNodes) {
checkedKeys.add((T) checkedNode.getPrimaryKey());
}
checkKeys(checkedKeys);
// Due to validate logic, the actual value
// may differ now, making a resync of the value is necessary
Set<T> validatedCheckedKeys = getCheckedKeys();
if (!CollectionUtility.equalsCollection(checkedKeys, validatedCheckedKeys)) {
resync = true;
}
if (!getTree().isCheckable()) {
// checks follow selection
getTree().visitTree(new ITreeVisitor() {
@Override
public boolean visit(ITreeNode node) {
node.setChecked(node.isSelectedNode());
return true;
}
});
}
getTree().applyNodeFilters();
} finally {
getTree().setTreeChanging(false);
m_valueTreeSyncActive = false;
}
if (resync) {
// The value of the treeBox is different
// from the one represented in the tree.
// Need to sync.
syncValueToTree();
}
}
use of org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode in project scout.rt by eclipse.
the class AbstractTreeBox method filterNewNodesRec.
private void filterNewNodesRec(List<ITreeNode> nodes, int level) {
if (nodes != null) {
for (ITreeNode node : nodes) {
if (node != null) {
interceptFilterNewNode(node, level);
filterNewNodesRec(node.getChildNodes(), level + 1);
}
}
}
}
Aggregations