Search in sources :

Example 6 with ITreeVisitor

use of org.eclipse.scout.rt.client.ui.basic.tree.ITreeVisitor 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 7 with ITreeVisitor

use of org.eclipse.scout.rt.client.ui.basic.tree.ITreeVisitor 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 8 with ITreeVisitor

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

the class AbstractTreeBox method loadChildNodes.

@Override
public final void loadChildNodes(ITreeNode parentNode) {
    if (m_tree != null) {
        try {
            m_valueTreeSyncActive = true;
            m_tree.setTreeChanging(true);
            // 
            interceptLoadChildNodes(parentNode);
            // when tree is non-incremental, mark all leaf cadidates as leafs
            if (!isLoadIncremental()) {
                ITreeVisitor v = new ITreeVisitor() {

                    @Override
                    public boolean visit(ITreeNode node) {
                        if (node.getChildNodeCount() == 0) {
                            node.setLeafInternal(true);
                        } else {
                            node.setLeafInternal(false);
                        }
                        return true;
                    }
                };
                getTree().visitNode(getTree().getRootNode(), v);
            }
            // auto-expand all
            if (isAutoExpandAll()) {
                m_tree.expandAll(parentNode);
            }
        } finally {
            m_tree.setTreeChanging(false);
            m_valueTreeSyncActive = false;
        }
        syncValueToTree();
    }
}
Also used : ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode) ITreeVisitor(org.eclipse.scout.rt.client.ui.basic.tree.ITreeVisitor)

Example 9 with ITreeVisitor

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

the class AbstractTreeBox method checkAllKeys.

@Override
public void checkAllKeys() {
    final Set<T> keySet = new HashSet<T>();
    ITreeVisitor v = new ITreeVisitor() {

        @SuppressWarnings("unchecked")
        @Override
        public boolean visit(ITreeNode node) {
            if (node.getPrimaryKey() != null) {
                keySet.add((T) node.getPrimaryKey());
            }
            return true;
        }
    };
    m_tree.visitNode(m_tree.getRootNode(), v);
    checkKeys(keySet);
}
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 10 with ITreeVisitor

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

the class IncrementalTreeBuilder method createParentMap.

/**
 * Creates a map containing every key in the tree and its parent tree node
 */
public Map<LOOKUP_KEY, ILookupRow<LOOKUP_KEY>> createParentMap(ITree tree) {
    final Map<LOOKUP_KEY, ILookupRow<LOOKUP_KEY>> map = new HashMap<>();
    tree.visitTree(new ITreeVisitor() {

        @Override
        public boolean visit(ITreeNode node) {
            ITreeNode parent = node.getParentNode();
            ILookupRow<LOOKUP_KEY> row = getLookupRow(node);
            if (row != null) {
                LOOKUP_KEY key = row.getKey();
                m_keyCache.put(key, row);
                map.put(key, getLookupRow(parent));
            }
            return true;
        }
    });
    return map;
}
Also used : ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode) ILookupRow(org.eclipse.scout.rt.shared.services.lookup.ILookupRow) HashMap(java.util.HashMap) ITreeVisitor(org.eclipse.scout.rt.client.ui.basic.tree.ITreeVisitor)

Aggregations

ITreeNode (org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode)16 ITreeVisitor (org.eclipse.scout.rt.client.ui.basic.tree.ITreeVisitor)16 HashSet (java.util.HashSet)4 IPage (org.eclipse.scout.rt.client.ui.desktop.outline.pages.IPage)4 ArrayList (java.util.ArrayList)3 ILookupRow (org.eclipse.scout.rt.shared.services.lookup.ILookupRow)3 IBookmarkService (org.eclipse.scout.rt.client.services.common.bookmark.IBookmarkService)2 Holder (org.eclipse.scout.rt.platform.holders.Holder)2 BookmarkFolder (org.eclipse.scout.rt.shared.services.common.bookmark.BookmarkFolder)2 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 IOutline (org.eclipse.scout.rt.client.ui.desktop.outline.IOutline)1 Order (org.eclipse.scout.rt.platform.Order)1 ConfigOperation (org.eclipse.scout.rt.platform.annotations.ConfigOperation)1 ExceptionHandler (org.eclipse.scout.rt.platform.exception.ExceptionHandler)1 PlatformError (org.eclipse.scout.rt.platform.exception.PlatformError)1 Bookmark (org.eclipse.scout.rt.shared.services.common.bookmark.Bookmark)1