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;
}
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();
}
}
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();
}
}
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);
}
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;
}
Aggregations