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);
}
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;
}
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;
}
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;
}
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 + ");");
}
}
Aggregations