Search in sources :

Example 16 with ITreeNode

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));
}
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) ITree(org.eclipse.scout.rt.client.ui.basic.tree.ITree) Test(org.junit.Test)

Example 17 with ITreeNode

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

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

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

Example 20 with ITreeNode

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());
}
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) ArrayList(java.util.ArrayList) ITree(org.eclipse.scout.rt.client.ui.basic.tree.ITree) Test(org.junit.Test)

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