Search in sources :

Example 1 with Nested

use of com.haulmont.cuba.gui.model.Nested in project cuba by cuba-platform.

the class RemoveAction method checkRemovePermission.

protected boolean checkRemovePermission() {
    ContainerDataUnit<E> containerDataUnit = (ContainerDataUnit) target.getItems();
    MetaClass metaClass = containerDataUnit.getEntityMetaClass();
    if (metaClass == null) {
        return false;
    }
    boolean entityOpPermitted = security.isEntityOpPermitted(metaClass, EntityOp.DELETE);
    if (!entityOpPermitted) {
        return false;
    }
    if (containerDataUnit.getContainer() instanceof Nested) {
        Nested nestedContainer = (Nested) containerDataUnit.getContainer();
        MetaClass masterMetaClass = nestedContainer.getMaster().getEntityMetaClass();
        MetaProperty metaProperty = masterMetaClass.getPropertyNN(nestedContainer.getProperty());
        boolean attrPermitted = security.isEntityAttrUpdatePermitted(masterMetaClass, metaProperty.getName());
        if (!attrPermitted) {
            return false;
        }
    }
    return true;
}
Also used : MetaClass(com.haulmont.chile.core.model.MetaClass) Nested(com.haulmont.cuba.gui.model.Nested) ContainerDataUnit(com.haulmont.cuba.gui.components.data.meta.ContainerDataUnit) MetaProperty(com.haulmont.chile.core.model.MetaProperty)

Example 2 with Nested

use of com.haulmont.cuba.gui.model.Nested in project cuba by cuba-platform.

the class LookupBuilderProcessor method handleSelectionWithContainer.

protected <E extends Entity> void handleSelectionWithContainer(LookupBuilder<E> builder, CollectionContainer<E> collectionDc, Collection<E> itemsFromLookup) {
    if (itemsFromLookup.isEmpty()) {
        return;
    }
    Collection<E> selectedItems = transform(itemsFromLookup, builder);
    boolean initializeMasterReference = false;
    Entity masterItem = null;
    MetaProperty inverseMetaProperty = null;
    // update holder reference if needed
    if (collectionDc instanceof Nested) {
        InstanceContainer masterDc = ((Nested) collectionDc).getMaster();
        String property = ((Nested) collectionDc).getProperty();
        masterItem = masterDc.getItem();
        MetaProperty metaProperty = masterItem.getMetaClass().getPropertyNN(property);
        inverseMetaProperty = metaProperty.getInverse();
        if (inverseMetaProperty != null && !inverseMetaProperty.getRange().getCardinality().isMany()) {
            Class<?> inversePropClass = extendedEntities.getEffectiveClass(inverseMetaProperty.getDomain());
            Class<?> dcClass = extendedEntities.getEffectiveClass(collectionDc.getEntityMetaClass());
            initializeMasterReference = inversePropClass.isAssignableFrom(dcClass);
        }
    }
    DataContext dataContext = UiControllerUtils.getScreenData(builder.getOrigin()).getDataContext();
    List<E> mergedItems = new ArrayList<>(selectedItems.size());
    View viewForCollectionContainer = clientConfig.getReloadUnfetchedAttributesFromLookupScreens() && collectionDc.getEntityMetaClass() != null && metadataTools.isPersistent(collectionDc.getEntityMetaClass()) ? getViewForCollectionContainer(collectionDc, initializeMasterReference, inverseMetaProperty) : null;
    for (E item : selectedItems) {
        if (!collectionDc.containsItem(item.getId())) {
            if (viewForCollectionContainer != null && !entityStates.isLoadedWithView(item, viewForCollectionContainer)) {
                item = dataManager.reload(item, viewForCollectionContainer);
            }
            // track changes in the related instance
            E mergedItem = dataContext.merge(item);
            if (initializeMasterReference) {
                // change reference, now it will be marked as modified
                mergedItem.setValue(inverseMetaProperty.getName(), masterItem);
            }
            mergedItems.add(mergedItem);
        }
    }
    collectionDc.getMutableItems().addAll(mergedItems);
}
Also used : Entity(com.haulmont.cuba.core.entity.Entity) Nested(com.haulmont.cuba.gui.model.Nested) ArrayList(java.util.ArrayList) InstanceContainer(com.haulmont.cuba.gui.model.InstanceContainer) DataContext(com.haulmont.cuba.gui.model.DataContext) MetaProperty(com.haulmont.chile.core.model.MetaProperty)

Example 3 with Nested

use of com.haulmont.cuba.gui.model.Nested in project cuba by cuba-platform.

the class LookupBuilderProcessor method getViewForCollectionContainer.

/**
 * See {@link #getViewForField(HasValue)} javadoc.
 *
 * @return a view or null if the view cannot be evaluated
 */
