Search in sources :

Example 41 with ITree

use of org.eclipse.scout.rt.client.ui.basic.tree.ITree in project scout.rt by eclipse.

the class JsonTreeTest method testAllNodesDeletedEvent.

/**
 * Tests whether an all nodes deleted event gets sent whenever all children of a node get deleted.
 */
@Test
public void testAllNodesDeletedEvent() throws JSONException {
    List<ITreeNode> nodes = new ArrayList<ITreeNode>();
    nodes.add(new TreeNode());
    nodes.add(new TreeNode());
    nodes.add(new TreeNode());
    ITree tree = createTree(nodes);
    m_uiSession.createJsonAdapter(tree, null);
    tree.removeChildNodes(tree.getRootNode(), tree.getRootNode().getChildNodes());
    List<JsonEvent> responseEvents = JsonTestUtility.extractEventsFromResponse(m_uiSession.currentJsonResponse(), JsonTree.EVENT_ALL_CHILD_NODES_DELETED);
    JsonEvent event = responseEvents.get(0);
    assertNull(event.getData().optJSONArray("nodeIds"));
}
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) JsonEvent(org.eclipse.scout.rt.ui.html.json.JsonEvent) ITree(org.eclipse.scout.rt.client.ui.basic.tree.ITree) Test(org.junit.Test)

Example 42 with ITree

use of org.eclipse.scout.rt.client.ui.basic.tree.ITree in project scout.rt by eclipse.

the class JsonTreeTest method testDispose.

@Test
public void testDispose() {
    ITree tree = new TreeWith3Levels();
    tree.initTree();
    JsonTree<ITree> object = UiSessionTestUtility.newJsonAdapter(m_uiSession, tree, null);
    WeakReference<JsonTree> ref = new WeakReference<JsonTree>(object);
    object.dispose();
    m_uiSession = null;
    object = null;
    TestingUtility.assertGC(ref);
}
Also used : WeakReference(java.lang.ref.WeakReference) ITree(org.eclipse.scout.rt.client.ui.basic.tree.ITree) TreeWith3Levels(org.eclipse.scout.rt.ui.html.json.tree.fixtures.TreeWith3Levels) Test(org.junit.Test)

Example 43 with ITree

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

Example 44 with ITree

use of org.eclipse.scout.rt.client.ui.basic.tree.ITree in project scout.rt by eclipse.

the class JsonTreeTest method testMenuDisposalOnPropertyChange.

@Test
public void testMenuDisposalOnPropertyChange() 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);
    assertNotNull(jsonTree.getAdapter(menu1));
    assertTrue(jsonTree.getAdapter(menu1).isInitialized());
    tree.getContextMenu().removeChildAction(menu1);
    assertNull(jsonTree.getAdapter(menu1));
}
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 45 with ITree

use of org.eclipse.scout.rt.client.ui.basic.tree.ITree in project scout.rt by eclipse.

the class JsonTreeTest method testTreeExpandedRecursive.

@Test
public void testTreeExpandedRecursive() 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());
    tree.addChildNode(tree.getRootNode().getChildNode(0).getChildNode(0), new TreeNode());
    tree.addChildNode(tree.getRootNode().getChildNode(0).getChildNode(0), new TreeNode());
    tree.addChildNode(tree.getRootNode().getChildNode(1), new TreeNode());
    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);
    // --------------------------------------
    tree.expandAll(tree.getRootNode());
    response = m_uiSession.currentJsonResponse().toJson();
    System.out.println("Response #2: " + response);
    List<JsonEvent> events = m_uiSession.currentJsonResponse().getEventList();
    assertEquals(3, events.size());
    assertEquals("nodeExpanded", events.get(0).getType());
    assertEquals(true, events.get(0).getData().optBoolean("expanded"));
    assertEquals(true, events.get(0).getData().optBoolean("recursive"));
    assertEquals("nodeExpanded", events.get(1).getType());
    assertEquals(true, events.get(1).getData().optBoolean("expanded"));
    assertEquals(true, events.get(1).getData().optBoolean("recursive"));
    assertEquals("nodeExpanded", events.get(2).getType());
    assertEquals(true, events.get(2).getData().optBoolean("expanded"));
    assertEquals(true, events.get(2).getData().optBoolean("recursive"));
    JsonTestUtility.endRequest(m_uiSession);
    // --------------------------------------
    tree.collapseAll(tree.getRootNode().getChildNode(0));
    response = m_uiSession.currentJsonResponse().toJson();
    System.out.println("Response #3: " + response);
    events = m_uiSession.currentJsonResponse().getEventList();
    assertEquals(1, events.size());
    assertEquals("nodeExpanded", events.get(0).getType());
    assertEquals(false, events.get(0).getData().optBoolean("expanded"));
    assertEquals(true, events.get(0).getData().optBoolean("recursive"));
}
Also used : 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) 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)

Aggregations

ITree (org.eclipse.scout.rt.client.ui.basic.tree.ITree)54 Test (org.junit.Test)40 ITreeNode (org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode)30 ArrayList (java.util.ArrayList)17 TreeNode (org.eclipse.scout.rt.ui.html.json.tree.fixtures.TreeNode)13 JsonEvent (org.eclipse.scout.rt.ui.html.json.JsonEvent)11 ILookupRow (org.eclipse.scout.rt.shared.services.lookup.ILookupRow)6 JSONObject (org.json.JSONObject)5 List (java.util.List)4 TreeEvent (org.eclipse.scout.rt.client.ui.basic.tree.TreeEvent)4 StyleField (org.eclipse.scout.rt.client.ui.form.fields.smartfield.SmartFieldTest.TestForm.MainBox.StyleField)4 PropertyChangeEvent (java.beans.PropertyChangeEvent)3 PropertyChangeListener (java.beans.PropertyChangeListener)3 HashSet (java.util.HashSet)3 ITreeNodeFilter (org.eclipse.scout.rt.client.ui.basic.tree.ITreeNodeFilter)3 TreeAdapter (org.eclipse.scout.rt.client.ui.basic.tree.TreeAdapter)3 IDesktop (org.eclipse.scout.rt.client.ui.desktop.IDesktop)3 WeakReference (java.lang.ref.WeakReference)2 IAction (org.eclipse.scout.rt.client.ui.action.IAction)2 IMenu (org.eclipse.scout.rt.client.ui.action.menu.IMenu)2