Search in sources :

Example 11 with EntityDataUnit

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

the class ResetPasswordAction method execute.

/**
 * Executes the action.
 */
@Override
public void execute() {
    if (target == null) {
        throw new IllegalStateException("Target is not set");
    }
    if (target.getFrame() == null) {
        throw new IllegalStateException("Target frame is not set");
    }
    if (!(target.getItems() instanceof EntityDataUnit)) {
        throw new IllegalStateException("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 ResetPassword target");
    }
    if (!(editedEntity instanceof UserDetails)) {
        throw new IllegalStateException("Target does not implement a UserDetails");
    }
    buildAndShowResetPasswordDialog();
}
Also used : UserDetails(org.springframework.security.core.userdetails.UserDetails) MetaClass(io.jmix.core.metamodel.model.MetaClass) EntityDataUnit(io.jmix.ui.component.data.meta.EntityDataUnit)

Example 12 with EntityDataUnit

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

the class ResetRememberMeTokenAction 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 13 with EntityDataUnit

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

the class ResetRememberMeTokenAction method execute.

@Override
public void execute() {
    if (target == null) {
        throw new IllegalStateException("Target is not set");
    }
    if (!(target.getItems() instanceof EntityDataUnit)) {
        throw new IllegalStateException("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");
    }
    if (!(UserDetails.class.isAssignableFrom(metaClass.getJavaClass()))) {
        throw new IllegalStateException("Target does not implement a UserDetails");
    }
    buildAndShowChangePasswordDialog();
}
Also used : MetaClass(io.jmix.core.metamodel.model.MetaClass) EntityDataUnit(io.jmix.ui.component.data.meta.EntityDataUnit)

Example 14 with EntityDataUnit

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

the class ShowUserSubstitutionsAction 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;
    }
    UiEntityContext userSubstitutionContext = new UiEntityContext(metadata.getClass(UserSubstitutionEntity.class));
    accessManager.applyRegisteredConstraints(userSubstitutionContext);
    if (!userSubstitutionContext.isViewPermitted()) {
        return false;
    }
    return super.isPermitted();
}
Also used : UiEntityContext(io.jmix.ui.accesscontext.UiEntityContext) UserSubstitutionEntity(io.jmix.securitydata.entity.UserSubstitutionEntity) MetaClass(io.jmix.core.metamodel.model.MetaClass) EntityDataUnit(io.jmix.ui.component.data.meta.EntityDataUnit)

Example 15 with EntityDataUnit

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

the class ScreenBuilders method lookup.

/**
 * Creates a screen builder using list component.
 * <p>
 * Example of building a lookup screen for adding row to table / tree component:
 * <pre>{@code
 * SomeCustomerListScreen screen = screenBuilders.lookup(customersTable)
 *         .withScreen(SomeCustomerListScreen.class)
 *         .build();
 * }</pre>
 *
 * @param listComponent {@link Table}, {@link DataGrid} or another component containing the list of entities
 * @param <E>           type of entity
 * @see #lookup(Class, FrameOwner)
 */
public <E> LookupBuilder<E> lookup(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));
    }
    LookupBuilder<E> builder = new LookupBuilder<>(frameOwner, entityClass, lookupBuilderProcessor::buildLookup);
    builder.withListComponent(listComponent);
    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)

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