use of io.jmix.core.metamodel.model.MetaProperty in project jmix by jmix-framework.
the class BulkEditorWindow method createFetchPlan.
protected FetchPlan createFetchPlan(MetaClass metaClass) {
FetchPlanBuilder builder = fetchPlans.builder(metaClass.getJavaClass());
for (MetaProperty metaProperty : metaClass.getProperties()) {
String fqn = generateFqn(metaProperty, null);
if (!managedFields.containsKey(fqn) && !managedEmbeddedProperties.contains(fqn)) {
continue;
}
addFetchPlanProperties(builder, metaProperty, fqn);
}
return builder.build();
}
use of io.jmix.core.metamodel.model.MetaProperty in project jmix by jmix-framework.
the class BulkEditorWindow method createEmbeddedFetchPlan.
protected FetchPlan createEmbeddedFetchPlan(MetaClass metaClass, String fqnPrefix) {
FetchPlanBuilder builder = fetchPlans.builder(metaClass.getJavaClass());
for (MetaProperty metaProperty : metaClass.getProperties()) {
String fqn = generateFqn(metaProperty, fqnPrefix);
if (!managedFields.containsKey(fqn)) {
continue;
}
addFetchPlanProperties(builder, metaProperty, fqn);
}
return builder.build();
}
use of io.jmix.core.metamodel.model.MetaProperty in project jmix by jmix-framework.
the class BulkEditorWindow method getManagedFields.
protected List<ManagedField> getManagedFields(MetaClass metaClass, @Nullable String fqnPrefix, @Nullable String localePrefix) {
List<ManagedField> managedFields = new ArrayList<>();
for (MetaProperty metaProperty : metaClass.getProperties()) {
if (isManagedAttribute(metaClass, metaProperty)) {
String fqn = generateFqn(metaProperty, fqnPrefix);
String propertyCaption = generatePropertyCaption(metaClass, metaProperty, localePrefix);
if (!metadataTools.isEmbedded(metaProperty)) {
managedFields.add(new ManagedField(fqn, metaProperty, propertyCaption, fqnPrefix));
} else {
List<ManagedField> nestedFields = getManagedFields(metaProperty, fqn, propertyCaption);
if (nestedFields.size() > 0) {
managedEmbeddedProperties.add(fqn);
}
managedFields.addAll(nestedFields);
}
}
}
return managedFields;
}
use of io.jmix.core.metamodel.model.MetaProperty in project jmix by jmix-framework.
the class BulkEditorWindow method ensureEmbeddedPropertyCreated.
protected void ensureEmbeddedPropertyCreated(E item, String propertyPath) {
if (!StringUtils.contains(propertyPath, ".")) {
return;
}
MetaPropertyPath path = context.getMetaClass().getPropertyPath(propertyPath);
if (path != null) {
Object currentItem = item;
for (MetaProperty property : path.getMetaProperties()) {
if (metadataTools.isEmbedded(property)) {
Object currentItemValue = EntityValues.getValue(currentItem, property.getName());
if (currentItemValue == null) {
Object newItem = metadata.create(property.getRange().asClass());
EntityValues.setValue(currentItem, property.getName(), newItem);
currentItem = newItem;
} else {
currentItem = currentItemValue;
}
} else {
break;
}
}
}
}
use of io.jmix.core.metamodel.model.MetaProperty in project jmix by jmix-framework.
the class StandardEditor method isEntityModifiedRecursive.
protected boolean isEntityModifiedRecursive(Object entity, DataContext dataContext, HashSet<Object> visited) {
if (visited.contains(entity)) {
return false;
}
visited.add(entity);
if (dataContext.isModified(entity) || dataContext.isRemoved(entity))
return true;
Metadata metadata = getApplicationContext().getBean(Metadata.class);
for (MetaProperty property : metadata.getClass(entity).getProperties()) {
if (property.getRange().isClass()) {
if (getEntityStates().isLoaded(entity, property.getName())) {
Object value = EntityValues.getValue(entity, property.getName());
if (value != null) {
if (value instanceof Collection) {
for (Object item : ((Collection) value)) {
if (isEntityModifiedRecursive(item, dataContext, visited)) {
return true;
}
}
} else {
if (isEntityModifiedRecursive(value, dataContext, visited)) {
return true;
}
}
}
}
}
}
return false;
}
Aggregations