use of org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode in project scout.rt by eclipse.
the class JsonTree method putChildNodeIndex.
/**
* If the given node has a parent node, the value for the property "childNodeIndex" is calculated and added to the
* given JSON object.
* <p>
* Note that the calculated value may differ from the model's {@link ITreeNode#getChildNodeIndex()} value! This is
* because not all model nodes are sent to the UI. The calculated value only counts nodes sent to the UI, e.g. a node
* with childNodeIndex=50 may result in "childNodeIndex: 3" if 47 of the preceding nodes are filtered.
*/
protected void putChildNodeIndex(JSONObject json, ITreeNode node) {
if (node.getParentNode() != null && node.getParentNode().getChildNodeCount() > 0) {
int childNodeIndex = 0;
// Find the node in the parents childNodes list (skipping non-accepted nodes)
for (ITreeNode childNode : node.getParentNode().getChildNodes()) {
// Only count accepted nodes
if (isNodeAccepted(childNode)) {
if (childNode == node) {
// We have found our node!
break;
}
childNodeIndex++;
}
}
putProperty(json, "childNodeIndex", childNodeIndex);
}
}
use of org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode in project scout.rt by eclipse.
the class JsonTree method handleModelAllChildNodesDeleted.
protected void handleModelAllChildNodesDeleted(TreeEvent event) {
JSONObject jsonEvent = new JSONObject();
putProperty(jsonEvent, PROP_COMMON_PARENT_NODE_ID, getNodeId(event.getCommonParentNode()));
addActionEvent(EVENT_ALL_CHILD_NODES_DELETED, jsonEvent);
// Read the removed nodes from the event, because they are no longer contained in the model
for (ITreeNode node : event.getChildNodes()) {
unlinkFromParentNode(node);
}
disposeNodes(event.getChildNodes(), true);
}
use of org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode in project scout.rt by eclipse.
the class JsonTree method handleUiNodeAction.
protected void handleUiNodeAction(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 nodeAction event", nodeId);
return;
}
getModel().getUIFacade().fireNodeActionFromUI(node);
}
use of org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode in project scout.rt by eclipse.
the class JsonTree method extractTreeNodes.
public List<ITreeNode> extractTreeNodes(JSONObject json) {
JSONArray nodeIds = json.getJSONArray(PROP_NODE_IDS);
List<ITreeNode> nodes = new ArrayList<>(nodeIds.length());
for (int i = 0; i < nodeIds.length(); i++) {
ITreeNode node = optTreeNodeForNodeId(nodeIds.getString(i));
if (node != null) {
nodes.add(node);
}
}
return nodes;
}
use of org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode in project scout.rt by eclipse.
the class JsonTree method handleModelNodesChecked.
protected void handleModelNodesChecked(Collection<ITreeNode> modelNodes) {
JSONArray jsonNodes = new JSONArray();
for (ITreeNode node : modelNodes) {
addJsonNodesChecked(jsonNodes, node);
if (getModel().isAutoCheckChildNodes()) {
for (ITreeNode childNode : collectChildNodesCheckedRec(node)) {
addJsonNodesChecked(jsonNodes, childNode);
}
}
}
if (jsonNodes.length() == 0) {
return;
}
JSONObject jsonEvent = new JSONObject();
putProperty(jsonEvent, PROP_NODES, jsonNodes);
addActionEvent(EVENT_NODES_CHECKED, jsonEvent);
}
Aggregations