use of io.jmix.core.ExtendedEntities in project jmix by jmix-framework.
the class OriginalEntityLoadInfo method create.
/**
* Create a new info instance.
* @param entity entity instance
* @return info instance
*/
public static OriginalEntityLoadInfo create(Entity entity) {
Objects.requireNonNull(entity, "entity is null");
Metadata metadata = AppBeans.get(Metadata.class);
MetadataTools metadataTools = AppBeans.get(MetadataTools.class);
ExtendedEntities extendedEntities = AppBeans.get(ExtendedEntities.class);
MetaClass metaClass = metadata.getSession().getClass(entity.getClass());
MetaClass originalMetaClass = extendedEntities.getOriginalMetaClass(metaClass);
if (originalMetaClass != null) {
metaClass = originalMetaClass;
}
MetaProperty primaryKeyProperty = metadataTools.getPrimaryKeyProperty(metaClass);
boolean stringKey = primaryKeyProperty != null && primaryKeyProperty.getJavaType().equals(String.class);
return new OriginalEntityLoadInfo((UUID) EntityValues.getId(entity), metaClass, stringKey);
}
use of io.jmix.core.ExtendedEntities in project jmix by jmix-framework.
the class ExcludeAction method doRemove.
@SuppressWarnings("unchecked")
@Override
protected void doRemove(Set<Entity> selected, boolean autocommit) {
CollectionDatasource ds = target.getDatasource();
if (ds instanceof NestedDatasource) {
// Clear reference to master entity
Datasource masterDs = ((NestedDatasource) ds).getMaster();
MetaProperty metaProperty = ((NestedDatasource) ds).getProperty();
if (masterDs != null && metaProperty != null) {
MetaProperty inverseProp = metaProperty.getInverse();
if (inverseProp != null) {
ExtendedEntities extendedEntities = metadata.getExtendedEntities();
Class inversePropClass = extendedEntities.getEffectiveClass(inverseProp.getDomain());
Class dsClass = extendedEntities.getEffectiveClass(ds.getMetaClass());
if (inversePropClass.isAssignableFrom(dsClass)) {
for (Entity item : selected) {
EntityValues.setValue(item, inverseProp.getName(), null);
}
}
}
}
}
for (Entity item : selected) {
ds.modifyItem(item);
ds.excludeItem(item);
}
if (autocommit && (ds.getCommitMode() != Datasource.CommitMode.PARENT)) {
try {
ds.commit();
} catch (RuntimeException e) {
ds.refresh();
throw e;
}
}
}
use of io.jmix.core.ExtendedEntities in project jmix by jmix-framework.
the class CreateAction method actionPerform.
/**
* This method is invoked by action owner component. Don't override it, there are special methods to
* customize behaviour below.
*
* @param component component invoking action
*/
@Override
public void actionPerform(Component component) {
if (beforeActionPerformedHandler != null) {
if (!beforeActionPerformedHandler.beforeActionPerformed())
return;
}
final CollectionDatasource datasource = target.getDatasource();
Entity item = createEntity();
if (target instanceof Tree) {
String hierarchyProperty = ((Tree) target).getHierarchyProperty();
Entity parentItem = datasource.getItem();
// datasource.getItem() may contain deleted item
if (parentItem != null && !datasource.containsItem(EntityValues.getId(parentItem))) {
parentItem = null;
}
EntityValues.setValue(item, hierarchyProperty, parentItem);
}
if (datasource instanceof NestedDatasource) {
// Initialize reference to master entity
Datasource masterDs = ((NestedDatasource) datasource).getMaster();
MetaProperty metaProperty = ((NestedDatasource) datasource).getProperty();
if (masterDs != null && metaProperty != null) {
MetaProperty inverseProp = metaProperty.getInverse();
if (inverseProp != null) {
ExtendedEntities extendedEntities = metadata.getExtendedEntities();
Class inversePropClass = extendedEntities.getEffectiveClass(inverseProp.getDomain());
Class dsClass = extendedEntities.getEffectiveClass(datasource.getMetaClass());
if (inversePropClass.isAssignableFrom(dsClass)) {
EntityValues.setValue(item, inverseProp.getName(), masterDs.getItem());
}
}
}
}
setInitialValuesToItem(item);
Datasource parentDs = null;
if (datasource instanceof PropertyDatasource) {
MetaProperty metaProperty = ((PropertyDatasource) datasource).getProperty();
if (metaProperty.getType().equals(MetaProperty.Type.COMPOSITION)) {
parentDs = datasource;
}
}
Map<String, Object> params = prepareWindowParams();
internalOpenEditor(datasource, item, parentDs, params);
}
use of io.jmix.core.ExtendedEntities in project jmix by jmix-framework.
the class LegacyCollectionDsValueSource method canUpdateMasterRefs.
protected boolean canUpdateMasterRefs() {
MetaPropertyPath mpp = getMaster().getMetaClass().getPropertyPath(metaPropertyPath.toPathString());
if (mpp == null) {
return false;
}
if (!mpp.getMetaProperty().getRange().getCardinality().isMany()) {
return false;
}
MetaProperty inverseProperty = mpp.getMetaProperty().getInverse();
if (inverseProperty == null || inverseProperty.getType() != MetaProperty.Type.ASSOCIATION || inverseProperty.getRange().getCardinality().isMany()) {
return false;
}
ExtendedEntities extendedEntities = metadata.getExtendedEntities();
Class invPropEntityClass = extendedEntities.getEffectiveClass(inverseProperty.getDomain());
Class datasourceEntityClass = datasource.getMetaClass().getJavaClass();
// noinspection unchecked
return invPropEntityClass.isAssignableFrom(datasourceEntityClass);
}
use of io.jmix.core.ExtendedEntities in project jmix by jmix-framework.
the class EntityChangedEvent method getResolvableType.
/**
* INTERNAL.
*/
@Internal
@Override
public ResolvableType getResolvableType() {
Metadata metadata = AppBeans.get(Metadata.class);
ExtendedEntities extendedEntities = metadata.getExtendedEntities();
MetaClass metaClass = extendedEntities.getOriginalOrThisMetaClass(metadata.getClassNN(entityId.getEntityClass()));
MetaProperty pkProperty = metadata.getTools().getPrimaryKeyProperty(metaClass);
if (pkProperty == null) {
throw new IllegalStateException("Unable to send EntityChangedEvent for " + metaClass + " because it has no primary key");
}
return ResolvableType.forClassWithGenerics(getClass(), ResolvableType.forClass(metaClass.getJavaClass()), ResolvableType.forClass(pkProperty.getJavaType()));
}
Aggregations