Search in sources :

Example 1 with UiControllerUtils.getScreenContext

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;
}
Also used : UiControllerUtils.getScreenContext(com.haulmont.cuba.gui.screen.UiControllerUtils.getScreenContext) MetaClass(com.haulmont.chile.core.model.MetaClass) Filter(com.haulmont.cuba.gui.components.Filter) MetaProperty(com.haulmont.chile.core.model.MetaProperty) FilterImplementation(com.haulmont.cuba.gui.components.FilterImplementation)

Aggregations

MetaClass (com.haulmont.chile.core.model.MetaClass)1 MetaProperty (com.haulmont.chile.core.model.MetaProperty)1 Filter (com.haulmont.cuba.gui.components.Filter)1 FilterImplementation (com.haulmont.cuba.gui.components.FilterImplementation)1 UiControllerUtils.getScreenContext (com.haulmont.cuba.gui.screen.UiControllerUtils.getScreenContext)1