Search in sources :

Example 1 with CollectionPropertyContainer

use of io.jmix.ui.model.CollectionPropertyContainer 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

MetaClass (io.jmix.core.metamodel.model.MetaClass)1 MetaProperty (io.jmix.core.metamodel.model.MetaProperty)1 Frame (io.jmix.ui.component.Frame)1 DataUnit (io.jmix.ui.component.data.DataUnit)1 ContainerDataUnit (io.jmix.ui.component.data.meta.ContainerDataUnit)1 EntityDataUnit (io.jmix.ui.component.data.meta.EntityDataUnit)1 CollectionContainer (io.jmix.ui.model.CollectionContainer)1 CollectionPropertyContainer (io.jmix.ui.model.CollectionPropertyContainer)1 InstanceContainer (io.jmix.ui.model.InstanceContainer)1