Search in sources :

Example 1 with ContainerDataUnit

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

the class BulkEditors method refreshItems.

protected void refreshItems(@Nullable DataUnit dataSource) {
    if (dataSource instanceof ContainerDataUnit) {
        CollectionContainer<?> container = ((ContainerDataUnit<?>) dataSource).getContainer();
        DataLoader loader = null;
        if (container instanceof HasLoader) {
            loader = ((HasLoader) container).getLoader();
        }
        if (loader != null) {
            loader.load();
        } else {
            log.warn("Target container has no loader, refresh is impossible");
        }
    }
}
Also used : DataLoader(io.jmix.ui.model.DataLoader) HasLoader(io.jmix.ui.model.HasLoader) ContainerDataUnit(io.jmix.ui.component.data.meta.ContainerDataUnit)

Example 2 with ContainerDataUnit

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

the class ExcludeAction method isPermitted.

@Override
protected boolean isPermitted() {
    if (target == null || !(target.getItems() instanceof ContainerDataUnit)) {
        return false;
    }
    ContainerDataUnit<E> containerDataUnit = (ContainerDataUnit) target.getItems();
    MetaClass metaClass = containerDataUnit.getEntityMetaClass();
    if (metaClass == null) {
        return false;
    }
    if (containerDataUnit.getContainer() instanceof Nested) {
        Nested nestedContainer = (Nested) containerDataUnit.getContainer();
        MetaClass masterMetaClass = nestedContainer.getMaster().getEntityMetaClass();
        MetaProperty metaProperty = masterMetaClass.getProperty(nestedContainer.getProperty());
        UiEntityAttributeContext attributeContext = new UiEntityAttributeContext(masterMetaClass, metaProperty.getName());
        accessManager.applyRegisteredConstraints(attributeContext);
        boolean attrPermitted = attributeContext.canModify();
        if (!attrPermitted) {
            return false;
        }
    }
    return super.isPermitted();
}
Also used : MetaClass(io.jmix.core.metamodel.model.MetaClass) UiEntityAttributeContext(io.jmix.ui.accesscontext.UiEntityAttributeContext) Nested(io.jmix.ui.model.Nested) ContainerDataUnit(io.jmix.ui.component.data.meta.ContainerDataUnit) MetaProperty(io.jmix.core.metamodel.model.MetaProperty)

Example 3 with ContainerDataUnit

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

the class RefreshAction method execute.

/**
 * Executes the action.
 */
@Override
public void execute() {
    if (target == null) {
        throw new IllegalStateException("RefreshAction target is not set");
    }
    if (target.getItems() instanceof EmptyDataUnit) {
        return;
    }
    if (!(target.getItems() instanceof ContainerDataUnit)) {
        throw new IllegalStateException("RefreshAction target is null or does not implement SupportsContainerBinding");
    }
    CollectionContainer container = ((ContainerDataUnit) target.getItems()).getContainer();
    if (container == null) {
        throw new IllegalStateException("RefreshAction target is not bound to CollectionContainer");
    }
    DataLoader loader = null;
    if (container instanceof HasLoader) {
        loader = ((HasLoader) container).getLoader();
    }
    if (loader != null) {
        DataContext dataContext = loader.getDataContext();
        if (dataContext != null) {
            for (Object entity : container.getItems()) {
                dataContext.evict(entity);
            }
        }
        loader.load();
    } else {
        log.warn("RefreshAction '{}' target container has no loader, refresh is impossible", getId());
    }
}
Also used : DataLoader(io.jmix.ui.model.DataLoader) DataContext(io.jmix.ui.model.DataContext) EmptyDataUnit(io.jmix.ui.component.data.meta.EmptyDataUnit) CollectionContainer(io.jmix.ui.model.CollectionContainer) HasLoader(io.jmix.ui.model.HasLoader) ContainerDataUnit(io.jmix.ui.component.data.meta.ContainerDataUnit)

Example 4 with ContainerDataUnit

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

the class RemoveAction method checkRemovePermission.

