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;
}
Aggregations