Search in sources :

Example 6 with ITreeNode

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);
    }
}
Also used : ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode)

Example 7 with ITreeNode

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);
}
Also used : ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode) JSONObject(org.json.JSONObject)

Example 8 with ITreeNode

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);
}
Also used : ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode)

Example 9 with ITreeNode

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;
}
Also used : ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode) JSONArray(org.json.JSONArray) ArrayList(java.util.ArrayList)

Example 10 with ITreeNode

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);
}
Also used : ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray)

Aggregations

ITreeNode (org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode)95 Test (org.junit.Test)34 ITree (org.eclipse.scout.rt.client.ui.basic.tree.ITree)29 ArrayList (java.util.ArrayList)23 ITreeVisitor (org.eclipse.scout.rt.client.ui.basic.tree.ITreeVisitor)16 JSONObject (org.json.JSONObject)14 TreeNode (org.eclipse.scout.rt.ui.html.json.tree.fixtures.TreeNode)12 JsonEvent (org.eclipse.scout.rt.ui.html.json.JsonEvent)11 JSONArray (org.json.JSONArray)10 HashSet (java.util.HashSet)9 IPage (org.eclipse.scout.rt.client.ui.desktop.outline.pages.IPage)6 EitherOrNode (org.eclipse.scout.rt.client.ui.form.fields.composer.node.EitherOrNode)6 IMenu (org.eclipse.scout.rt.client.ui.action.menu.IMenu)5 TreeEvent (org.eclipse.scout.rt.client.ui.basic.tree.TreeEvent)5 IOutline (org.eclipse.scout.rt.client.ui.desktop.outline.IOutline)5 LinkedList (java.util.LinkedList)4 ITableRow (org.eclipse.scout.rt.client.ui.basic.table.ITableRow)4 IDesktop (org.eclipse.scout.rt.client.ui.desktop.IDesktop)4 ITreeNodeFilter (org.eclipse.scout.rt.client.ui.basic.tree.ITreeNodeFilter)3 StyleField (org.eclipse.scout.rt.client.ui.form.fields.smartfield.SmartFieldTest.TestForm.MainBox.StyleField)3