Search in sources :

Example 21 with EntityDataUnit

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

the class EditAction method refreshState.

@Override
public void refreshState() {
    super.refreshState();
    if (target == null || !(target.getItems() instanceof EntityDataUnit)) {
        return;
    }
    if (!captionInitialized) {
        MetaClass metaClass = ((EntityDataUnit) target.getItems()).getEntityMetaClass();
        UiEntityContext entityContext = new UiEntityContext(metaClass);
        accessManager.applyRegisteredConstraints(entityContext);
        InMemoryCrudEntityContext inMemoryContext = new InMemoryCrudEntityContext(metaClass, applicationContext);
        accessManager.applyRegisteredConstraints(inMemoryContext);
        if (metaClass != null) {
            Object entity = target.getSingleSelected();
            if (entityContext.isEditPermitted() && (inMemoryContext.updatePredicate() == null || entity != null && inMemoryContext.isUpdatePermitted(entity))) {
                super.setCaption(messages.getMessage("actions.Edit"));
            } else {
                super.setCaption(messages.getMessage("actions.View"));
            }
        }
    }
}
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)

Example 22 with EntityDataUnit

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

the class RelatedAction method execute.

@Override
public void execute() {
    if (target == null) {
        throw new IllegalStateException("RelatedAction target is not set");
    }
    if (!(target.getItems() instanceof EntityDataUnit)) {
        throw new IllegalStateException("RelatedAction 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");
    }
    if (metaProperty == null && property == null) {
        throw new IllegalStateException("Either 'metaProperty' or 'property' must be defined");
    }
    Frame frame = target.getFrame();
    if (frame == null) {
        throw new IllegalStateException("Target is not bound to a frame");
    }
    RelatedEntitiesBuilder builder = relatedEntitiesSupport.builder(frame.getFrameOwner()).withMetaClass(metaClass).withProperty(property).withMetaProperty(metaProperty).withSelectedEntities(target.getSelected()).withConfigurationName(configurationName);
    builder = screenInitializer.initBuilder(builder);
    Screen screen = builder.build();
    screenInitializer.initScreen(screen);
    screen.show();
}
Also used : Frame(io.jmix.ui.component.Frame) RelatedEntitiesBuilder(io.jmix.ui.relatedentities.RelatedEntitiesBuilder) MetaClass(io.jmix.core.metamodel.model.MetaClass) Screen(io.jmix.ui.screen.Screen) EntityDataUnit(io.jmix.ui.component.data.meta.EntityDataUnit)

Example 23 with EntityDataUnit

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

the class AbstractTable method setupPaginationDataSourceProvider.

public void setupPaginationDataSourceProvider() {
    if (pagination == null) {
        return;
    }
    DataUnit items = getItems();
    PaginationDataBinder provider;
    if (items instanceof ContainerDataUnit) {
        provider = applicationContext.getBean(PaginationDataUnitBinder.class, items);
    } else if (items instanceof EmptyDataUnit && items instanceof EntityDataUnit) {
        provider = new PaginationEmptyBinder(((EntityDataUnit) items).getEntityMetaClass());
    } else {
        throw new IllegalStateException("Unsupported data unit type: " + items);
    }
    pagination.setDataBinder(provider);
}
Also used : PaginationDataUnitBinder(io.jmix.ui.component.pagination.data.PaginationDataUnitBinder) PaginationEmptyBinder(io.jmix.ui.component.pagination.data.PaginationEmptyBinder) EmptyDataUnit(io.jmix.ui.component.data.meta.EmptyDataUnit) DataUnit(io.jmix.ui.component.data.DataUnit) EntityDataUnit(io.jmix.ui.component.data.meta.EntityDataUnit) ContainerDataUnit(io.jmix.ui.component.data.meta.ContainerDataUnit) EmptyDataUnit(io.jmix.ui.component.data.meta.EmptyDataUnit) PaginationDataBinder(io.jmix.ui.component.pagination.data.PaginationDataBinder) ContainerDataUnit(io.jmix.ui.component.data.meta.ContainerDataUnit) 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