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