Search in sources :

Example 1 with HasInstanceMetaClass

use of io.jmix.core.entity.HasInstanceMetaClass in project jmix by jmix-framework.

the class InstanceContainerImpl method setItem.

@Override
public void setItem(@Nullable E item) {
    E prevItem = this.item;
    if (this.item != null) {
        detachListener(this.item);
    }
    if (item != null) {
        MetaClass aClass = item instanceof HasInstanceMetaClass ? ((HasInstanceMetaClass) item).getInstanceMetaClass() : metadata.getClass(item);
        if (!aClass.equals(entityMetaClass) && !entityMetaClass.getDescendants().contains(aClass)) {
            throw new DevelopmentException(String.format("Invalid item's metaClass '%s'", aClass), ParamsMap.of("container", toString(), "metaClass", aClass));
        }
        detachListener(item);
        attachListener(item);
    }
    this.item = item;
    fireItemChanged(prevItem);
}
Also used : HasInstanceMetaClass(io.jmix.core.entity.HasInstanceMetaClass) MetaClass(io.jmix.core.metamodel.model.MetaClass) HasInstanceMetaClass(io.jmix.core.entity.HasInstanceMetaClass) DevelopmentException(io.jmix.core.DevelopmentException)

Aggregations

DevelopmentException (io.jmix.core.DevelopmentException)1 HasInstanceMetaClass (io.jmix.core.entity.HasInstanceMetaClass)1 MetaClass (io.jmix.core.metamodel.model.MetaClass)1