Search in sources :

Example 56 with ITreeNode

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

the class JsonOutlineTable method tableRowToJson.

@Override
protected JSONObject tableRowToJson(ITableRow row) {
    JSONObject json = super.tableRowToJson(row);
    ITreeNode treeNode = m_page.getTreeNodeFor(row);
    JsonOutline<IOutline> jsonOutline = getGlobalAdapter(m_page.getOutline());
    String nodeId = jsonOutline.getOrCreateNodeId(treeNode);
    putProperty(json, "nodeId", nodeId);
    return json;
}
Also used : ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode) JSONObject(org.json.JSONObject) IOutline(org.eclipse.scout.rt.client.ui.desktop.outline.IOutline)

Example 57 with ITreeNode

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

the class TreeContextMenu method calculateEnableState.

/**
 * @param ownerSelection
 */
protected void calculateEnableState(Collection<? extends ITreeNode> ownerSelection) {
    boolean enabled = true;
    for (ITreeNode node : ownerSelection) {
        if (!node.isEnabled()) {
            enabled = false;
            break;
        }
    }
    final boolean inheritedEnability = enabled;
    acceptVisitor(new IActionVisitor() {

        @Override
        public int visit(IAction action) {
            if (action instanceof IMenu) {
                IMenu menu = (IMenu) action;
                if (!menu.hasChildActions() && menu.isInheritAccessibility()) {
                    menu.setEnabledInheritAccessibility(inheritedEnability);
                }
            }
            return CONTINUE;
        }
    });
}
Also used : IActionVisitor(org.eclipse.scout.rt.client.ui.action.IActionVisitor) IMenu(org.eclipse.scout.rt.client.ui.action.menu.IMenu) ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode) IAction(org.eclipse.scout.rt.client.ui.action.IAction)

Example 58 with ITreeNode

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

the class AbstractComposerField method loadXMLRec.

private void loadXMLRec(Element x, ITreeNode parent) {
    // build tree
    for (Element xmlElem : XmlUtility.getChildElements(x)) {
        if ("attribute".equals(xmlElem.getTagName())) {
            String id = xmlElem.getAttribute("id");
            IDataModelAttributeOp op;
            Integer aggregationType = 0;
            try {
                int operator = DataModelConstants.OPERATOR_EQ;
                String opAttribName = "op";
                if (xmlElem.hasAttribute(opAttribName)) {
                    operator = Integer.parseInt(xmlElem.getAttribute(opAttribName));
                }
                op = DataModelAttributeOp.create(operator);
                String aggregTypeName = "aggregationType";
                if (xmlElem.hasAttribute(aggregTypeName)) {
                    aggregationType = Integer.parseInt(xmlElem.getAttribute(aggregTypeName));
                }
                if (aggregationType == 0) {
                    aggregationType = null;
                }
            } catch (Exception e) {
                LOG.warn("read op", e);
                continue;
            }
            ArrayList<Object> valueList = new ArrayList<Object>();
            try {
                for (int i = 1; i <= 5; i++) {
                    String valueName = (i == 1 ? "value" : "value" + i);
                    if (xmlElem.hasAttribute(valueName)) {
                        valueList.add(XmlUtility.getObjectAttribute(xmlElem, valueName));
                    }
                }
            } catch (Exception e) {
                LOG.warn("read value for attribute {}", id, e);
                continue;
            }
            ArrayList<String> displayValueList = new ArrayList<String>();
            for (int i = 1; i <= 5; i++) {
                String displayValueName = (i == 1 ? "displayValue" : "displayValue" + i);
                if (xmlElem.hasAttribute(displayValueName)) {
                    String val = null;
                    if (xmlElem.hasAttribute(displayValueName)) {
                        val = xmlElem.getAttribute(displayValueName);
                    }
                    displayValueList.add(val);
                }
            }
            // find definition
            AttributePath attPath = DataModelUtility.externalIdToAttributePath(getDataModel(), id);
            IDataModelAttribute foundAtt = (attPath != null ? attPath.getAttribute() : null);
            if (foundAtt == null) {
                LOG.warn("cannot find attribute with id={}", id);
                continue;
            }
            ITreeNode node = addAttributeNode(parent, foundAtt, aggregationType, op, valueList, displayValueList);
            if (node != null) {
                // add children recursive
                loadXMLRec(xmlElem, node);
            }
        } else if ("entity".equals(xmlElem.getTagName())) {
            String id = xmlElem.getAttribute("id");
            boolean negated = Boolean.parseBoolean(xmlElem.getAttribute("negated"));
            String text = null;
            if (xmlElem.hasAttribute("displayValues")) {
                text = xmlElem.getAttribute("displayValues");
            }
            // find definition
            EntityPath entityPath = DataModelUtility.externalIdToEntityPath(getDataModel(), id);
            IDataModelEntity foundEntity = (entityPath != null ? entityPath.lastElement() : null);
            if (foundEntity == null) {
                LOG.warn("cannot find entity with id={}", id);
                continue;
            }
            ITreeNode node = addEntityNode(parent, foundEntity, negated, null, text != null ? Collections.singletonList(text) : null);
            if (node != null) {
                // add children recursive
                loadXMLRec(xmlElem, node);
            }
        } else if ("or".equals(xmlElem.getTagName())) {
            boolean beginning = Boolean.parseBoolean(xmlElem.getAttribute("begin"));
            boolean negated = Boolean.parseBoolean(xmlElem.getAttribute("negated"));
            ITreeNode node = null;
            if (beginning) {
                node = addEitherNode(parent, negated);
            } else {
                // find last EitherOrNode
                EitherOrNode orNode = null;
                for (ITreeNode n : parent.getChildNodes()) {
                    if (n instanceof EitherOrNode && ((EitherOrNode) n).isEndOfEitherOr()) {
                        orNode = (EitherOrNode) n;
                    }
                }
                if (orNode != null) {
                    node = addAdditionalOrNode(orNode, negated);
                }
            }
            if (node != null) {
                // add children recursive
                loadXMLRec(xmlElem, node);
            }
        }
    }
}
Also used : EntityPath(org.eclipse.scout.rt.shared.data.model.EntityPath) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) IDataModelEntity(org.eclipse.scout.rt.shared.data.model.IDataModelEntity) IDataModelAttribute(org.eclipse.scout.rt.shared.data.model.IDataModelAttribute) EitherOrNode(org.eclipse.scout.rt.client.ui.form.fields.composer.node.EitherOrNode) ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode) IDataModelAttributeOp(org.eclipse.scout.rt.shared.data.model.IDataModelAttributeOp) AttributePath(org.eclipse.scout.rt.shared.data.model.AttributePath)

