Search in sources :

Example 51 with ITreeNode

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

the class JsonTree method treeNodeToJson.

protected JSONObject treeNodeToJson(ITreeNode node) {
    JSONObject json = new JSONObject();
    putProperty(json, "id", getOrCreateNodeId(node));
    putProperty(json, "expanded", node.isExpanded());
    putProperty(json, "expandedLazy", node.isExpandedLazy());
    putProperty(json, "lazyExpandingEnabled", node.isLazyExpandingEnabled());
    putProperty(json, "leaf", node.isLeaf());
    putProperty(json, "checked", node.isChecked());
    putProperty(json, "enabled", node.isEnabled());
    putProperty(json, "iconId", BinaryResourceUrlUtility.createIconUrl(node.getCell().getIconId()));
    putProperty(json, "initialExpanded", node.isInitialExpanded());
    putChildNodeIndex(json, node);
    putCellProperties(json, node.getCell());
    JSONArray jsonChildNodes = new JSONArray();
    if (node.getChildNodeCount() > 0) {
        for (ITreeNode childNode : node.getChildNodes()) {
            if (!isNodeAccepted(childNode)) {
                continue;
            }
            jsonChildNodes.put(treeNodeToJson(childNode));
        }
    }
    putProperty(json, "childNodes", jsonChildNodes);
    JsonObjectUtility.filterDefaultValues(json, "TreeNode");
    return json;
}
Also used : ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray)

Example 52 with ITreeNode

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

the class JsonTree method toJson.

@Override
public JSONObject toJson() {
    JSONObject json = super.toJson();
    JSONArray jsonNodes = new JSONArray();
    for (ITreeNode childNode : getTopLevelNodes()) {
        if (!isNodeAccepted(childNode)) {
            continue;
        }
        jsonNodes.put(treeNodeToJson(childNode));
    }
    putProperty(json, PROP_NODES, jsonNodes);
    putProperty(json, PROP_SELECTED_NODES, nodeIdsToJson(getModel().getSelectedNodes(), true, true));
    putProperty(json, PROP_MENUS, getJsonContextMenu().childActionsToJson());
    return json;
}
Also used : ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray)

Example 53 with ITreeNode

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

the class JsonTree method handleModelChildNodeOrderChanged.

protected void handleModelChildNodeOrderChanged(TreeEvent event) {
    JSONObject jsonEvent = new JSONObject();
    jsonEvent.put("parentNodeId", getNodeId(event.getCommonParentNode()));
    boolean hasNodeIds = false;
    for (ITreeNode childNode : event.getChildNodes()) {
        if (!isNodeAccepted(childNode)) {
            continue;
        }
        String childNodeId = optNodeId(childNode);
        if (childNodeId == null) {
            // Ignore nodes that are not yet sent to the UI (may happen due to asynchronous event processing)
            continue;
        }
        jsonEvent.append("childNodeIds", childNodeId);
        hasNodeIds = true;
    }
    if (hasNodeIds) {
        addActionEvent(EVENT_CHILD_NODE_ORDER_CHANGED, jsonEvent);
    }
}
Also used : ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode) JSONObject(org.json.JSONObject)

Example 54 with ITreeNode

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

the class JsonTree method jsonToCheckedInfo.

protected CheckedInfo jsonToCheckedInfo(JSONObject data) {
    JSONArray jsonNodes = data.optJSONArray("nodes");
    CheckedInfo checkInfo = new CheckedInfo();
    for (int i = 0; i < jsonNodes.length(); i++) {
        JSONObject jsonObject = jsonNodes.optJSONObject(i);
        ITreeNode row = m_treeNodes.get(jsonObject.getString("nodeId"));
        checkInfo.getAllNodes().add(row);
        if (jsonObject.optBoolean("checked")) {
            checkInfo.getCheckedNodes().add(row);
        } else {
            checkInfo.getUncheckedNodes().add(row);
        }
    }
    return checkInfo;
}
Also used : ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray)

Example 55 with ITreeNode

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

the class JsonTree method handleUiNodeExpanded.

protected void handleUiNodeExpanded(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 nodeExpanded event", nodeId);
        return;
    }
    boolean expanded = event.getData().getBoolean(PROP_EXPANDED);
    boolean lazy = event.getData().getBoolean(PROP_EXPANDED_LAZY);
    int eventType = expanded ? TreeEvent.TYPE_NODE_EXPANDED : TreeEvent.TYPE_NODE_COLLAPSED;
    addTreeEventFilterCondition(eventType).setNodes(CollectionUtility.arrayList(node));
    getModel().getUIFacade().setNodeExpandedFromUI(node, expanded, lazy);
}
Also used : ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode)

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