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");
}
}
}
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();
}
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());
}
}
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;
}
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;
}
Aggregations