Search in sources :

Example 11 with ITreeNode

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

the class JsonTree method consumeBinaryResource.

@Override
public void consumeBinaryResource(List<BinaryResource> binaryResources, Map<String, String> uploadProperties) {
    if ((getModel().getDropType() & IDNDSupport.TYPE_FILE_TRANSFER) == IDNDSupport.TYPE_FILE_TRANSFER) {
        ResourceListTransferObject transferObject = new ResourceListTransferObject(binaryResources);
        ITreeNode node = null;
        if (uploadProperties != null && uploadProperties.containsKey("nodeId")) {
            String nodeId = uploadProperties.get("nodeId");
            if (!StringUtility.isNullOrEmpty(nodeId)) {
                node = getTreeNodeForNodeId(nodeId);
            }
        }
        getModel().getUIFacade().fireNodeDropActionFromUI(node, transferObject);
    }
}
Also used : ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode) ResourceListTransferObject(org.eclipse.scout.rt.client.ui.dnd.ResourceListTransferObject)

Example 12 with ITreeNode

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

the class TreeEventFilter method filter.

/**
 * Computes whether the event should be returned to the GUI. There are three cases:
 * <ul>
 * <li>No filtering happens: The original event is returned. <br>
 * This is the case if the conditions don't contain an event with the same type as the original event.</li>
 * <li>Partial filtering happens (if condition.checkNodes is true): A new event with a subset of tree nodes is
 * returned.<br>
 * This is the case if the conditions contain a relevant event but has different nodes than the original event.
 * <li>Complete filtering happens: Null is returned.<br>
 * This is the case if the event should be filtered for every node in the original event
 */
@Override
public TreeEvent filter(TreeEvent event) {
    for (TreeEventFilterCondition condition : getConditions()) {
        if (condition.getType() == event.getType()) {
            if (condition.checkNodes()) {
                Collection<ITreeNode> nodes = new ArrayList<>(event.getNodes());
                nodes.removeAll(condition.getNodes());
                if (nodes.size() == 0) {
                    // Ignore event if no nodes remain (or if the event contained no nodes at all)
                    return null;
                }
                return new TreeEvent(m_jsonTree.getModel(), event.getType(), event.getCommonParentNode(), nodes);
            }
            if (condition.checkCheckedNodes()) {
                List<ITreeNode> nodes = new ArrayList<>(event.getNodes());
                List<ITreeNode> checkedNodes = new ArrayList<>();
                List<ITreeNode> uncheckedNodes = new ArrayList<>();
                for (ITreeNode node : nodes) {
                    if (node.isChecked()) {
                        checkedNodes.add(node);
                    } else {
                        uncheckedNodes.add(node);
                    }
                }
                if (CollectionUtility.equalsCollection(checkedNodes, condition.getCheckedNodes()) && CollectionUtility.equalsCollection(uncheckedNodes, condition.getUncheckedNodes())) {
                    // Ignore event if the checked and the unchecked nodes have not changes
                    return null;
                }
                // Otherwise, send nodes that have a different checked state than before
                checkedNodes.removeAll(condition.getCheckedNodes());
                uncheckedNodes.removeAll(condition.getUncheckedNodes());
                nodes = CollectionUtility.combine(checkedNodes, uncheckedNodes);
                TreeEvent newEvent = new TreeEvent(m_jsonTree.getModel(), event.getType(), event.getCommonParentNode(), nodes);
                return newEvent;
            }
            // Ignore event if only type should be checked
            return null;
        }
    }
    return event;
}
Also used : TreeEvent(org.eclipse.scout.rt.client.ui.basic.tree.TreeEvent) ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode) ArrayList(java.util.ArrayList)

Example 13 with ITreeNode

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

the class AbstractAddAttributeMenu method execOwnerValueChanged.

@Override
protected void execOwnerValueChanged(Object newOwnerValue) {
    EntityNode entityNode = null;
    ITreeNode treeNode = m_parentNode;
    while (treeNode != null) {
        if (treeNode instanceof EntityNode) {
            entityNode = (EntityNode) treeNode;
            break;
        }
        treeNode = treeNode.getParentNode();
    }
    List<IDataModelAttribute> attributes;
    if (entityNode != null) {
        attributes = entityNode.getEntity().getAttributes();
    } else {
        attributes = m_field.getAttributes();
    }
    setVisible(attributes.size() > 0);
}
Also used : ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode) IDataModelAttribute(org.eclipse.scout.rt.shared.data.model.IDataModelAttribute)

Example 14 with ITreeNode

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

the class AbstractComposerNode method attachAddEntityMenus.

protected void attachAddEntityMenus(Collection<IMenu> menus) {
    EntityNode eNode = null;
    ITreeNode n = this;
    while (n != null) {
        if (n instanceof EntityNode) {
            eNode = (EntityNode) n;
            break;
        }
        n = n.getParentNode();
    }
    List<IDataModelEntity> childEntitites;
    if (eNode != null) {
        childEntitites = eNode.getEntity().getEntities();
    } else {
        childEntitites = getComposerField().getEntities();
    }
    for (IDataModelEntity e : childEntitites) {
        menus.add(createAddEntityMenu(e));
    }
}
Also used : ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode) IDataModelEntity(org.eclipse.scout.rt.shared.data.model.IDataModelEntity)

Example 15 with ITreeNode

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

the class JsonTreeTest method testIgnorableSelectionEvent.

/**
 * Response must not contain the selection event if the selection was triggered by the request
 */
@Test
public void testIgnorableSelectionEvent() throws JSONException {
    ITree tree = createTreeWithOneNode();
    ITreeNode node = tree.getRootNode().getChildNode(0);
    JsonTree<ITree> jsonTree = m_uiSession.createJsonAdapter(tree, null);
    JsonEvent event = createJsonSelectedEvent(jsonTree.getOrCreateNodeId(node));
    jsonTree.handleUiEvent(event);
    List<JsonEvent> responseEvents = JsonTestUtility.extractEventsFromResponse(m_uiSession.currentJsonResponse(), JsonTree.EVENT_NODES_SELECTED);
    assertTrue(responseEvents.size() == 0);
}
Also used : ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode) JsonEvent(org.eclipse.scout.rt.ui.html.json.JsonEvent) ITree(org.eclipse.scout.rt.client.ui.basic.tree.ITree) Test(org.junit.Test)

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