use of io.jmix.ui.accesscontext.UiEntityContext in project jmix by jmix-framework.
the class EditAction method isDisabledWhenScreenReadOnly.
@Override
public boolean isDisabledWhenScreenReadOnly() {
if (!(target.getItems() instanceof EntityDataUnit)) {
return true;
}
MetaClass metaClass = ((EntityDataUnit) target.getItems()).getEntityMetaClass();
if (metaClass != null) {
// Even though the screen is read-only, this edit action may remain active
// because the related entity cannot be edited and the corresponding edit screen
// will be opened in read-only mode either.
UiEntityContext entityContext = new UiEntityContext(metaClass);
accessManager.applyRegisteredConstraints(entityContext);
return entityContext.isEditPermitted();
}
return true;
}
use of io.jmix.ui.accesscontext.UiEntityContext in project jmix by jmix-framework.
the class RemoveAction method checkRemovePermission.
protected boolean checkRemovePermission() {
if (target == null || !(target.getItems() instanceof ContainerDataUnit)) {
return false;
}
ContainerDataUnit<E> containerDataUnit = (ContainerDataUnit) target.getItems();
MetaClass metaClass = containerDataUnit.getEntityMetaClass();
if (metaClass == null) {
return false;
}
UiEntityContext entityContext = new UiEntityContext(metaClass);
accessManager.applyRegisteredConstraints(entityContext);
if (!entityContext.isDeletePermitted()) {
return false;
}
if (containerDataUnit.getContainer() instanceof Nested) {
Nested nestedContainer = (Nested) containerDataUnit.getContainer();
MetaClass masterMetaClass = nestedContainer.getMaster().getEntityMetaClass();
MetaProperty metaProperty = masterMetaClass.getProperty(nestedContainer.getProperty());
UiEntityAttributeContext entityAttributeContext = new UiEntityAttributeContext(masterMetaClass, metaProperty.getName());
accessManager.applyRegisteredConstraints(entityAttributeContext);
if (!entityAttributeContext.canModify()) {
return false;
}
}
return true;
}
use of io.jmix.ui.accesscontext.UiEntityContext in project jmix by jmix-framework.
the class ViewAction method isPermitted.
@Override
protected boolean isPermitted() {
if (target == null || !(target.getItems() instanceof EntityDataUnit)) {
return false;
}
MetaClass metaClass = ((EntityDataUnit) target.getItems()).getEntityMetaClass();
if (metaClass == null) {
return true;
}
UiEntityContext entityContext = new UiEntityContext(metaClass);
accessManager.applyRegisteredConstraints(entityContext);
if (!entityContext.isViewPermitted()) {
return false;
}
return super.isPermitted();
}
use of io.jmix.ui.accesscontext.UiEntityContext in project jmix by jmix-framework.
the class StandardEditor method setupLock.
protected void setupLock() {
Object entityId = EntityValues.getId(entityToEdit);
if (!getEntityStates().isNew(entityToEdit) && entityId != null) {
AccessManager accessManager = getApplicationContext().getBean(AccessManager.class);
MetaClass metaClass = getEditedEntityContainer().getEntityMetaClass();
UiEntityContext entityContext = new UiEntityContext(metaClass);
accessManager.applyRegisteredConstraints(entityContext);
InMemoryCrudEntityContext inMemoryContext = new InMemoryCrudEntityContext(metaClass, getApplicationContext());
accessManager.applyRegisteredConstraints(inMemoryContext);
if (entityContext.isEditPermitted() && (inMemoryContext.updatePredicate() == null || inMemoryContext.isUpdatePermitted(getEditedEntity()))) {
readOnlyDueToLock = false;
PessimisticLockStatus lockStatus = getLockingSupport().lock(entityId);
if (lockStatus == PessimisticLockStatus.LOCKED) {
justLocked = true;
addAfterDetachListener(afterDetachEvent -> releaseLock());
} else if (lockStatus == PessimisticLockStatus.FAILED) {
readOnlyDueToLock = true;
showEnableEditingBtn = false;
setReadOnly(true);
}
} else {
showEnableEditingBtn = false;
setReadOnly(true);
}
}
}
use of io.jmix.ui.accesscontext.UiEntityContext in project jmix by jmix-framework.
the class MasterDetailScreen method initBrowseEditAction.
/**
* Adds an EditAction that enables controls for editing.
*/
protected void initBrowseEditAction() {
ListComponent<T> table = getTable();
EditAction editAction = (EditAction) table.getActionNN("edit");
editAction.withHandler(actionPerformedEvent -> {
T item = table.getSingleSelected();
if (item != null) {
if (lockIfNeeded(item)) {
refreshOptionsForLookupFields();
enableEditControls(false);
}
}
});
MetaClass entityMetaClass = getApplicationContext().getBean(Metadata.class).getClass(getEntityClass());
UiEntityContext entityContext = new UiEntityContext(entityMetaClass);
getApplicationContext().getBean(AccessManager.class).applyRegisteredConstraints(entityContext);
editAction.addEnabledRule(() -> table.getSelected().size() == 1 && entityContext.isEditPermitted());
}
Aggregations