Search in sources :

Example 1 with ExtendedEntities

use of com.haulmont.cuba.core.global.ExtendedEntities in project cuba by cuba-platform.

the class ExcludeAction method doRemove.

@SuppressWarnings("unchecked")
@Override
protected void doRemove(Set<Entity> selected, boolean autocommit) {
    @SuppressWarnings({ "unchecked" }) 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) {
                        item.setValue(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;
        }
    }
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) PropertyDatasource(com.haulmont.cuba.gui.data.PropertyDatasource) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) NestedDatasource(com.haulmont.cuba.gui.data.NestedDatasource) ExtendedEntities(com.haulmont.cuba.core.global.ExtendedEntities) Entity(com.haulmont.cuba.core.entity.Entity) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) NestedDatasource(com.haulmont.cuba.gui.data.NestedDatasource) MetaClass(com.haulmont.chile.core.model.MetaClass) MetaProperty(com.haulmont.chile.core.model.MetaProperty)

Example 2 with ExtendedEntities

use of com.haulmont.cuba.core.global.ExtendedEntities in project cuba by cuba-platform.

the class SetupAttributeAccessEvent method getResolvableType.

@Override
public ResolvableType getResolvableType() {
    ExtendedEntities extendedEntities = AppBeans.get(ExtendedEntities.NAME);
    MetaClass metaClass = extendedEntities.getOriginalOrThisMetaClass(getEntity().getMetaClass());
    return ResolvableType.forClassWithGenerics(getClass(), ResolvableType.forClass(metaClass.getJavaClass()));
}
Also used : ExtendedEntities(com.haulmont.cuba.core.global.ExtendedEntities) MetaClass(com.haulmont.chile.core.model.MetaClass)

Example 3 with ExtendedEntities

use of com.haulmont.cuba.core.global.ExtendedEntities in project cuba by cuba-platform.

the class WebTokenList method isInversePropertyAssignableFromDsClass.

protected boolean isInversePropertyAssignableFromDsClass(MetaProperty inverseProp) {
    Metadata metadata = AppBeans.get(Metadata.NAME);
    ExtendedEntities extendedEntities = metadata.getExtendedEntities();
    Class inversePropClass = extendedEntities.getEffectiveClass(inverseProp.getDomain());
    Class dsClass = extendedEntities.getEffectiveClass(datasource.getMetaClass());
    // noinspection unchecked
    return inversePropClass.isAssignableFrom(dsClass);
}
Also used : ExtendedEntities(com.haulmont.cuba.core.global.ExtendedEntities) Metadata(com.haulmont.cuba.core.global.Metadata)

Example 4 with ExtendedEntities

use of com.haulmont.cuba.core.global.ExtendedEntities in project cuba by cuba-platform.

the class DesktopTokenList method isInversePropertyAssignableFromDsClass.

protected boolean isInversePropertyAssignableFromDsClass(MetaProperty inverseProp) {
    Metadata metadata = AppBeans.get(Metadata.NAME);
    ExtendedEntities extendedEntities = metadata.getExtendedEntities();
    Class inversePropClass = extendedEntities.getEffectiveClass(inverseProp.getDomain());
    Class dsClass = extendedEntities.getEffectiveClass(datasource.getMetaClass());
    // noinspection unchecked
    return inversePropClass.isAssignableFrom(dsClass);
}
Also used : ExtendedEntities(com.haulmont.cuba.core.global.ExtendedEntities) Metadata(com.haulmont.cuba.core.global.Metadata)

Aggregations

ExtendedEntities (com.haulmont.cuba.core.global.ExtendedEntities)4 MetaClass (com.haulmont.chile.core.model.MetaClass)2 Metadata (com.haulmont.cuba.core.global.Metadata)2 MetaProperty (com.haulmont.chile.core.model.MetaProperty)1 Entity (com.haulmont.cuba.core.entity.Entity)1 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)1 Datasource (com.haulmont.cuba.gui.data.Datasource)1 NestedDatasource (com.haulmont.cuba.gui.data.NestedDatasource)1 PropertyDatasource (com.haulmont.cuba.gui.data.PropertyDatasource)1