Search in sources :

Example 1 with IDataModelAttribute

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

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

the class FormDataStatementBuilderWithComposerTest method prepareComposer.

private ComposerAttributeNodeData prepareComposer(int aggregationType) {
    IDataModelEntity entity = m_dataModel.getEntity(TestDataModel.Entity.class);
    IDataModelEntity subEntity = entity.getEntity(TestDataModel.Entity.SubEntity.class);
    IDataModelAttribute subAttribute = subEntity.getAttribute(TestDataModel.Entity.SubEntity.SubAttribute.class);
    ComposerAttributeNodeData subAttributeNode = new ComposerAttributeNodeData();
    subAttributeNode.setAggregationType(aggregationType);
    subAttributeNode.setOperator(DataModelConstants.OPERATOR_EQ);
    String attributeExternalId = DataModelUtility.attributePathToExternalId(m_dataModel, new EntityPath().addToEnd(entity).addToEnd(subEntity).addToEnd(subAttribute));
    subAttributeNode.setAttributeExternalId(attributeExternalId);
    subAttributeNode.setValues(CollectionUtility.arrayList(10L));
    ComposerEntityNodeData subEntityNode = new ComposerEntityNodeData();
    subEntityNode.setEntityExternalId(DataModelUtility.entityPathToExternalId(m_dataModel, new EntityPath().addToEnd(entity).addToEnd(subEntity)));
    subEntityNode.setChildNodes(Arrays.<TreeNodeData>asList(subAttributeNode));
    ComposerEntityNodeData entityNode = new ComposerEntityNodeData();
    entityNode.setEntityExternalId(DataModelUtility.entityPathToExternalId(m_dataModel, new EntityPath().addToEnd(entity)));
    entityNode.setChildNodes(Arrays.<TreeNodeData>asList(subEntityNode));
    return subAttributeNode;
}
Also used : IDataModelEntity(org.eclipse.scout.rt.shared.data.model.IDataModelEntity) AbstractDataModelEntity(org.eclipse.scout.rt.shared.data.model.AbstractDataModelEntity) EntityPath(org.eclipse.scout.rt.shared.data.model.EntityPath) ComposerEntityNodeData(org.eclipse.scout.rt.shared.data.form.fields.composer.ComposerEntityNodeData) ComposerAttributeNodeData(org.eclipse.scout.rt.shared.data.form.fields.composer.ComposerAttributeNodeData) IDataModelEntity(org.eclipse.scout.rt.shared.data.model.IDataModelEntity) IDataModelAttribute(org.eclipse.scout.rt.shared.data.model.IDataModelAttribute)

Example 3 with IDataModelAttribute

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

the class FormDataStatementBuilderCheck method attributeToName.

protected String attributeToName(AttributePath aPath) {
    String ename = entityToName(aPath.getEntityPath());
    IDataModelAttribute a = aPath.getAttribute();
    String name = a.getClass().getSimpleName();
    name = name.replaceAll("^Abstract(.*)$", "$1");
    name = name.replaceAll("^(.*)Attribute", "$1");
    if (ename != null) {
        String[] array = ename.replaceAll("([a-z])([A-Z])", "$1 $2").split(" ");
        for (int i = array.length - 1; i >= 0; i--) {
            if (name.startsWith(array[i])) {
                name = name.substring(array[i].length());
            }
        }
    }
    return name;
}
Also used : IDataModelAttribute(org.eclipse.scout.rt.shared.data.model.IDataModelAttribute)

Example 4 with IDataModelAttribute

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

the class FormDataStatementBuilder method buildComposerAttributeNode.

