Search in sources :

Example 16 with EntityDataUnit

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

the class ScreenBuilders method editor.

/**
 * Creates a screen builder using list component.
 * <p>
 * Example of building a screen for editing a currently selected entity:
 * <pre>{@code
 * SomeCustomerEditor screen = screenBuilders.editor(customersTable)
 *          .withScreen(SomeCustomerEditor.class)
 *          .build();
 * }</pre>
 * <p>
 * Example of building a screen for creating a new entity instance:
 * <pre>{@code
 * SomeCustomerEditor screen = screenBuilders.editor(customersTable)
 *          .withScreen(SomeCustomerEditor.class)
 *          .newEntity()
 *          .build();
 * }</pre>
 *
 * @param listComponent {@link Table}, {@link DataGrid} or another component containing the list of entities
 * @see #editor(Class, FrameOwner)
 */
public <E> EditorBuilder<E> editor(ListComponent<E> listComponent) {
    checkNotNullArgument(listComponent);
    checkNotNullArgument(listComponent.getFrame());
    FrameOwner frameOwner = listComponent.getFrame().getFrameOwner();
    Class<E> entityClass;
    DataUnit items = listComponent.getItems();
    if (items instanceof EntityDataUnit) {
        entityClass = ((EntityDataUnit) items).getEntityMetaClass().getJavaClass();
    } else {
        throw new IllegalStateException(String.format("Component %s is not bound to data", listComponent));
    }
    EditorBuilder<E> builder = new EditorBuilder<>(frameOwner, entityClass, editorBuilderProcessor::buildEditor);
    builder.withListComponent(listComponent);
    builder.editEntity(listComponent.getSingleSelected());
    return builder;
}
Also used : EntityDataUnit(io.jmix.ui.component.data.meta.EntityDataUnit) DataUnit(io.jmix.ui.component.data.DataUnit) FrameOwner(io.jmix.ui.screen.FrameOwner) EntityDataUnit(io.jmix.ui.component.data.meta.EntityDataUnit)

Example 17 with EntityDataUnit

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

the class ExecutionHistoryAction method actionPerform.

@Override
public void actionPerform(Component component) {
    if (target != null && target.getFrame() != null) {
        MetaClass metaClass = null;
        DataUnit items = target.getItems();
        if (items instanceof EntityDataUnit) {
            metaClass = ((EntityDataUnit) items).getEntityMetaClass();
        }
        openLookup(target.getFrame().getFrameOwner(), metaClass);
    } else if (component instanceof Component.BelongToFrame) {
        FrameOwner screen = ComponentsHelper.getWindowNN((Component.BelongToFrame) component).getFrameOwner();
        openLookup(screen, null);
    } else {
        throw new IllegalStateException("No target screen or component found for 'ExecutionHistoryAction'");
    }
}
Also used : DataUnit(io.jmix.ui.component.data.DataUnit) EntityDataUnit(io.jmix.ui.component.data.meta.EntityDataUnit) MetaClass(io.jmix.core.metamodel.model.MetaClass) EntityDataUnit(io.jmix.ui.component.data.meta.EntityDataUnit) Component(io.jmix.ui.component.Component)

Example 18 with EntityDataUnit

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

the class ResetPasswordAction 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.isEditPermitted()) {
        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 19 with EntityDataUnit

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

the class EditAction method execute.

/**
 * Executes the action.
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public void execute() {
    if (target == null) {
        throw new IllegalStateException("EditAction target is not set");
    }
    if (!(target.getItems() instanceof EntityDataUnit)) {
        throw new IllegalStateException("EditAction 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 EditAction 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);
    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 20 with EntityDataUnit

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

the class EditAction method isPermitted.

@Override
protected boolean isPermitted() {
    if (target == null || target.getSingleSelected() == 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);
    InMemoryCrudEntityContext inMemoryCrudEntityContext = new InMemoryCrudEntityContext(metaClass, applicationContext);
    accessManager.applyRegisteredConstraints(inMemoryCrudEntityContext);
    if (!entityContext.isViewPermitted() && !entityContext.isEditPermitted()) {
        return false;
    }
    if (inMemoryCrudEntityContext.updatePredicate() != null) {
        return true;
    }
    return super.isPermitted();
}
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

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