Search in sources :

Example 21 with KeyValueEntity

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);
}
Also used : KeyValueEntity(io.jmix.core.entity.KeyValueEntity) Entity(io.jmix.core.Entity) MetaClass(io.jmix.core.metamodel.model.MetaClass) KeyValueEntity(io.jmix.core.entity.KeyValueEntity)

Example 22 with KeyValueEntity

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);
    });
}
Also used : KeyValueEntity(io.jmix.core.entity.KeyValueEntity)

Example 23 with KeyValueEntity

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);
}
Also used : ValueLoadContext(io.jmix.core.ValueLoadContext) KeyValueEntity(io.jmix.core.entity.KeyValueEntity)

Aggregations

KeyValueEntity (io.jmix.core.entity.KeyValueEntity)23 ValueLoadContext (io.jmix.core.ValueLoadContext)3 MetaClass (io.jmix.core.metamodel.model.MetaClass)3 MetaProperty (io.jmix.core.metamodel.model.MetaProperty)3 EntityMap (io.jmix.reports.app.EntityMap)2 JmixTableData (io.jmix.reports.entity.JmixTableData)2 BigDecimal (java.math.BigDecimal)2 ArrayList (java.util.ArrayList)2 EntityManager (javax.persistence.EntityManager)2 Query (javax.persistence.Query)2 TransactionTemplate (org.springframework.transaction.support.TransactionTemplate)2 ValueLoadContext (com.haulmont.cuba.core.global.ValueLoadContext)1 BandData (com.haulmont.yarg.structure.BandData)1 Customer (dataaccess.ex1.entity.Customer)1 Customer (datamodel.ex1.entity.Customer)1 DataManager (io.jmix.core.DataManager)1 Entity (io.jmix.core.Entity)1 Metadata (io.jmix.core.Metadata)1 MetadataTools (io.jmix.core.MetadataTools)1 EntityListParameterValue (io.jmix.dashboards.model.parameter.type.EntityListParameterValue)1