Search in sources :

Example 6 with IDataModelEntity

use of org.eclipse.scout.rt.shared.data.model.IDataModelEntity in project scout.rt by eclipse.

the class MoveDataModelEntitiyAndAttributeTest method testSetup.

@Test
public void testSetup() {
    TestDataModel dataModel = new TestDataModel();
    assertDataModelElements(dataModel.getEntities(), Top1Entity.class, Top2Entity.class, Top3Entity.class);
    assertDataModelElements(dataModel.getAttributes(), Top1Attribute.class, Top2Attribute.class, Top3Attribute.class);
    IDataModelEntity entity = dataModel.getEntities().get(0);
    assertDataModelElements(entity.getEntities(), Sub1Top1Entity.class, Sub2Top1Entity.class, Sub3Top1Entity.class);
    assertDataModelElements(entity.getAttributes(), Sub1Top1Attribute.class, Sub2Top1Attribute.class, Sub3Top1Attribute.class);
}
Also used : IDataModelEntity(org.eclipse.scout.rt.shared.data.model.IDataModelEntity) TestDataModel(org.eclipse.scout.rt.shared.extension.data.model.fixture.TestDataModel) Test(org.junit.Test)

Example 7 with IDataModelEntity

use of org.eclipse.scout.rt.shared.data.model.IDataModelEntity in project scout.rt by eclipse.

the class FormDataStatementBuilder method buildComposerEntityNodeContribution.

public EntityContribution buildComposerEntityNodeContribution(ComposerEntityNodeData node, EntityStrategy entityStrategy) {
    if (getDataModel() == null) {
        throw new ProcessingException("there is no data model set, call FormDataStatementBuilder.setDataModel to set one");
    }
    EntityPath entityPath = DataModelUtility.externalIdToEntityPath(getDataModel(), node.getEntityExternalId());
    IDataModelEntity entity = (entityPath != null ? entityPath.lastElement() : null);
    if (entity == null) {
        LOG.warn("no entity for external id: {}", node.getEntityExternalId());
        return null;
    }
    DataModelEntityPartDefinition def = m_dataModelEntMap.get(entity.getClass());
    if (def == null) {
        LOG.warn("no PartDefinition for entity: {}", entity);
        return null;
    }
    ComposerEntityNodeData parentEntityNode = getParentNodeOfType(node, ComposerEntityNodeData.class);
    Map<String, String> parentAliasMap = (parentEntityNode != null ? m_aliasMapper.getNodeAliases(parentEntityNode) : m_aliasMapper.getRootAliases());
    String baseStm;
    switch(entityStrategy) {
        case BuildQuery:
            {
                baseStm = def.getSelectClause();
                break;
            }
        case BuildConstraints:
            {
                baseStm = def.getWhereClause();
                break;
            }
        default:
            {
                baseStm = null;
            }
    }
    String stm = null;
    if (baseStm != null) {
        stm = def.createInstance(this, node, entityStrategy, baseStm, parentAliasMap);
    }
    if (stm == null) {
        return null;
    }
    m_aliasMapper.addAllNodeEntitiesFrom(node, stm);
    stm = m_aliasMapper.replaceMarkersByAliases(stm, m_aliasMapper.getNodeAliases(node), parentAliasMap);
    switch(entityStrategy) {
        case BuildQuery:
            {
                EntityContribution resultContrib = buildComposerEntityUnitContribution(node, entityStrategy, stm, node.getChildNodes(), isConsumeChildContributions(entityPath));
                return resultContrib;
            }
        case BuildConstraints:
            {
                String s = buildComposerEntityEitherOrSplit(entityStrategy, stm, node.isNegative(), node.getChildNodes());
                EntityContribution resultContrib = (s != null ? EntityContribution.create(s) : new EntityContribution());
                return resultContrib;
            }
        default:
            {
                return null;
            }
    }
}
Also used : EntityPath(org.eclipse.scout.rt.shared.data.model.EntityPath) ComposerEntityNodeData(org.eclipse.scout.rt.shared.data.form.fields.composer.ComposerEntityNodeData) IDataModelEntity(org.eclipse.scout.rt.shared.data.model.IDataModelEntity) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException)

