Search in sources :

Example 1 with Session

use of io.jmix.core.metamodel.model.Session in project jmix by jmix-framework.

the class KeyValueMetaPropertyBuilder method build.

public KeyValueMetaProperty build(MetaClass metaClass, String name, Class javaClass) {
    MetaProperty.Type type;
    Range range;
    Session metadataSession = metadata.getSession();
    if (Entity.class.isAssignableFrom(javaClass)) {
        range = new ClassRange(metadataSession.findClass(javaClass));
        type = MetaProperty.Type.ASSOCIATION;
    } else if (EnumClass.class.isAssignableFrom(javaClass)) {
        @SuppressWarnings("unchecked") EnumerationImpl enumeration = new EnumerationImpl(javaClass);
        range = new EnumerationRange(enumeration);
        type = MetaProperty.Type.ENUM;
    } else {
        @SuppressWarnings("unchecked") Datatype datatype = datatypeRegistry.get(javaClass);
        range = new DatatypeRange(datatype);
        type = MetaProperty.Type.DATATYPE;
    }
    return new KeyValueMetaProperty(metaClass, name, javaClass, range, type);
}
Also used : ClassRange(io.jmix.core.metamodel.model.impl.ClassRange) EnumerationImpl(io.jmix.core.metamodel.datatype.impl.EnumerationImpl) EnumClass(io.jmix.core.metamodel.datatype.impl.EnumClass) MetaProperty(io.jmix.core.metamodel.model.MetaProperty) EnumerationRange(io.jmix.core.metamodel.model.impl.EnumerationRange) ClassRange(io.jmix.core.metamodel.model.impl.ClassRange) Range(io.jmix.core.metamodel.model.Range) DatatypeRange(io.jmix.core.metamodel.model.impl.DatatypeRange) EnumerationRange(io.jmix.core.metamodel.model.impl.EnumerationRange) DatatypeRange(io.jmix.core.metamodel.model.impl.DatatypeRange) Session(io.jmix.core.metamodel.model.Session) Datatype(io.jmix.core.metamodel.datatype.Datatype)

Example 2 with Session

use of io.jmix.core.metamodel.model.Session in project jmix by jmix-framework.

the class ExtendedEntities method replaceExtendedMetaClasses.

protected void replaceExtendedMetaClasses() {
    Session session = metadata.getSession();
    List<Pair<MetaClass, MetaClass>> replaceMap = new ArrayList<>();
    for (MetaClass metaClass : session.getClasses()) {
        MetaClass effectiveMetaClass = session.getClass(getEffectiveClass(metaClass));
        if (effectiveMetaClass != metaClass) {
            replaceMap.add(new Pair<>(metaClass, effectiveMetaClass));
        }
        for (MetaProperty metaProperty : metaClass.getOwnProperties()) {
            MetaPropertyImpl propertyImpl = (MetaPropertyImpl) metaProperty;
            // replace domain
            Class effectiveDomainClass = getEffectiveClass(metaProperty.getDomain());
            MetaClass effectiveDomainMeta = session.getClass(effectiveDomainClass);
            if (metaProperty.getDomain() != effectiveDomainMeta) {
                propertyImpl.setDomain(effectiveDomainMeta);
            }
            if (metaProperty.getRange().isClass()) {
                // replace range class
                ClassRange range = (ClassRange) metaProperty.getRange();
                Class effectiveRangeClass = getEffectiveClass(range.asClass());
                MetaClass effectiveRangeMeta = session.getClass(effectiveRangeClass);
                if (effectiveRangeMeta != range.asClass()) {
                    ClassRange newRange = new ClassRange(effectiveRangeMeta);
                    newRange.setCardinality(range.getCardinality());
                    newRange.setOrdered(range.isOrdered());
                    ((MetaPropertyImpl) metaProperty).setRange(newRange);
                }
            }
        }
    }
    for (Pair<MetaClass, MetaClass> replace : replaceMap) {
        MetaClass replacedMetaClass = replace.getFirst();
        registerReplacedMetaClass(replacedMetaClass);
        MetaClassImpl effectiveMetaClass = (MetaClassImpl) replace.getSecond();
        ((SessionImpl) session).registerClass(replacedMetaClass.getName(), replacedMetaClass.getJavaClass(), effectiveMetaClass);
    }
}
Also used : ClassRange(io.jmix.core.metamodel.model.impl.ClassRange) ArrayList(java.util.ArrayList) MetaPropertyImpl(io.jmix.core.metamodel.model.impl.MetaPropertyImpl) MetaClass(io.jmix.core.metamodel.model.MetaClass) KeyValueMetaClass(io.jmix.core.impl.keyvalue.KeyValueMetaClass) MetaClass(io.jmix.core.metamodel.model.MetaClass) KeyValueMetaClass(io.jmix.core.impl.keyvalue.KeyValueMetaClass) SessionImpl(io.jmix.core.metamodel.model.impl.SessionImpl) MetaProperty(io.jmix.core.metamodel.model.MetaProperty) MetaClassImpl(io.jmix.core.metamodel.model.impl.MetaClassImpl) Session(io.jmix.core.metamodel.model.Session) Pair(io.jmix.core.common.datastruct.Pair)

