Search in sources :

Example 11 with DsContext

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

the class FoldersBean method openFolder.

@Override
public void openFolder(AbstractSearchFolder folder) {
    if (StringUtils.isBlank(folder.getFilterComponentId())) {
        log.warn("Unable to open folder: componentId is blank");
        return;
    }
    String[] strings = ValuePathHelper.parse(folder.getFilterComponentId());
    String screenId = strings[0];
    WindowInfo windowInfo = windowConfig.getWindowInfo(screenId);
    Map<String, Object> params = new HashMap<>();
    WindowParams.DISABLE_AUTO_REFRESH.set(params, true);
    WindowParams.DISABLE_RESUME_SUSPENDED.set(params, true);
    if (!StringUtils.isBlank(folder.getTabName())) {
        WindowParams.DESCRIPTION.set(params, messages.getMainMessage(folder.getTabName()));
    } else {
        WindowParams.DESCRIPTION.set(params, messages.getMainMessage(folder.getName()));
    }
    WindowParams.FOLDER_ID.set(params, folder.getId());
    WindowManager wm = App.getInstance().getWindowManager();
    Window window = wm.openWindow(windowInfo, OpenType.NEW_TAB, params);
    Filter filterComponent = null;
    if (strings.length > 1) {
        String filterComponentId = StringUtils.join(Arrays.copyOfRange(strings, 1, strings.length), '.');
        filterComponent = (Filter) window.getComponentNN(filterComponentId);
        FilterEntity filterEntity = metadata.create(FilterEntity.class);
        filterEntity.setFolder(folder);
        filterEntity.setComponentId(folder.getFilterComponentId());
        filterEntity.setName(folder.getLocName());
        filterEntity.setXml(folder.getFilterXml());
        filterEntity.setApplyDefault(BooleanUtils.isNotFalse(folder.getApplyDefault()));
        if (folder instanceof SearchFolder) {
            filterEntity.setIsSet(((SearchFolder) folder).getIsSet());
        }
        filterComponent.setFilterEntity(filterEntity);
        filterComponent.switchFilterMode(FilterDelegate.FilterMode.GENERIC_MODE);
    }
    if (filterComponent != null && folder instanceof SearchFolder) {
        SearchFolder searchFolder = (SearchFolder) folder;
        if (searchFolder.getPresentation() != null) {
            ((HasPresentations) filterComponent.getApplyTo()).applyPresentation(searchFolder.getPresentation().getId());
        }
    }
    if (window.getFrameOwner() instanceof LegacyFrame) {
        DsContext dsContext = ((LegacyFrame) window.getFrameOwner()).getDsContext();
        if (dsContext != null) {
            ((DsContextImplementation) dsContext).resumeSuspended();
        }
    }
}
Also used : Window(com.haulmont.cuba.gui.components.Window) HasPresentations(com.haulmont.cuba.gui.components.HasPresentations) DsContextImplementation(com.haulmont.cuba.gui.data.impl.DsContextImplementation) DsContext(com.haulmont.cuba.gui.data.DsContext) HashMap(java.util.HashMap) FilterEntity(com.haulmont.cuba.security.entity.FilterEntity) AbstractSearchFolder(com.haulmont.cuba.core.entity.AbstractSearchFolder) SearchFolder(com.haulmont.cuba.security.entity.SearchFolder) LegacyFrame(com.haulmont.cuba.gui.screen.compatibility.LegacyFrame) WindowInfo(com.haulmont.cuba.gui.config.WindowInfo) WindowManager(com.haulmont.cuba.gui.WindowManager) Filter(com.haulmont.cuba.gui.components.Filter)

Example 12 with DsContext

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

the class WebTableFieldFactory method findOptionsDatasource.

@Nullable
protected CollectionDatasource findOptionsDatasource(Table.Column columnConf, String propertyId) {
    String optDsName = columnConf.getXmlDescriptor() != null ? columnConf.getXmlDescriptor().attributeValue("optionsDatasource") : "";
    if (Strings.isNullOrEmpty(optDsName)) {
        return null;
    } else {
        if (webTable.getDatasource() == null) {
            throw new IllegalStateException("Table datasource is null");
        }
        DsContext dsContext = webTable.getDatasource().getDsContext();
        CollectionDatasource ds = (CollectionDatasource) dsContext.get(optDsName);
        if (ds == null) {
            throw new IllegalStateException(String.format("Options datasource for table column '%s' not found: %s", propertyId, optDsName));
        }
        return ds;
    }
}
Also used : DsContext(com.haulmont.cuba.gui.data.DsContext) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) Nullable(javax.annotation.Nullable)

Example 13 with DsContext

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

