Search in sources :

Example 11 with InMemoryCrudEntityContext

use of io.jmix.core.accesscontext.InMemoryCrudEntityContext in project jmix by jmix-framework.

the class EditAction method refreshState.

@Override
public void refreshState() {
    super.refreshState();
    if (target == null || !(target.getItems() instanceof EntityDataUnit)) {
        return;
    }
    if (!captionInitialized) {
        MetaClass metaClass = ((EntityDataUnit) target.getItems()).getEntityMetaClass();
        UiEntityContext entityContext = new UiEntityContext(metaClass);
        accessManager.applyRegisteredConstraints(entityContext);
        InMemoryCrudEntityContext inMemoryContext = new InMemoryCrudEntityContext(metaClass, applicationContext);
        accessManager.applyRegisteredConstraints(inMemoryContext);
        if (metaClass != null) {
            Object entity = target.getSingleSelected();
            if (entityContext.isEditPermitted() && (inMemoryContext.updatePredicate() == null || entity != null && inMemoryContext.isUpdatePermitted(entity))) {
                super.setCaption(messages.getMessage("actions.Edit"));
            } else {
                super.setCaption(messages.getMessage("actions.View"));
            }
        }
    }
}
Also used : UiEntityContext(io.jmix.ui.accesscontext.UiEntityContext) InMemoryCrudEntityContext(io.jmix.core.accesscontext.InMemoryCrudEntityContext) MetaClass(io.jmix.core.metamodel.model.MetaClass) EntityDataUnit(io.jmix.ui.component.data.meta.EntityDataUnit)

Aggregations

InMemoryCrudEntityContext (io.jmix.core.accesscontext.InMemoryCrudEntityContext)11 MetaClass (io.jmix.core.metamodel.model.MetaClass)10 UiEntityContext (io.jmix.ui.accesscontext.UiEntityContext)3 AccessDeniedException (io.jmix.core.security.AccessDeniedException)2 EntityDataUnit (io.jmix.ui.component.data.meta.EntityDataUnit)2 EntitySystemAccess.getSecurityState (io.jmix.core.entity.EntitySystemAccess.getSecurityState)1 SecurityState (io.jmix.core.entity.SecurityState)1 EntityTokenException (io.jmix.core.impl.serialization.EntityTokenException)1 MetaProperty (io.jmix.core.metamodel.model.MetaProperty)1