Search in sources :

Example 1 with UiBulkEditContext

use of io.jmix.ui.accesscontext.UiBulkEditContext in project jmix by jmix-framework.

the class BulkEditAction method execute.

/**
 * Executes the action.
 */
@SuppressWarnings("unchecked")
@Override
public void execute() {
    if (!(target.getItems() instanceof EntityDataUnit)) {
        throw new IllegalStateException("BulkEditAction target Items is null " + "or does not implement EntityDataUnit");
    }
    MetaClass metaClass = ((EntityDataUnit) target.getItems()).getEntityMetaClass();
    if (metaClass == null) {
        throw new IllegalStateException("Target is not bound to entity");
    }
    UiBulkEditContext context = new UiBulkEditContext();
    accessManager.applyRegisteredConstraints(context);
    if (!context.isPermitted()) {
        if (target.getFrame() != null) {
            Notifications notifications = getScreenContext(target.getFrame()).getNotifications();
            notifications.create(NotificationType.ERROR).withCaption(messages.getMessage("accessDenied.message")).show();
        }
        return;
    }
    if (target.getSelected().isEmpty() && target.getFrame() != null) {
        Notifications notifications = getScreenContext(target.getFrame()).getNotifications();
        notifications.create(NotificationType.ERROR).withCaption(messages.getMessage("actions.BulkEdit.emptySelection")).show();
        return;
    }
    Window window = ComponentsHelper.getWindowNN(target);
    BulkEditorBuilder<?> builder = bulkEditors.builder(metaClass, target.getSelected(), window.getFrameOwner()).withListComponent(target);
    if (columnsMode != null) {
        builder = builder.withColumnsMode(columnsMode);
    }
    if (exclude != null) {
        builder = builder.withExclude(exclude);
    }
    if (fieldSorter != null) {
        builder = builder.withFieldSorter(fieldSorter);
    }
    if (includeProperties != null) {
        builder = builder.withIncludeProperties(includeProperties);
    }
    if (openMode != null) {
        builder = builder.withOpenMode(openMode);
    }
    if (useConfirmDialog != null) {
        builder = builder.withUseConfirmDialog(useConfirmDialog);
    }
    builder.create().show();
}
Also used : Window(io.jmix.ui.component.Window) UiBulkEditContext(io.jmix.ui.accesscontext.UiBulkEditContext) MetaClass(io.jmix.core.metamodel.model.MetaClass) EntityDataUnit(io.jmix.ui.component.data.meta.EntityDataUnit) Notifications(io.jmix.ui.Notifications)

Example 2 with UiBulkEditContext

use of io.jmix.ui.accesscontext.UiBulkEditContext in project jmix by jmix-framework.

the class BulkEditAction method setAccessManager.

@Autowired
@Override
protected void setAccessManager(AccessManager accessManager) {
    super.setAccessManager(accessManager);
    UiBulkEditContext context = new UiBulkEditContext();
    accessManager.applyRegisteredConstraints(context);
    visibleBySpecificUiPermission = context.isPermitted();
}
Also used : UiBulkEditContext(io.jmix.ui.accesscontext.UiBulkEditContext) Autowired(org.springframework.beans.factory.annotation.Autowired)

Aggregations

UiBulkEditContext (io.jmix.ui.accesscontext.UiBulkEditContext)2 MetaClass (io.jmix.core.metamodel.model.MetaClass)1 Notifications (io.jmix.ui.Notifications)1 Window (io.jmix.ui.component.Window)1 EntityDataUnit (io.jmix.ui.component.data.meta.EntityDataUnit)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1