the class WebScreens method initDsContext.

protected void initDsContext(Window window, Element element, ComponentLoaderContext componentLoaderContext) {
    DsContext dsContext = loadDsContext(element);
    initDatasources(window, dsContext, componentLoaderContext.getParams());
    componentLoaderContext.setDsContext(dsContext);
}
Also used : DsContext(com.haulmont.cuba.gui.data.DsContext)

Example 14 with DsContext

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

the class WebScreens method loadWindowFromXml.

protected <T extends Screen> void loadWindowFromXml(Element element, WindowInfo windowInfo, Window window, T controller, ComponentLoaderContext componentLoaderContext) {
    if (windowInfo.getTemplate() != null) {
        String messagesPack = element.attributeValue("messagesPack");
        if (messagesPack != null) {
            componentLoaderContext.setMessagesPack(messagesPack);
        } else {
            componentLoaderContext.setMessagesPack(getMessagePack(windowInfo.getTemplate()));
        }
    }
    LayoutLoader layoutLoader = beanLocator.getPrototype(LayoutLoader.NAME, componentLoaderContext);
    ComponentLoader<Window> windowLoader = layoutLoader.createWindowContent(window, element);
    if (controller instanceof LegacyFrame) {
        screenViewsLoader.deployViews(element);
        initDsContext(window, element, componentLoaderContext);
        DsContext dsContext = ((LegacyFrame) controller).getDsContext();
        if (dsContext != null) {
            dsContext.setFrameContext(window.getContext());
        }
    }
    windowLoader.loadComponent();
}
Also used : LayoutLoader(com.haulmont.cuba.gui.xml.layout.LayoutLoader) GuiDialogWindow(com.haulmont.cuba.web.gui.components.WebDialogWindow.GuiDialogWindow) WebWindow(com.haulmont.cuba.web.gui.WebWindow) WebTabWindow(com.haulmont.cuba.web.gui.components.WebTabWindow) DsContext(com.haulmont.cuba.gui.data.DsContext)

Example 15 with DsContext

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

the class WebScreens method loadDsContext.

protected DsContext loadDsContext(Element element) {
    DataSupplier dataSupplier;
    String dataSupplierClass = element.attributeValue("dataSupplier");
    if (StringUtils.isEmpty(dataSupplierClass)) {
        dataSupplier = defaultDataSupplier;
    } else {
        Class<Object> aClass = ReflectionHelper.getClass(dataSupplierClass);
        try {
            dataSupplier = (DataSupplier) aClass.newInstance();
        } catch (InstantiationException | IllegalAccessException e) {
            throw new RuntimeException("Unable to create data supplier for screen", e);
        }
    }
    // noinspection UnnecessaryLocalVariable
    DsContext dsContext = new DsContextLoader(dataSupplier).loadDatasources(element.element("dsContext"), null, null);
    return dsContext;
}
Also used : DsContextLoader(com.haulmont.cuba.gui.xml.data.DsContextLoader) DsContext(com.haulmont.cuba.gui.data.DsContext) GenericDataSupplier(com.haulmont.cuba.gui.data.impl.GenericDataSupplier) DataSupplier(com.haulmont.cuba.gui.data.DataSupplier)

Aggregations

DsContext (com.haulmont.cuba.gui.data.DsContext)15 LegacyFrame (com.haulmont.cuba.gui.screen.compatibility.LegacyFrame)5 Element (org.dom4j.Element)5 Datasource (com.haulmont.cuba.gui.data.Datasource)4 DsContextImplementation (com.haulmont.cuba.gui.data.impl.DsContextImplementation)4 DsContextLoader (com.haulmont.cuba.gui.xml.data.DsContextLoader)3 MetaClass (com.haulmont.chile.core.model.MetaClass)2 MetaProperty (com.haulmont.chile.core.model.MetaProperty)2 GuiDevelopmentException (com.haulmont.cuba.gui.GuiDevelopmentException)2 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)2 DataSupplier (com.haulmont.cuba.gui.data.DataSupplier)2 DatasourceImplementation (com.haulmont.cuba.gui.data.impl.DatasourceImplementation)2 GenericDataSupplier (com.haulmont.cuba.gui.data.impl.GenericDataSupplier)2 java.util (java.util)2 Function (java.util.function.Function)2 StringUtils (org.apache.commons.lang3.StringUtils)2 Strings (com.google.common.base.Strings)1 Iterables (com.google.common.collect.Iterables)1 Preconditions.checkNotNullArgument (com.haulmont.bali.util.Preconditions.checkNotNullArgument)1 MetaPropertyPath (com.haulmont.chile.core.model.MetaPropertyPath)1