Example 59 with ITreeNode

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

the class AbstractComposerField method storeXMLRec.

private void storeXMLRec(Element x, ITreeNode parent) {
    for (ITreeNode node : parent.getChildNodes()) {
        if (node instanceof EntityNode) {
            EntityNode entityNode = (EntityNode) node;
            Element xEntity = x.getOwnerDocument().createElement("entity");
            xEntity.setAttribute("id", DataModelUtility.entityPathToExternalId(getDataModel(), interceptResolveEntityPath(entityNode)));
            xEntity.setAttribute("negated", (entityNode.isNegative() ? "true" : "false"));
            List<String> texts = entityNode.getTexts();
            xEntity.setAttribute("displayValues", CollectionUtility.hasElements(texts) ? StringUtility.emptyIfNull(CollectionUtility.firstElement(texts)) : null);
            x.appendChild(xEntity);
            // recursion
            storeXMLRec(xEntity, node);
        } else if (node instanceof AttributeNode) {
            AttributeNode attNode = (AttributeNode) node;
            Element xAtt = x.getOwnerDocument().createElement("attribute");
            xAtt.setAttribute("id", DataModelUtility.attributePathToExternalId(getDataModel(), interceptResolveAttributePath(attNode)));
            IDataModelAttributeOp op = attNode.getOp();
            try {
                xAtt.setAttribute("op", op.getOperator() + "");
                if (attNode.getAggregationType() != null) {
                    xAtt.setAttribute("aggregationType", attNode.getAggregationType() + "");
                }
            } catch (Exception e) {
                LOG.warn("write op {}", op, e);
            }
            List<String> texts = attNode.getTexts();
            if (CollectionUtility.hasElements(texts)) {
                Iterator<String> it = texts.iterator();
                xAtt.setAttribute("displayValue", StringUtility.emptyIfNull(it.next()));
                int i = 2;
                while (it.hasNext()) {
                    xAtt.setAttribute(("displayValue" + i), StringUtility.emptyIfNull(it.next()));
                    i++;
                }
            }
            List<Object> values = attNode.getValues();
            if (values != null) {
                int i = 0;
                for (Object value : values) {
                    String valueName = (i == 0 ? "value" : "value" + (i + 1));
                    try {
                        XmlUtility.setObjectAttribute(xAtt, valueName, value);
                    } catch (Exception e) {
                        LOG.warn("write value[{}] for attribute {}: {}", i, attNode.getAttribute(), value, e);
                    }
                    i++;
                }
            }
            x.appendChild(xAtt);
        } else if (node instanceof EitherOrNode) {
            EitherOrNode orNode = (EitherOrNode) node;
            Element xOr = x.getOwnerDocument().createElement("or");
            xOr.setAttribute("begin", "" + orNode.isBeginOfEitherOr());
            xOr.setAttribute("negated", (orNode.isNegative() ? "true" : "false"));
            x.appendChild(xOr);
            // recursion
            storeXMLRec(xOr, node);
        }
    }
}
Also used : EitherOrNode(org.eclipse.scout.rt.client.ui.form.fields.composer.node.EitherOrNode) ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode) AttributeNode(org.eclipse.scout.rt.client.ui.form.fields.composer.node.AttributeNode) Element(org.w3c.dom.Element) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) IDataModelAttributeOp(org.eclipse.scout.rt.shared.data.model.IDataModelAttributeOp) EntityNode(org.eclipse.scout.rt.client.ui.form.fields.composer.node.EntityNode)

Example 60 with ITreeNode

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

the class AbstractComposerField method execMarkSaved.

@Override
protected void execMarkSaved() {
    try {
        m_tree.setTreeChanging(true);
        // 
        ITreeVisitor v = new ITreeVisitor() {

            @Override
            public boolean visit(ITreeNode node) {
                if (!node.isStatusNonchanged()) {
                    node.setStatusInternal(ITreeNode.STATUS_NON_CHANGED);
                    m_tree.updateNode(node);
                }
                return true;
            }
        };
        m_tree.visitNode(m_tree.getRootNode(), v);
        m_tree.clearDeletedNodes();
        updateInitialValue();
    } finally {
        m_tree.setTreeChanging(false);
    }
}
Also used : ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode) ITreeVisitor(org.eclipse.scout.rt.client.ui.basic.tree.ITreeVisitor)

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