public EntityContribution buildComposerAttributeNode(final ComposerAttributeNodeData node, AttributeStrategy attributeStrategy) {
    if (getDataModel() == null) {
        throw new ProcessingException("there is no data model set, call FormDataStatementBuilder.setDataModel to set one");
    }
    AttributePath attPath = DataModelUtility.externalIdToAttributePath(getDataModel(), node.getAttributeExternalId());
    IDataModelAttribute attribute = (attPath != null ? attPath.getAttribute() : null);
    if (attribute == null) {
        LOG.warn("no attribute for external id: {}", node.getAttributeExternalId());
        return new EntityContribution();
    }
    DataModelAttributePartDefinition def = m_dataModelAttMap.get(attribute.getClass());
    if (def == null) {
        Integer agg = node.getAggregationType();
        if (agg != null && agg == AGGREGATION_COUNT) {
            def = new DataModelAttributePartDefinition(null, "1", false);
        }
    }
    if (def == null) {
        LOG.warn("no PartDefinition for attribute: {}", attribute);
        return new EntityContribution();
    }
    List<Object> bindValues = new ArrayList<Object>();
    if (node.getValues() != null) {
        bindValues.addAll(node.getValues());
    }
    List<String> bindNames = new ArrayList<String>(bindValues.size());
    for (int i = 0; i < bindValues.size(); i++) {
        bindNames.add("" + (char) (((int) 'a') + i));
    }
    AliasMapper aliasMap = getAliasMapper();
    ComposerEntityNodeData parentEntityNode = FormDataStatementBuilder.getParentNodeOfType(node, ComposerEntityNodeData.class);
    Map<String, String> parentAliasMap = parentEntityNode != null ? aliasMap.getNodeAliases(parentEntityNode) : aliasMap.getRootAliases();
    String stm = null;
    switch(attributeStrategy) {
        case BuildConstraintOfAttribute:
        case BuildConstraintOfContext:
        case BuildConstraintOfAttributeWithContext:
            {
                stm = def.getWhereClause();
                break;
            }
        case BuildQueryOfAttributeAndConstraintOfContext:
            {
                stm = def.getSelectClause();
                break;
            }
    }
    EntityContribution contrib = null;
    if (stm != null) {
        contrib = def.createInstance(this, node, attributeStrategy, stm, bindNames, bindValues, parentAliasMap);
    }
    if (contrib == null) {
        contrib = new EntityContribution();
    }
    switch(attributeStrategy) {
        case BuildQueryOfAttributeAndConstraintOfContext:
            {
                if (contrib.getSelectParts().isEmpty()) {
                    contrib.getSelectParts().add("NULL");
                    contrib.getGroupByParts().add("NULL");
                }
                break;
            }
    }
    if (hasInjections()) {
        injectPostBuildAttribute(node, attributeStrategy, contrib);
    }
    return contrib;
}
Also used : ArrayList(java.util.ArrayList) IDataModelAttribute(org.eclipse.scout.rt.shared.data.model.IDataModelAttribute) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ComposerEntityNodeData(org.eclipse.scout.rt.shared.data.form.fields.composer.ComposerEntityNodeData) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException) AttributePath(org.eclipse.scout.rt.shared.data.model.AttributePath)

Example 5 with IDataModelAttribute

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

the class FormDataStatementBuilderCheck method checkDataModelAttribute.

protected void checkDataModelAttribute(AttributePath aPath) {
    IDataModelAttribute a = aPath.getAttribute();
    DataModelAttributePartDefinition part = builder.getDataModelAttributePartDefinitions().get(a.getClass());
    if (part == null) {
        if (a.getClass().getSimpleName().endsWith("CountAttribute")) {
            // default aggregate count attribute
            return;
        }
        String parentName = "";
        EntityPath parentPath = aPath.getEntityPath();
        if (!parentPath.isEmpty()) {
            parentName = entityToName(parentPath);
        }
        String name = attributeToName(aPath);
        String sqlColumnName = toSqlColumn(name);
        // 
        String sqlTemplate;
        if (!parentPath.isEmpty()) {
            sqlTemplate = "\"@${parentName}@.${sqlColumnName}\"";
        } else {
            sqlTemplate = "\"${sqlColumnName}\"";
        }
        String sql = sqlTemplate.replace("${sqlColumnName}", sqlColumnName).replace("${parentName}", parentName);
        addBodyLine("setComposerAttributeDefinition(" + resolveImport(a.getClass()) + ".class," + sql + ");");
    }
}
Also used : EntityPath(org.eclipse.scout.rt.shared.data.model.EntityPath) IDataModelAttribute(org.eclipse.scout.rt.shared.data.model.IDataModelAttribute)

Aggregations

IDataModelAttribute (org.eclipse.scout.rt.shared.data.model.IDataModelAttribute)8 ITreeNode (org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode)3 EntityPath (org.eclipse.scout.rt.shared.data.model.EntityPath)3 IDataModelAttributeOp (org.eclipse.scout.rt.shared.data.model.IDataModelAttributeOp)3 ArrayList (java.util.ArrayList)2 ComposerEntityNodeData (org.eclipse.scout.rt.shared.data.form.fields.composer.ComposerEntityNodeData)2 AttributePath (org.eclipse.scout.rt.shared.data.model.AttributePath)2 IDataModelEntity (org.eclipse.scout.rt.shared.data.model.IDataModelEntity)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 ComposerAttributeForm (org.eclipse.scout.rt.client.ui.form.fields.composer.internal.ComposerAttributeForm)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 Element (org.w3c.dom.Element)1