Search in sources :

Example 6 with DsContextImplementation

use of com.haulmont.cuba.gui.data.impl.DsContextImplementation in project cuba by cuba-platform.

the class RelatedEntitiesBean method openRelatedScreen.

@Override
public void openRelatedScreen(Collection<? extends Entity> selectedEntities, MetaClass metaClass, MetaProperty metaProperty, RelatedScreenDescriptor descriptor) {
    Preconditions.checkNotNullArgument(metaClass, "MetaClass can't be null");
    Preconditions.checkNotNullArgument(metaProperty, "MetaProperty can't be null");
    WindowManager windowManager = windowManagerProvider.get();
    if (!selectedEntities.isEmpty()) {
        Map<String, Object> params = new HashMap<>();
        WindowParams.DISABLE_AUTO_REFRESH.set(params, true);
        WindowParams.DISABLE_RESUME_SUSPENDED.set(params, true);
        if (descriptor != null && descriptor.getScreenParams() != null) {
            params.putAll(descriptor.getScreenParams());
        }
        String screen;
        if (descriptor != null && StringUtils.isNotEmpty(descriptor.getScreenId())) {
            screen = descriptor.getScreenId();
        } else {
            screen = windowConfig.getBrowseScreenId(metaProperty.getRange().asClass());
        }
        if (StringUtils.isEmpty(screen)) {
            String message = String.format("Can't show related entities: passed screenId is null and " + "there is no default browse screen for %s", metaClass.getName());
            throw new IllegalStateException(message);
        }
        WindowManager.OpenType openType = WindowManager.OpenType.THIS_TAB;
        if (descriptor != null) {
            openType = descriptor.getOpenType();
        }
        Window window = windowManager.openWindow(windowConfig.getWindowInfo(screen), openType, params);
        boolean found = ComponentsHelper.walkComponents(window, screenComponent -> {
            if (!(screenComponent instanceof Filter)) {
                return false;
            } else {
                MetaClass actualMetaClass = ((Filter) screenComponent).getDatasource().getMetaClass();
                MetaClass relatedMetaClass = metaProperty.getRange().asClass();
                MetaClass effectiveMetaClass = extendedEntities.getEffectiveMetaClass(relatedMetaClass);
                if (Objects.equals(actualMetaClass, effectiveMetaClass)) {
                    MetaDataDescriptor metaDataDescriptor = new MetaDataDescriptor(metaClass, metaProperty);
                    applyFilter(((Filter) screenComponent), selectedEntities, descriptor, metaDataDescriptor);
                    return true;
                }
                return false;
            }
        });
        if (!found) {
            windowManager.showNotification(messages.getMainMessage("actions.Related.FilterNotFound"), Frame.NotificationType.WARNING);
        }
        ((DsContextImplementation) window.getDsContext()).resumeSuspended();
    } else {
        windowManager.showNotification(messages.getMainMessage("actions.Related.NotSelected"), Frame.NotificationType.HUMANIZED);
    }
}
Also used : Window(com.haulmont.cuba.gui.components.Window) DsContextImplementation(com.haulmont.cuba.gui.data.impl.DsContextImplementation) MetaClass(com.haulmont.chile.core.model.MetaClass) Filter(com.haulmont.cuba.gui.components.Filter)

Example 7 with DsContextImplementation

use of com.haulmont.cuba.gui.data.impl.DsContextImplementation in project cuba by cuba-platform.

the class WebAccordion method initComponentTabChangeListener.

private void initComponentTabChangeListener() {
    // after all lazy tabs listeners
    if (!componentTabChangeListenerInitialized) {
        component.addSelectedTabChangeListener(event -> {
            if (context != null) {
                context.executeInjectTasks();
                context.executePostWrapTasks();
                context.executeInitTasks();
            }
            // Fire GUI listener
            fireTabChanged();
            // We suppose that context.executePostInitTasks() executes a task once and then remove it from task list.
            if (context != null) {
                context.executePostInitTasks();
            }
            Window window = ComponentsHelper.getWindow(WebAccordion.this);
            if (window != null) {
                ((DsContextImplementation) window.getDsContext()).resumeSuspended();
            } else {
                LoggerFactory.getLogger(WebAccordion.class).warn("Please specify Frame for Accordion");
            }
        });
        componentTabChangeListenerInitialized = true;
    }
}
Also used : Window(com.haulmont.cuba.gui.components.Window) DsContextImplementation(com.haulmont.cuba.gui.data.impl.DsContextImplementation)

Aggregations

DsContextImplementation (com.haulmont.cuba.gui.data.impl.DsContextImplementation)7 MetaClass (com.haulmont.chile.core.model.MetaClass)4 MetaProperty (com.haulmont.chile.core.model.MetaProperty)2 Range (com.haulmont.chile.core.model.Range)2 Entity (com.haulmont.cuba.core.entity.Entity)2 AppConfig (com.haulmont.cuba.gui.AppConfig)2 com.haulmont.cuba.gui.components (com.haulmont.cuba.gui.components)2 Filter (com.haulmont.cuba.gui.components.Filter)2 Formatter (com.haulmont.cuba.gui.components.Formatter)2 Window (com.haulmont.cuba.gui.components.Window)2 DsBuilder (com.haulmont.cuba.gui.data.DsBuilder)2 ComponentsFactory (com.haulmont.cuba.gui.xml.layout.ComponentsFactory)2 SimpleDateFormat (java.text.SimpleDateFormat)2 java.util (java.util)2 Inject (javax.inject.Inject)2 StringUtils (org.apache.commons.lang.StringUtils)2 Files (com.google.common.io.Files)1 Dom4j (com.haulmont.bali.util.Dom4j)1 ParamsMap (com.haulmont.bali.util.ParamsMap)1 Session (com.haulmont.chile.core.model.Session)1