use of io.jmix.core.entity.KeyValueEntity in project jmix by jmix-framework.
the class CaptionAdapter method apply.
@Override
public String apply(Object entity) {
if (!(entity instanceof Entity)) {
return "";
}
if (captionProperty != null) {
MetaClass entityMetaClass;
if (entity instanceof KeyValueEntity) {
entityMetaClass = ((KeyValueEntity) entity).getInstanceMetaClass();
} else {
entityMetaClass = metadata.getClass(entity);
}
if (entityMetaClass.getPropertyPath(captionProperty) == null) {
throw new IllegalArgumentException(String.format("Couldn't find property with name '%s'", captionProperty));
}
Object propertyValue = EntityValues.getValueEx(entity, captionProperty);
return propertyValue != null ? propertyValue.toString() : " ";
}
return metadataTools.getInstanceName(entity);
}
use of io.jmix.core.entity.KeyValueEntity in project jmix by jmix-framework.
the class KeyValueCollectionContainerImpl method getMutableItems.
@Override
public List<KeyValueEntity> getMutableItems() {
return new ObservableList<>(collection, idMap, (changeType, changes) -> {
buildIdMap();
clearItemIfNotExists();
if (changeType == CollectionChangeType.ADD_ITEMS || changeType == CollectionChangeType.SET_ITEM) {
for (KeyValueEntity entity : changes) {
updateEntityMetadata(entity);
}
} else if (changeType == CollectionChangeType.REFRESH) {
for (KeyValueEntity entity : collection) {
updateEntityMetadata(entity);
}
}
fireCollectionChanged(changeType, changes);
});
}
use of io.jmix.core.entity.KeyValueEntity in project jmix by jmix-framework.
the class KeyValueInstanceLoaderImpl method load.
@Override
public void load() {
if (container == null)
throw new IllegalStateException("container is null");
if (query == null && delegate == null)
throw new IllegalStateException("both query and delegate are null");
ValueLoadContext loadContext = createLoadContext();
if (!sendPreLoadEvent(loadContext)) {
return;
}
KeyValueEntity result = null;
if (delegate == null) {
List<KeyValueEntity> list = dataManager.loadValues(loadContext);
if (!list.isEmpty()) {
result = list.get(0);
}
} else {
result = delegate.apply(loadContext);
}
container.setItem(result);
sendPostLoadEvent(result);
}
Aggregations