protected boolean checkRemovePermission() {
    if (target == null || !(target.getItems() instanceof ContainerDataUnit)) {
        return false;
    }
    ContainerDataUnit<E> containerDataUnit = (ContainerDataUnit) target.getItems();
    MetaClass metaClass = containerDataUnit.getEntityMetaClass();
    if (metaClass == null) {
        return false;
    }
    UiEntityContext entityContext = new UiEntityContext(metaClass);
    accessManager.applyRegisteredConstraints(entityContext);
    if (!entityContext.isDeletePermitted()) {
        return false;
    }
    if (containerDataUnit.getContainer() instanceof Nested) {
        Nested nestedContainer = (Nested) containerDataUnit.getContainer();
        MetaClass masterMetaClass = nestedContainer.getMaster().getEntityMetaClass();
        MetaProperty metaProperty = masterMetaClass.getProperty(nestedContainer.getProperty());
        UiEntityAttributeContext entityAttributeContext = new UiEntityAttributeContext(masterMetaClass, metaProperty.getName());
        accessManager.applyRegisteredConstraints(entityAttributeContext);
        if (!entityAttributeContext.canModify()) {
            return false;
        }
    }
    return true;
}
Also used : UiEntityContext(io.jmix.ui.accesscontext.UiEntityContext) MetaClass(io.jmix.core.metamodel.model.MetaClass) UiEntityAttributeContext(io.jmix.ui.accesscontext.UiEntityAttributeContext) Nested(io.jmix.ui.model.Nested) ContainerDataUnit(io.jmix.ui.component.data.meta.ContainerDataUnit) MetaProperty(io.jmix.core.metamodel.model.MetaProperty)

Example 5 with ContainerDataUnit

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

the class ViewAction method isReadOnlyCompositionEditor.

/**
 * In case of composition relation, editor for nested entities should be in read-only mode with hidden
 * "enableEditing" action if master editor is in read-only mode too.
 *
 * @param editor editor to check
 * @return {@code true} if the relation between entities is a composition
 */
protected boolean isReadOnlyCompositionEditor(Screen editor) {
    Frame frame = target.getFrame();
    if (frame == null) {
        throw new IllegalStateException("Component is not attached to the Frame");
    }
    FrameOwner origin = target.getFrame().getFrameOwner();
    if (!(origin instanceof ReadOnlyAwareScreen) || !((ReadOnlyAwareScreen) origin).isReadOnly() || !(editor instanceof StandardEditor)) {
        return false;
    }
    DataUnit items = target.getItems();
    if (!(items instanceof ContainerDataUnit)) {
        return false;
    }
    CollectionContainer container = ((ContainerDataUnit) target.getItems()).getContainer();
    if (!(container instanceof CollectionPropertyContainer)) {
        return false;
    }
    InstanceContainer masterContainer = ((CollectionPropertyContainer) container).getMaster();
    String property = ((CollectionPropertyContainer) container).getProperty();
    MetaClass metaClass = masterContainer.getEntityMetaClass();
    MetaProperty metaProperty = metaClass.getProperty(property);
    return metaProperty.getType() == MetaProperty.Type.COMPOSITION;
}
Also used : Frame(io.jmix.ui.component.Frame) CollectionContainer(io.jmix.ui.model.CollectionContainer) InstanceContainer(io.jmix.ui.model.InstanceContainer) ContainerDataUnit(io.jmix.ui.component.data.meta.ContainerDataUnit) DataUnit(io.jmix.ui.component.data.DataUnit) EntityDataUnit(io.jmix.ui.component.data.meta.EntityDataUnit) MetaClass(io.jmix.core.metamodel.model.MetaClass) ContainerDataUnit(io.jmix.ui.component.data.meta.ContainerDataUnit) MetaProperty(io.jmix.core.metamodel.model.MetaProperty) CollectionPropertyContainer(io.jmix.ui.model.CollectionPropertyContainer)

Aggregations

ContainerDataUnit (io.jmix.ui.component.data.meta.ContainerDataUnit)20 MetaClass (io.jmix.core.metamodel.model.MetaClass)8 DataUnit (io.jmix.ui.component.data.DataUnit)6 MetaProperty (io.jmix.core.metamodel.model.MetaProperty)5 Nested (io.jmix.ui.model.Nested)4 UiEntityAttributeContext (io.jmix.ui.accesscontext.UiEntityAttributeContext)3 EmptyDataUnit (io.jmix.ui.component.data.meta.EmptyDataUnit)3 EntityDataUnit (io.jmix.ui.component.data.meta.EntityDataUnit)3 CollectionContainer (io.jmix.ui.model.CollectionContainer)3 Screens (io.jmix.ui.Screens)2 io.jmix.ui.component (io.jmix.ui.component)2 Frame (io.jmix.ui.component.Frame)2 Window (io.jmix.ui.component.Window)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 DataContext (io.jmix.ui.model.DataContext)2 DataLoader (io.jmix.ui.model.DataLoader)2 HasLoader (io.jmix.ui.model.HasLoader)2 FrameOwner (io.jmix.ui.screen.FrameOwner)2