Search in sources :

Example 1 with EntityNode

use of org.eclipse.scout.rt.client.ui.form.fields.composer.node.EntityNode in project scout.rt by eclipse.

the class AbstractComposerField method execCreateEntityNode.

/**
 * Override this method to decorate or enhance new nodes whenever they are created
 *
 * @return the new node or null to ignore the add of a new node of this type
 *         <p>
 *         Normally overrides call super. {@link #execCreateEntityNode(ITreeNode, IDataModelEntity, boolean, Object[],
 *         List<String>)}
 */
@ConfigOperation
@Order(110)
protected EntityNode execCreateEntityNode(ITreeNode parentNode, IDataModelEntity e, boolean negated, List<? extends Object> values, List<String> texts) {
    EntityNode node = new EntityNode(this, e);
    node.setValues(values);
    node.setTexts(texts);
    node.setNegative(negated);
    node.setStatus(ITreeNode.STATUS_INSERTED);
    return node;
}
Also used : EntityNode(org.eclipse.scout.rt.client.ui.form.fields.composer.node.EntityNode) Order(org.eclipse.scout.rt.platform.Order) ConfigOperation(org.eclipse.scout.rt.platform.annotations.ConfigOperation)

Example 2 with EntityNode

use of org.eclipse.scout.rt.client.ui.form.fields.composer.node.EntityNode in project scout.rt by eclipse.

the class AbstractComposerField method execResolveEntityPath.

/**
 * For {@link #exportFormFieldData(AbstractFormFieldData)}, {@link AbstractTree#exportTreeData(AbstractTreeFieldData)}
 * and {@link #storeToXml(Element)} it is necessary to export {@link IDataModelEntity} and {@link IDataModelAttribute}
 * as external strings. see {@link EntityPath}
 * <p>
 * This callback completes an entity path to its root. The parameter path contains the entity path represented in the
 * composer tree of {@link EntityNode}s, the last element is the deepest tree node.
 * <p>
 * The default traverses the tree up to the root and collects all non-null {@link EntityNode#getEntity()}
 * <p>
 * This is prefixed with {@link #interceptResolveRootPathForTopLevelEntity(IDataModelEntity, List)}
 */
@ConfigOperation
@Order(99)
protected EntityPath execResolveEntityPath(EntityNode node) {
    LinkedList<IDataModelEntity> list = new LinkedList<IDataModelEntity>();
    EntityNode tmp = node;
    while (tmp != null) {
        if (tmp.getEntity() != null) {
            list.add(0, tmp.getEntity());
        }
        // next
        tmp = tmp.getAncestorNode(EntityNode.class);
    }
    if (list.size() > 0) {
        interceptResolveRootPathForTopLevelEntity(list.get(0), list);
    }
    return new EntityPath(list);
}
Also used : EntityPath(org.eclipse.scout.rt.shared.data.model.EntityPath) IDataModelEntity(org.eclipse.scout.rt.shared.data.model.IDataModelEntity) LinkedList(java.util.LinkedList) EntityNode(org.eclipse.scout.rt.client.ui.form.fields.composer.node.EntityNode) Order(org.eclipse.scout.rt.platform.Order) ConfigOperation(org.eclipse.scout.rt.platform.annotations.ConfigOperation)

Example 3 with EntityNode

use of org.eclipse.scout.rt.client.ui.form.fields.composer.node.EntityNode in project scout.rt by eclipse.

the class AbstractComposerField method addEntityNode.

@Override
public EntityNode addEntityNode(ITreeNode parentNode, IDataModelEntity e, boolean negated, List<? extends Object> values, List<String> texts) {
    EntityNode node = interceptCreateEntityNode(parentNode, e, negated, values, texts);
    if (node != null) {
        getTree().addChildNode(parentNode, node);
        getTree().setNodeExpanded(node, true);
    }
    return node;
}
Also used : EntityNode(org.eclipse.scout.rt.client.ui.form.fields.composer.node.EntityNode)

Example 4 with EntityNode

use of org.eclipse.scout.rt.client.ui.form.fields.composer.node.EntityNode 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 5 with EntityNode

use of org.eclipse.scout.rt.client.ui.form.fields.composer.node.EntityNode in project scout.rt by eclipse.

the class AbstractComposerField method execResolveAttributePath.

/**
 * see {@link #execResolveEntityPathForEntityExport(EntityNode)}, {@link AttributePath} for more details
 * <p>
 * The path in the composer tree is prefixed with
 * {@link #interceptResolveRootPathForTopLevelAttribute(IDataModelAttribute, List)}
 */
@ConfigOperation
@Order(99)
protected AttributePath execResolveAttributePath(AttributeNode node) {
    LinkedList<IDataModelEntity> list = new LinkedList<IDataModelEntity>();
    if (node == null) {
        return null;
    }
    EntityNode tmp = node.getAncestorNode(EntityNode.class);
    while (tmp != null) {
        if (tmp.getEntity() != null) {
            list.add(0, tmp.getEntity());
        }
        // next
        tmp = tmp.getAncestorNode(EntityNode.class);
    }
    if (list.size() > 0) {
        interceptResolveRootPathForTopLevelEntity(list.get(0), list);
    } else {
        interceptResolveRootPathForTopLevelAttribute(node.getAttribute(), list);
    }
    return new AttributePath(list, node.getAttribute());
}
Also used : IDataModelEntity(org.eclipse.scout.rt.shared.data.model.IDataModelEntity) LinkedList(java.util.LinkedList) EntityNode(org.eclipse.scout.rt.client.ui.form.fields.composer.node.EntityNode) AttributePath(org.eclipse.scout.rt.shared.data.model.AttributePath) Order(org.eclipse.scout.rt.platform.Order) ConfigOperation(org.eclipse.scout.rt.platform.annotations.ConfigOperation)

Aggregations

EntityNode (org.eclipse.scout.rt.client.ui.form.fields.composer.node.EntityNode)6 LinkedList (java.util.LinkedList)3 Order (org.eclipse.scout.rt.platform.Order)3 ConfigOperation (org.eclipse.scout.rt.platform.annotations.ConfigOperation)3 ArrayList (java.util.ArrayList)2 ITreeNode (org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode)2 AttributeNode (org.eclipse.scout.rt.client.ui.form.fields.composer.node.AttributeNode)2 EitherOrNode (org.eclipse.scout.rt.client.ui.form.fields.composer.node.EitherOrNode)2 IDataModelEntity (org.eclipse.scout.rt.shared.data.model.IDataModelEntity)2 Iterator (java.util.Iterator)1 List (java.util.List)1 AttributePath (org.eclipse.scout.rt.shared.data.model.AttributePath)1 EntityPath (org.eclipse.scout.rt.shared.data.model.EntityPath)1 IDataModelAttributeOp (org.eclipse.scout.rt.shared.data.model.IDataModelAttributeOp)1 Element (org.w3c.dom.Element)1