@Nullable
protected <E extends Entity> View getViewForCollectionContainer(CollectionContainer<E> collectionDc, boolean initializeMasterReference, MetaProperty inverseMetaProperty) {
    View view = null;
    if (collectionDc instanceof Nested) {
        InstanceContainer masterDc = ((Nested) collectionDc).getMaster();
        View masterView = masterDc.getView();
        if (masterView != null) {
            String property = ((Nested) collectionDc).getProperty();
            ViewProperty viewProperty = masterView.getProperty(property);
            if (viewProperty != null) {
                view = viewProperty.getView();
                if (view != null && initializeMasterReference && inverseMetaProperty != null) {
                    view.addProperty(inverseMetaProperty.getName());
                }
            }
        }
    } else {
        view = collectionDc.getView();
    }
    return view;
}
Also used : Nested(com.haulmont.cuba.gui.model.Nested) InstanceContainer(com.haulmont.cuba.gui.model.InstanceContainer) Nullable(javax.annotation.Nullable)

Example 4 with Nested

use of com.haulmont.cuba.gui.model.Nested in project cuba by cuba-platform.

the class AddAction method isPermitted.

@Override
protected boolean isPermitted() {
    if (target == null || !(target.getItems() instanceof ContainerDataUnit)) {
        return false;
    }
    ContainerDataUnit containerDataUnit = (ContainerDataUnit) target.getItems();
    MetaClass metaClass = containerDataUnit.getEntityMetaClass();
    if (metaClass == null) {
        return false;
    }
    if (containerDataUnit.getContainer() instanceof Nested) {
        Nested nestedContainer = (Nested) containerDataUnit.getContainer();
        MetaClass masterMetaClass = nestedContainer.getMaster().getEntityMetaClass();
        MetaProperty metaProperty = masterMetaClass.getPropertyNN(nestedContainer.getProperty());
        boolean attrPermitted = security.isEntityAttrUpdatePermitted(masterMetaClass, metaProperty.getName());
        if (!attrPermitted) {
            return false;
        }
    }
    return super.isPermitted();
}
Also used : MetaClass(com.haulmont.chile.core.model.MetaClass) Nested(com.haulmont.cuba.gui.model.Nested) ContainerDataUnit(com.haulmont.cuba.gui.components.data.meta.ContainerDataUnit) MetaProperty(com.haulmont.chile.core.model.MetaProperty)

Example 5 with Nested

use of com.haulmont.cuba.gui.model.Nested in project cuba by cuba-platform.

the class ExcludeAction method isPermitted.

@Override
protected boolean isPermitted() {
    if (target == null || !(target.getItems() instanceof ContainerDataUnit)) {
        return false;
    }
    ContainerDataUnit<E> containerDataUnit = (ContainerDataUnit) target.getItems();
    MetaClass metaClass = containerDataUnit.getEntityMetaClass();
    if (metaClass == null) {
        return false;
    }
    if (containerDataUnit.getContainer() instanceof Nested) {
        Nested nestedContainer = (Nested) containerDataUnit.getContainer();
        MetaClass masterMetaClass = nestedContainer.getMaster().getEntityMetaClass();
        MetaProperty metaProperty = masterMetaClass.getPropertyNN(nestedContainer.getProperty());
        boolean attrPermitted = security.isEntityAttrUpdatePermitted(masterMetaClass, metaProperty.getName());
        if (!attrPermitted) {
            return false;
        }
    }
    return super.isPermitted();
}
Also used : MetaClass(com.haulmont.chile.core.model.MetaClass) Nested(com.haulmont.cuba.gui.model.Nested) ContainerDataUnit(com.haulmont.cuba.gui.components.data.meta.ContainerDataUnit) MetaProperty(com.haulmont.chile.core.model.MetaProperty)

Aggregations

Nested (com.haulmont.cuba.gui.model.Nested)8 MetaProperty (com.haulmont.chile.core.model.MetaProperty)7 MetaClass (com.haulmont.chile.core.model.MetaClass)6 InstanceContainer (com.haulmont.cuba.gui.model.InstanceContainer)5 ContainerDataUnit (com.haulmont.cuba.gui.components.data.meta.ContainerDataUnit)4 Entity (com.haulmont.cuba.core.entity.Entity)3 Preconditions.checkNotNullArgument (com.haulmont.bali.util.Preconditions.checkNotNullArgument)1 MetaPropertyPath (com.haulmont.chile.core.model.MetaPropertyPath)1 com.haulmont.cuba.core.global (com.haulmont.cuba.core.global)1 BeanLocatorAware (com.haulmont.cuba.core.sys.BeanLocatorAware)1 Focusable (com.haulmont.cuba.gui.components.Component.Focusable)1 DataGrid (com.haulmont.cuba.gui.components.DataGrid)1 DialogAction (com.haulmont.cuba.gui.components.DialogAction)1 Field (com.haulmont.cuba.gui.components.Field)1 ListComponent (com.haulmont.cuba.gui.components.ListComponent)1 Table (com.haulmont.cuba.gui.components.Table)1 DataUnit (com.haulmont.cuba.gui.components.data.DataUnit)1 EntityValueSource (com.haulmont.cuba.gui.components.data.meta.EntityValueSource)1 WindowConfig (com.haulmont.cuba.gui.config.WindowConfig)1 CollectionContainer (com.haulmont.cuba.gui.model.CollectionContainer)1