Example 8 with IDataModelEntity

use of org.eclipse.scout.rt.shared.data.model.IDataModelEntity in project scout.rt by eclipse.

the class FormDataStatementBuilderCheck method entityToName.

protected String entityToName(EntityPath ePath) {
    if (ePath.isEmpty()) {
        return null;
    }
    IDataModelEntity e = ePath.lastElement();
    String name = e.getClass().getSimpleName();
    name = name.replaceAll("^Abstract(.*)$", "$1");
    name = name.replaceAll("^(.*)Entity$", "$1");
    String[] array = name.replaceAll("([a-z])([A-Z])", "$1 $2").split(" ");
    return array[array.length - 1];
}
Also used : IDataModelEntity(org.eclipse.scout.rt.shared.data.model.IDataModelEntity)

Example 9 with IDataModelEntity

use of org.eclipse.scout.rt.shared.data.model.IDataModelEntity 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 10 with IDataModelEntity

use of org.eclipse.scout.rt.shared.data.model.IDataModelEntity in project scout.rt by eclipse.

the class AbstractComposerField method execResolveRootPathForTopLevelAttribute.

/**
 * see {@link #interceptResolveAttributePath(AttributeNode)}
 */
@ConfigOperation
@Order(98)
protected void execResolveRootPathForTopLevelAttribute(IDataModelAttribute a, List<IDataModelEntity> lifeList) {
    IDataModelEntity tmp = (a != null ? a.getParentEntity() : null);
    while (tmp != null) {
        lifeList.add(0, tmp);
        tmp = tmp.getParentEntity();
    }
}
Also used : IDataModelEntity(org.eclipse.scout.rt.shared.data.model.IDataModelEntity) Order(org.eclipse.scout.rt.platform.Order) ConfigOperation(org.eclipse.scout.rt.platform.annotations.ConfigOperation)

Aggregations

IDataModelEntity (org.eclipse.scout.rt.shared.data.model.IDataModelEntity)15 EntityPath (org.eclipse.scout.rt.shared.data.model.EntityPath)5 TestDataModel (org.eclipse.scout.rt.shared.extension.data.model.fixture.TestDataModel)5 Test (org.junit.Test)5 Order (org.eclipse.scout.rt.platform.Order)4 ConfigOperation (org.eclipse.scout.rt.platform.annotations.ConfigOperation)4 IExtensionRegistry (org.eclipse.scout.rt.shared.extension.IExtensionRegistry)4 LinkedList (java.util.LinkedList)2 ITreeNode (org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode)2 EntityNode (org.eclipse.scout.rt.client.ui.form.fields.composer.node.EntityNode)2 ComposerEntityNodeData (org.eclipse.scout.rt.shared.data.form.fields.composer.ComposerEntityNodeData)2 AttributePath (org.eclipse.scout.rt.shared.data.model.AttributePath)2 IDataModelAttribute (org.eclipse.scout.rt.shared.data.model.IDataModelAttribute)2 ArrayList (java.util.ArrayList)1 EitherOrNode (org.eclipse.scout.rt.client.ui.form.fields.composer.node.EitherOrNode)1 ProcessingException (org.eclipse.scout.rt.platform.exception.ProcessingException)1 ComposerAttributeNodeData (org.eclipse.scout.rt.shared.data.form.fields.composer.ComposerAttributeNodeData)1 AbstractDataModelEntity (org.eclipse.scout.rt.shared.data.model.AbstractDataModelEntity)1 IDataModelAttributeOp (org.eclipse.scout.rt.shared.data.model.IDataModelAttributeOp)1 Element (org.w3c.dom.Element)1