use of com.haulmont.chile.core.model.MetaProperty in project cuba by cuba-platform.
the class BulkEditorWindow method createNestedEmbeddedDatasources.
protected void createNestedEmbeddedDatasources(Datasource masterDs, MetaClass metaClass, String fqnPrefix) {
for (MetaProperty metaProperty : metaClass.getProperties()) {
if (MetaProperty.Type.ASSOCIATION == metaProperty.getType() || MetaProperty.Type.COMPOSITION == metaProperty.getType()) {
String fqn = metaProperty.getName();
if (StringUtils.isNotEmpty(fqnPrefix)) {
fqn = fqnPrefix + "." + fqn;
}
if (managedEmbeddedProperties.contains(fqn) && metadataTools.isEmbedded(metaProperty)) {
MetaClass propertyMetaClass = metaProperty.getRange().asClass();
@SuppressWarnings("unchecked") NestedDatasource<Entity> propertyDs = new EmbeddedDatasourceImpl();
propertyDs.setup(fqn + "Ds", masterDs, metaProperty.getName());
propertyDs.setAllowCommit(false);
createNestedEmbeddedDatasources(propertyDs, propertyMetaClass, fqn);
datasources.put(fqn, propertyDs);
dsContext.register(propertyDs);
}
}
}
}
use of com.haulmont.chile.core.model.MetaProperty in project cuba by cuba-platform.
the class BulkEditorWindow method getManagedFields.
protected List<ManagedField> getManagedFields(MetaProperty embeddedProperty, String fqnPrefix, String localePrefix) {
List<ManagedField> managedFields = new ArrayList<>();
MetaClass metaClass = embeddedProperty.getRange().asClass();
for (MetaProperty metaProperty : metaClass.getProperties()) {
if (isManagedAttribute(metaClass, metaProperty)) {
String fqn = fqnPrefix + "." + metaProperty.getName();
String localeName = localePrefix + " " + messageTools.getPropertyCaption(metaClass, metaProperty.getName());
if (!metadataTools.isEmbedded(metaProperty)) {
managedFields.add(new ManagedField(fqn, metaProperty, localeName, fqnPrefix));
} else {
List<ManagedField> nestedFields = getManagedFields(metaProperty, fqn, localeName);
if (nestedFields.size() > 0) {
managedEmbeddedProperties.add(fqn);
}
managedFields.addAll(nestedFields);
}
}
}
return managedFields;
}
use of com.haulmont.chile.core.model.MetaProperty in project cuba by cuba-platform.
the class BulkEditorWindow method createEmbeddedFields.
/**
* Recursively instantiates the embedded properties.
* E.g. embedded properties of the embedded property will also be instantiated.
*
* @param metaClass meta class of the entity
* @param item entity instance
*/
protected void createEmbeddedFields(MetaClass metaClass, Entity item, String fqnPrefix) {
for (MetaProperty metaProperty : metaClass.getProperties()) {
String fqn = metaProperty.getName();
if (StringUtils.isNotEmpty(fqnPrefix)) {
fqn = fqnPrefix + "." + fqn;
}
if (managedEmbeddedProperties.contains(fqn) && metadataTools.isEmbedded(metaProperty)) {
MetaClass embeddedMetaClass = metaProperty.getRange().asClass();
Entity embedded = item.getValue(metaProperty.getName());
if (embedded == null) {
embedded = metadata.create(embeddedMetaClass);
item.setValue(metaProperty.getName(), embedded);
}
createEmbeddedFields(embeddedMetaClass, embedded, fqn);
}
}
}
use of com.haulmont.chile.core.model.MetaProperty in project cuba by cuba-platform.
the class BulkEditorWindow method ensureEmbeddedPropertyCreated.
protected void ensureEmbeddedPropertyCreated(Entity item, String propertyPath) {
if (!StringUtils.contains(propertyPath, ".")) {
return;
}
MetaPropertyPath path = metaClass.getPropertyPath(propertyPath);
if (path != null) {
Entity currentItem = item;
for (MetaProperty property : path.getMetaProperties()) {
if (metadataTools.isEmbedded(property)) {
Object currentItemValue = currentItem.getValue(property.getName());
if (currentItemValue == null) {
Entity newItem = metadata.create(property.getRange().asClass());
currentItem.setValue(property.getName(), newItem);
currentItem = newItem;
} else {
currentItem = (Entity) currentItemValue;
}
} else {
break;
}
}
}
}
use of com.haulmont.chile.core.model.MetaProperty in project cuba by cuba-platform.
the class BulkEditorWindow method getManagedFields.
protected List<ManagedField> getManagedFields(MetaClass metaClass) {
List<ManagedField> managedFields = new ArrayList<>();
// sort Fields
for (MetaProperty metaProperty : metaClass.getProperties()) {
if (isManagedAttribute(metaClass, metaProperty)) {
String propertyCaption = messageTools.getPropertyCaption(metaClass, metaProperty.getName());
if (!metadataTools.isEmbedded(metaProperty)) {
managedFields.add(new ManagedField(metaProperty.getName(), metaProperty, propertyCaption, null));
} else {
List<ManagedField> nestedFields = getManagedFields(metaProperty, metaProperty.getName(), propertyCaption);
if (nestedFields.size() > 0) {
managedEmbeddedProperties.add(metaProperty.getName());
}
managedFields.addAll(nestedFields);
}
}
}
if (loadDynamicAttributes) {
List<CategoryAttribute> categoryAttributes = (List<CategoryAttribute>) dynamicAttributes.getAttributesForMetaClass(metaClass);
if (!categoryAttributes.isEmpty()) {
for (CategoryAttribute attribute : categoryAttributes) {
MetaPropertyPath metaPropertyPath = DynamicAttributesUtils.getMetaPropertyPath(metaClass, attribute);
String propertyCaption = attribute.getLocaleName();
if (isManagedDynamicAttribute(metaClass, metaPropertyPath.getMetaProperty())) {
managedFields.add(new ManagedField(metaPropertyPath.getMetaProperty().getName(), metaPropertyPath.getMetaProperty(), propertyCaption, null));
}
}
}
}
return managedFields;
}
Aggregations