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