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);
}
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);
}
}
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);
}
}
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());
}
}
Aggregations