Search in sources :

Example 1 with NestedDatasource

use of com.haulmont.cuba.gui.data.NestedDatasource 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 NestedDatasource

use of com.haulmont.cuba.gui.data.NestedDatasource in project cuba by cuba-platform.

the class DesktopTokenList method getInverseProperty.

@Nullable
protected MetaProperty getInverseProperty(CollectionDatasource datasource) {
    if (datasource instanceof NestedDatasource) {
        MetaProperty metaProperty = ((NestedDatasource) datasource).getProperty();
        com.google.common.base.Preconditions.checkState(metaProperty != null);
        return metaProperty.getInverse();
    }
    return null;
}
Also used : NestedDatasource(com.haulmont.cuba.gui.data.NestedDatasource) MetaProperty(com.haulmont.chile.core.model.MetaProperty) Nullable(javax.annotation.Nullable)

Example 3 with NestedDatasource

use of com.haulmont.cuba.gui.data.NestedDatasource in project cuba by cuba-platform.

the class WebTokenList method getInverseProperty.

@Nullable
protected MetaProperty getInverseProperty(CollectionDatasource datasource) {
    if (datasource instanceof NestedDatasource) {
        MetaProperty metaProperty = ((NestedDatasource) datasource).getProperty();
        com.google.common.base.Preconditions.checkState(metaProperty != null);
        return metaProperty.getInverse();
    }
    return null;
}
Also used : NestedDatasource(com.haulmont.cuba.gui.data.NestedDatasource) MetaProperty(com.haulmont.chile.core.model.MetaProperty) Nullable(javax.annotation.Nullable)

Example 4 with NestedDatasource

use of com.haulmont.cuba.gui.data.NestedDatasource in project cuba by cuba-platform.

the class DesktopTokenList method getMasterEntity.

@Nullable
protected Entity getMasterEntity(CollectionDatasource datasource) {
    if (datasource instanceof NestedDatasource) {
        Datasource masterDs = ((NestedDatasource) datasource).getMaster();
        com.google.common.base.Preconditions.checkState(masterDs != null);
        return masterDs.getItem();
    }
    return null;
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) NestedDatasource(com.haulmont.cuba.gui.data.NestedDatasource) NestedDatasource(com.haulmont.cuba.gui.data.NestedDatasource) Nullable(javax.annotation.Nullable)

Example 5 with NestedDatasource

use of com.haulmont.cuba.gui.data.NestedDatasource in project cuba by cuba-platform.

the class WebTokenList method getMasterEntity.

@Nullable
protected Entity getMasterEntity(CollectionDatasource datasource) {
    if (datasource instanceof NestedDatasource) {
        Datasource masterDs = ((NestedDatasource) datasource).getMaster();
        com.google.common.base.Preconditions.checkState(masterDs != null);
        return masterDs.getItem();
    }
    return null;
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) NestedDatasource(com.haulmont.cuba.gui.data.NestedDatasource) NestedDatasource(com.haulmont.cuba.gui.data.NestedDatasource) Nullable(javax.annotation.Nullable)

Aggregations

NestedDatasource (com.haulmont.cuba.gui.data.NestedDatasource)5 Nullable (javax.annotation.Nullable)4 MetaProperty (com.haulmont.chile.core.model.MetaProperty)3 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)3 Datasource (com.haulmont.cuba.gui.data.Datasource)3 MetaClass (com.haulmont.chile.core.model.MetaClass)1 Entity (com.haulmont.cuba.core.entity.Entity)1 ExtendedEntities (com.haulmont.cuba.core.global.ExtendedEntities)1 PropertyDatasource (com.haulmont.cuba.gui.data.PropertyDatasource)1