Search in sources :

Example 1 with EntityDataUnit

use of io.jmix.ui.component.data.meta.EntityDataUnit 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 EntityDataUnit

use of io.jmix.ui.component.data.meta.EntityDataUnit in project jmix by jmix-framework.

the class CreateAction method execute.

/**
 * Executes the action.
 */
@SuppressWarnings("unchecked")
@Override
public void execute() {
    if (target == null) {
        throw new IllegalStateException("CreateAction target is not set");
    }
    if (!(target.getItems() instanceof EntityDataUnit)) {
        throw new IllegalStateException("CreateAction 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");
    }
    EditorBuilder builder = screenBuilders.editor(target);
    if (newEntitySupplier != null) {
        E entity = newEntitySupplier.get();
        builder = builder.newEntity(entity);
    } else {
        builder = builder.newEntity();
    }
    if (initializer != null) {
        builder = builder.withInitializer(initializer);
    }
    builder = screenInitializer.initBuilder(builder);
    if (transformation != null) {
        builder.withTransformation(transformation);
    }
    Screen editor = builder.build();
    if (afterCommitHandler != null) {
        editor.addAfterCloseListener(afterCloseEvent -> {
            CloseAction closeAction = afterCloseEvent.getCloseAction();
            if (closeAction.equals(WINDOW_COMMIT_AND_CLOSE_ACTION)) {
                Object committedEntity = ((EditorScreen) editor).getEditedEntity();
                afterCommitHandler.accept((E) committedEntity);
            }
        });
    }
    screenInitializer.initScreen(editor);
    editor.show();
}
Also used : MetaClass(io.jmix.core.metamodel.model.MetaClass) EditorBuilder(io.jmix.ui.builder.EditorBuilder) EntityDataUnit(io.jmix.ui.component.data.meta.EntityDataUnit)

Example 3 with EntityDataUnit

use of io.jmix.ui.component.data.meta.EntityDataUnit in project jmix by jmix-framework.

the class CreateAction 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.isCreatePermitted()) {
        return false;
    }
    return super.isPermitted();
}
Also used : UiEntityContext(io.jmix.ui.accesscontext.UiEntityContext) MetaClass(io.jmix.core.metamodel.model.MetaClass) EntityDataUnit(io.jmix.ui.component.data.meta.EntityDataUnit)

Example 4 with EntityDataUnit

use of io.jmix.ui.component.data.meta.EntityDataUnit 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;
}
Also used : UiEntityContext(io.jmix.ui.accesscontext.UiEntityContext) MetaClass(io.jmix.core.metamodel.model.MetaClass) EntityDataUnit(io.jmix.ui.component.data.meta.EntityDataUnit)

Example 5 with EntityDataUnit

use of io.jmix.ui.component.data.meta.EntityDataUnit in project jmix by jmix-framework.

the class ViewAction method execute.

/**
 * Executes the action.
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public void execute() {
    if (target == null) {
        throw new IllegalStateException("ViewAction target is not set");
    }
    if (!(target.getItems() instanceof EntityDataUnit)) {
        throw new IllegalStateException("ViewAction target dataSource 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");
    }
    Object editedEntity = target.getSingleSelected();
    if (editedEntity == null) {
        throw new IllegalStateException("There is not selected item in ViewAction target");
    }
    EditorBuilder builder = screenBuilders.editor(target).editEntity(editedEntity);
    builder = screenInitializer.initBuilder(builder);
    if (transformation != null) {
        builder.withTransformation(transformation);
    }
    Screen editor = builder.build();
    if (afterCommitHandler != null) {
        editor.addAfterCloseListener(afterCloseEvent -> {
            CloseAction closeAction = afterCloseEvent.getCloseAction();
            if (closeAction.equals(WINDOW_COMMIT_AND_CLOSE_ACTION)) {
                Object committedEntity = ((EditorScreen) editor).getEditedEntity();
                afterCommitHandler.accept((E) committedEntity);
            }
        });
    }
    screenInitializer.initScreen(editor);
    if (editor instanceof ReadOnlyAwareScreen) {
        ((ReadOnlyAwareScreen) editor).setReadOnly(true);
        if (isReadOnlyCompositionEditor(editor)) {
            readOnlyScreensSupport.setScreenReadOnly(editor, true, false);
        }
    } else {
        throw new IllegalStateException(String.format("Screen '%s' does not implement ReadOnlyAwareScreen: %s", editor.getId(), editor.getClass()));
    }
    editor.show();
}
Also used : MetaClass(io.jmix.core.metamodel.model.MetaClass) EditorBuilder(io.jmix.ui.builder.EditorBuilder) EntityDataUnit(io.jmix.ui.component.data.meta.EntityDataUnit)

Aggregations

EntityDataUnit (io.jmix.ui.component.data.meta.EntityDataUnit)23 MetaClass (io.jmix.core.metamodel.model.MetaClass)19 UiEntityContext (io.jmix.ui.accesscontext.UiEntityContext)9 DataUnit (io.jmix.ui.component.data.DataUnit)5 EditorBuilder (io.jmix.ui.builder.EditorBuilder)3 InMemoryCrudEntityContext (io.jmix.core.accesscontext.InMemoryCrudEntityContext)2 ContainerDataUnit (io.jmix.ui.component.data.meta.ContainerDataUnit)2 EmptyDataUnit (io.jmix.ui.component.data.meta.EmptyDataUnit)2 PaginationDataBinder (io.jmix.ui.component.pagination.data.PaginationDataBinder)2 PaginationDataUnitBinder (io.jmix.ui.component.pagination.data.PaginationDataUnitBinder)2 PaginationEmptyBinder (io.jmix.ui.component.pagination.data.PaginationEmptyBinder)2 FrameOwner (io.jmix.ui.screen.FrameOwner)2 UserDetails (org.springframework.security.core.userdetails.UserDetails)2 UserSubstitutionEntity (io.jmix.securitydata.entity.UserSubstitutionEntity)1 Notifications (io.jmix.ui.Notifications)1 Screens (io.jmix.ui.Screens)1 UiBulkEditContext (io.jmix.ui.accesscontext.UiBulkEditContext)1 Component (io.jmix.ui.component.Component)1 Frame (io.jmix.ui.component.Frame)1 Window (io.jmix.ui.component.Window)1