use of org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode in project scout.rt by eclipse.
the class JsonTree method handleModelNodesUpdated.
protected void handleModelNodesUpdated(TreeEvent event) {
JSONArray jsonNodes = new JSONArray();
for (ITreeNode node : event.getNodes()) {
if (!isNodeAccepted(node)) {
continue;
}
String nodeId = optNodeId(node);
if (nodeId == null) {
// Ignore nodes that are not yet sent to the UI (may happen due to asynchronous event processing)
continue;
}
JSONObject jsonNode = new JSONObject();
putProperty(jsonNode, "id", nodeId);
// Only send _some_ of the properties. Everything else (e.g. "checked", "expanded") will be handled with separate events.
// --> See also: Tree.js/_onNodesUpdated()
putProperty(jsonNode, "leaf", node.isLeaf());
putProperty(jsonNode, "enabled", node.isEnabled());
putProperty(jsonNode, "lazyExpandingEnabled", node.isLazyExpandingEnabled());
jsonNodes.put(jsonNode);
}
if (jsonNodes.length() == 0) {
return;
}
JSONObject jsonEvent = new JSONObject();
putProperty(jsonEvent, PROP_NODES, jsonNodes);
putProperty(jsonEvent, PROP_COMMON_PARENT_NODE_ID, optNodeId(event.getCommonParentNode()));
addActionEvent(EVENT_NODES_UPDATED, jsonEvent);
}
use of org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode in project scout.rt by eclipse.
the class JsonTree method handleModelNodesDeleted.
protected void handleModelNodesDeleted(TreeEvent event) {
Collection<ITreeNode> nodes = event.getNodes();
JSONObject jsonEvent = new JSONObject();
putProperty(jsonEvent, PROP_COMMON_PARENT_NODE_ID, optNodeId(event.getCommonParentNode()));
// Caveat: This can only be optimized when no nodes were inserted again in the same "tree changing" scope.
if (event.getCommonParentNode() != null && getFilteredNodeCount(event.getCommonParentNode()) == 0) {
addActionEvent(EVENT_ALL_CHILD_NODES_DELETED, jsonEvent);
} else {
JSONArray jsonNodeIds = nodeIdsToJson(nodes, false, false);
if (jsonNodeIds.length() > 0) {
putProperty(jsonEvent, PROP_NODE_IDS, jsonNodeIds);
addActionEvent(EVENT_NODES_DELETED, jsonEvent);
}
}
for (ITreeNode node : nodes) {
unlinkFromParentNode(node);
}
disposeNodes(nodes, true);
}
use of org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode in project scout.rt by eclipse.
the class JsonTree method applyFilterChangedEventToUiRec.
/**
* Recursively traverses through the given nodes (and its child nodes) and checks which of the model nodes are hidden
* by tree filters.
* <ul>
* <li>For every newly hidden node (i.e. a node that is currently visible on the UI) a NODES_DELETED event is created.
* <li>For every newly visible node (i.e. a node that is currently invisible on the UI) a NODES_INSERTED event is
* created.
* </ul>
* All new events are added to the event buffer, where they might be coalesced later.
*/
protected void applyFilterChangedEventToUiRec(List<ITreeNode> nodes) {
for (ITreeNode node : nodes) {
boolean processChildNodes = true;
if (!isInvisibleRootNode(node) && node.getTree() != null) {
String existingNodeId = optNodeId(node);
if (node.isFilterAccepted()) {
if (existingNodeId == null) {
// Node is not filtered but JsonTree does not know it yet --> handle as insertion event
m_eventBuffer.add(new TreeEvent(node.getTree(), TreeEvent.TYPE_NODES_INSERTED, node));
// Stop recursion, because this node (including its child nodes) is already inserted
processChildNodes = false;
}
} else if (!node.isRejectedByUser()) {
if (existingNodeId != null) {
// Node is filtered, but JsonTree has it in its list --> handle as deletion event
m_eventBuffer.add(new TreeEvent(node.getTree(), TreeEvent.TYPE_NODES_DELETED, node));
}
// Stop recursion, because this node (including its child nodes) is already deleted
processChildNodes = false;
}
}
// Recursion
if (processChildNodes) {
applyFilterChangedEventToUiRec(node.getChildNodes());
}
}
}
use of org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode in project scout.rt by eclipse.
the class JsonTree method handleUiNodeClick.
protected void handleUiNodeClick(JsonEvent event) {
String nodeId = event.getData().getString(PROP_NODE_ID);
ITreeNode node = optTreeNodeForNodeId(nodeId);
if (node == null) {
LOG.info("Requested tree-node with ID {} doesn't exist. Skip nodeClicked event", nodeId);
return;
}
getModel().getUIFacade().fireNodeClickFromUI(node, MouseButton.Left);
}
use of org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode in project scout.rt by eclipse.
the class JsonTree method unlinkFromParentNode.
/**
* Removes the given node from the child list of the parent node ({@link #m_childNodes}). Does not remove it from the
* {@link #m_parentNodes} list because it is not necessary as it will be done in
* {@link #disposeNode(ITreeNode, boolean)}.
*/
protected void unlinkFromParentNode(ITreeNode node) {
ITreeNode parentNode = getParentNode(node);
Set<ITreeNode> childrenOfParent = getChildNodes(parentNode);
childrenOfParent.remove(node);
}
Aggregations