Search in sources :

Example 21 with ITreeNode

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());
}
Also used : ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode) ITree(org.eclipse.scout.rt.client.ui.basic.tree.ITree) Menu(org.eclipse.scout.rt.ui.html.json.menu.fixtures.Menu) Test(org.junit.Test)

Example 22 with ITreeNode

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);
}
Also used : ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode) ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode) TreeNode(org.eclipse.scout.rt.ui.html.json.tree.fixtures.TreeNode) ITreeNodeFilter(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNodeFilter) ArrayList(java.util.ArrayList) JsonEvent(org.eclipse.scout.rt.ui.html.json.JsonEvent) ITree(org.eclipse.scout.rt.client.ui.basic.tree.ITree) Test(org.junit.Test)

Example 23 with ITreeNode

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);
}
Also used : ArrayList(java.util.ArrayList) JsonEvent(org.eclipse.scout.rt.ui.html.json.JsonEvent) ITree(org.eclipse.scout.rt.client.ui.basic.tree.ITree) TreeAdapter(org.eclipse.scout.rt.client.ui.basic.tree.TreeAdapter) TreeEvent(org.eclipse.scout.rt.client.ui.basic.tree.TreeEvent) ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode) JSONObject(org.json.JSONObject) ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode) TreeNode(org.eclipse.scout.rt.ui.html.json.tree.fixtures.TreeNode) Tree(org.eclipse.scout.rt.ui.html.json.tree.fixtures.Tree) ITree(org.eclipse.scout.rt.client.ui.basic.tree.ITree) Test(org.junit.Test)

Example 24 with ITreeNode

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();
    }
}
Also used : ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode) HashSet(java.util.HashSet) ITreeVisitor(org.eclipse.scout.rt.client.ui.basic.tree.ITreeVisitor)

Example 25 with ITreeNode

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);
            }
        }
    }
}
Also used : ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode)

Aggregations

ITreeNode (org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode)95 Test (org.junit.Test)34 ITree (org.eclipse.scout.rt.client.ui.basic.tree.ITree)29 ArrayList (java.util.ArrayList)23 ITreeVisitor (org.eclipse.scout.rt.client.ui.basic.tree.ITreeVisitor)16 JSONObject (org.json.JSONObject)14 TreeNode (org.eclipse.scout.rt.ui.html.json.tree.fixtures.TreeNode)12 JsonEvent (org.eclipse.scout.rt.ui.html.json.JsonEvent)11 JSONArray (org.json.JSONArray)10 HashSet (java.util.HashSet)9 IPage (org.eclipse.scout.rt.client.ui.desktop.outline.pages.IPage)6 EitherOrNode (org.eclipse.scout.rt.client.ui.form.fields.composer.node.EitherOrNode)6 IMenu (org.eclipse.scout.rt.client.ui.action.menu.IMenu)5 TreeEvent (org.eclipse.scout.rt.client.ui.basic.tree.TreeEvent)5 IOutline (org.eclipse.scout.rt.client.ui.desktop.outline.IOutline)5 LinkedList (java.util.LinkedList)4 ITableRow (org.eclipse.scout.rt.client.ui.basic.table.ITableRow)4 IDesktop (org.eclipse.scout.rt.client.ui.desktop.IDesktop)4 ITreeNodeFilter (org.eclipse.scout.rt.client.ui.basic.tree.ITreeNodeFilter)3 StyleField (org.eclipse.scout.rt.client.ui.form.fields.smartfield.SmartFieldTest.TestForm.MainBox.StyleField)3