Example 3 with Session

use of io.jmix.core.metamodel.model.Session in project jmix by jmix-framework.

the class EntityInspectorBrowser method onBeforeShow.

// to handle the usage of entityName public setter
@Subscribe
public void onBeforeShow(BeforeShowEvent event) {
    if (entityName != null) {
        Session session = metadata.getSession();
        selectedMeta = session.getClass(entityName);
        createEntitiesTable(selectedMeta);
        lookupBox.setVisible(false);
    }
}
Also used : Session(io.jmix.core.metamodel.model.Session)

Example 4 with Session

use of io.jmix.core.metamodel.model.Session in project jmix by jmix-framework.

the class EntityInspectorBrowser method onInit.

@Subscribe
public void onInit(InitEvent event) {
    showMode.setValue(ShowMode.NON_REMOVED);
    ScreenOptions screenOptions = event.getOptions();
    String entityParam = screenOptions instanceof MapScreenOptions ? (String) ((MapScreenOptions) screenOptions).getParams().get("entity") : null;
    getScreenData().setDataContext(dataComponents.createDataContext());
    if (entityParam != null) {
        Session session = metadata.getSession();
        selectedMeta = session.getClass(entityParam);
        createEntitiesTable(selectedMeta);
        lookupBox.setVisible(false);
    } else {
        entitiesLookup.setOptionsMap(getEntitiesLookupFieldOptions());
        entitiesLookup.addValueChangeListener(e -> showEntities());
        showMode.addValueChangeListener(e -> showEntities());
    }
}
Also used : Session(io.jmix.core.metamodel.model.Session)

Aggregations

Session (io.jmix.core.metamodel.model.Session)4 MetaProperty (io.jmix.core.metamodel.model.MetaProperty)2 ClassRange (io.jmix.core.metamodel.model.impl.ClassRange)2 Pair (io.jmix.core.common.datastruct.Pair)1 KeyValueMetaClass (io.jmix.core.impl.keyvalue.KeyValueMetaClass)1 Datatype (io.jmix.core.metamodel.datatype.Datatype)1 EnumClass (io.jmix.core.metamodel.datatype.impl.EnumClass)1 EnumerationImpl (io.jmix.core.metamodel.datatype.impl.EnumerationImpl)1 MetaClass (io.jmix.core.metamodel.model.MetaClass)1 Range (io.jmix.core.metamodel.model.Range)1 DatatypeRange (io.jmix.core.metamodel.model.impl.DatatypeRange)1 EnumerationRange (io.jmix.core.metamodel.model.impl.EnumerationRange)1 MetaClassImpl (io.jmix.core.metamodel.model.impl.MetaClassImpl)1 MetaPropertyImpl (io.jmix.core.metamodel.model.impl.MetaPropertyImpl)1 SessionImpl (io.jmix.core.metamodel.model.impl.SessionImpl)1 ArrayList (java.util.ArrayList)1