Search in sources :

Example 21 with ITree

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

the class IncrementalTreeBuilderTest method testCreatePaths_NullKeyLookupRow.

@Test
public void testCreatePaths_NullKeyLookupRow() {
    final Map<Long, ILookupRow<Long>> lookupRowsMap = new HashMap<>();
    lookupRowsMap.put(1L, new LookupRow<Long>(1L, "A"));
    lookupRowsMap.put(2L, new LookupRow<Long>(2L, "A-B").withParentKey(1L));
    lookupRowsMap.put(null, new LookupRow<Long>(null, "(none)"));
    Collection<ILookupRow<Long>> rows = lookupRowsMap.values();
    IKeyLookupProvider<Long> provider = new IKeyLookupProvider<Long>() {

        @Override
        public ILookupRow<Long> getLookupRow(Long key) {
            return lookupRowsMap.get(key);
        }
    };
    ITree tree = createTestTree();
    IncrementalTreeBuilder<Long> builder = new IncrementalTreeBuilder<Long>(provider);
    List<List<ILookupRow<Long>>> paths = builder.createPaths(rows, tree);
    assertEquals(3, paths.size());
}
Also used : ILookupRow(org.eclipse.scout.rt.shared.services.lookup.ILookupRow) LookupRow(org.eclipse.scout.rt.shared.services.lookup.LookupRow) ILookupRow(org.eclipse.scout.rt.shared.services.lookup.ILookupRow) HashMap(java.util.HashMap) ITree(org.eclipse.scout.rt.client.ui.basic.tree.ITree) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 22 with ITree

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

the class SmartFieldTest method testHierarchicalOpenProposal.

@Test
public void testHierarchicalOpenProposal() {
    StyleField f = m_styleField;
    f.setBrowseHierarchy(true);
    f.setValue(10L);
    f.getUIFacade().openProposalChooserFromUI("Red", false, true);
    waitForProposalResult(IProposalChooser.PROP_SEARCH_RESULT);
    // single result
    assertTrue(m_styleField.isProposalChooserRegistered());
    assertEquals("Red", m_styleField.getDisplayText());
    // verifies tree is loaded containing a single node
    @SuppressWarnings("unchecked") TreeProposalChooser<Long> treeProposalChooser = (TreeProposalChooser<Long>) f.getProposalChooser();
    ITree tree = treeProposalChooser.getModel();
    ITreeNode rootNode = tree.getRootNode();
    assertEquals(5, rootNode.getChildNodes().size());
    assertEquals("Red", rootNode.getChildNode(0).getCell().getText());
    // current value should be selected
    assertTrue(rootNode.getChildNode(0).isSelectedNode());
}
Also used : ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode) ITree(org.eclipse.scout.rt.client.ui.basic.tree.ITree) StyleField(org.eclipse.scout.rt.client.ui.form.fields.smartfield.SmartFieldTest.TestForm.MainBox.StyleField) Test(org.junit.Test)

Example 23 with ITree

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

the class TreeBoxTest method testAutoSelectBehavior.

/**
 * Select a parent node in a tree box with auto check child nodes activated, and check whether this node and all child
 * nodes are selected. {@link AbstractTreeBox#getConfiguredAutoCheckChildNodes} returns true on the
 * {@link AutoSelectTreeBox}. Bug 368107 - Check child nodes when parent node is checked
 */
@Test
public void testAutoSelectBehavior() throws Exception {
    AutoSelectTreeBox treeBox = new AutoSelectTreeBox();
    treeBox.initField();
    ITree tree = treeBox.getTree();
    // A
    ITreeNode node = tree.findNode(1L);
    assertNotNull(node);
    tree.setNodeChecked(node, true);
    Set<Long> valueSet = new HashSet<Long>(treeBox.getValue());
    // parent node and 3 childs nodes selected
    assertEquals(4, valueSet.size());
    // and the selected ones are correct
    // A
    assertEquals(true, valueSet.contains(1L));
    // A-A
    assertEquals(true, valueSet.contains(5L));
    // A-B
    assertEquals(true, valueSet.contains(6L));
    // A-C
    assertEquals(true, valueSet.contains(7L));
}
Also used : ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode) ITree(org.eclipse.scout.rt.client.ui.basic.tree.ITree) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 24 with ITree

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

the class TreeBoxTest method testDefaultBehavior.

/**
 * Select a parent node in a tree box and check whether only this node is selected..
 * {@link AbstractTreeBox#getConfiguredAutoCheckChildNodes} returns false on the {@link SimpleTreeBox}. Bug 368107 -
 * Check child nodes when parent node is checked
 */
@Test
public void testDefaultBehavior() throws Exception {
    SimpleTreeBox treeBox = createSimpleTreeBox();
    ITree tree = treeBox.getTree();
    // A
    ITreeNode node = tree.findNode(1L);
    assertNotNull(node);
    tree.setNodeChecked(node, true);
    Set<Long> valueSet = new HashSet<Long>(treeBox.getValue());
    // only one node selected
    assertEquals(1, valueSet.size());
    // and the selected one is the node explicitly set before
    // A
    assertEquals(true, valueSet.contains(1L));
}
Also used : ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode) ITree(org.eclipse.scout.rt.client.ui.basic.tree.ITree) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 25 with ITree

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

the class AbstractPage method setTreeInternal.

@Override
public void setTreeInternal(ITree tree, boolean includeSubtree) {
    ITree oldTree = getTree();
    if (oldTree != null) {
        oldTree.removeTreeListener(m_treeListener);
    }
    super.setTreeInternal(tree, includeSubtree);
    if (tree == null) {
        return;
    }
    tree.addTreeListener(m_treeListener, TreeEvent.TYPE_NODES_UPDATED);
}
Also used : ITree(org.eclipse.scout.rt.client.ui.basic.tree.ITree)

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