use of com.haulmont.cuba.gui.screen.UiControllerUtils.getScreenContext in project cuba by cuba-platform.
the class RelatedEntitiesBean method buildScreen.
protected Screen buildScreen(RelatedEntitiesBuilder builder) {
MetaClass metaClass = getMetaClassNN(builder);
MetaProperty metaProperty = getMetaPropertyNN(builder, metaClass);
Screen screen = createScreen(builder, metaClass, metaProperty);
Collection<? extends Entity> selectedEntities = builder.getSelectedEntities() == null ? Collections.emptyList() : builder.getSelectedEntities();
boolean found = ComponentsHelper.walkComponents(screen.getWindow(), screenComponent -> {
if (!(screenComponent instanceof Filter)) {
return false;
} else {
MetaClass actualMetaClass = ((FilterImplementation) screenComponent).getEntityMetaClass();
MetaClass relatedMetaClass = metaProperty.getRange().asClass();
MetaClass effectiveMetaClass = extendedEntities.getEffectiveMetaClass(relatedMetaClass);
if (Objects.equals(actualMetaClass, effectiveMetaClass)) {
MetaDataDescriptor metaDataDescriptor = new MetaDataDescriptor(metaClass, metaProperty);
RelatedScreenDescriptor descriptor = new RelatedScreenDescriptor();
descriptor.setFilterCaption(builder.getFilterCaption());
applyFilter(((Filter) screenComponent), selectedEntities, descriptor, metaDataDescriptor);
return true;
}
return false;
}
});
if (!found) {
screen.addAfterShowListener(event -> {
ScreenContext screenContext = UiControllerUtils.getScreenContext(event.getSource());
screenContext.getNotifications().create(Notifications.NotificationType.WARNING).withCaption(messages.getMainMessage("actions.Related.FilterNotFound")).show();
});
}
return screen;
}
Aggregations