Search in sources :

Example 46 with ITreeNode

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

Example 47 with ITreeNode

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

Example 48 with ITreeNode

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

Example 49 with ITreeNode

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

Example 50 with ITreeNode

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