use of com.haulmont.cuba.gui.screen.FrameOwner in project cuba by cuba-platform.
the class FormLoader method loadDataContainer.
protected void loadDataContainer(Form resultComponent, Element element) {
String containerId = element.attributeValue("dataContainer");
if (!Strings.isNullOrEmpty(containerId)) {
FrameOwner frameOwner = getComponentContext().getFrame().getFrameOwner();
ScreenData screenData = UiControllerUtils.getScreenData(frameOwner);
InstanceContainer container = screenData.getContainer(containerId);
// noinspection unchecked
resultComponent.setValueSourceProvider(new ContainerValueSourceProvider(container));
}
}
use of com.haulmont.cuba.gui.screen.FrameOwner in project cuba by cuba-platform.
the class FragmentLoader method loadDsContext.
protected void loadDsContext(@Nullable Element dsContextElement) {
DsContext dsContext = null;
if (resultComponent.getFrameOwner() instanceof LegacyFrame) {
DsContextLoader dsContextLoader;
DsContext parentDsContext = getComponentContext().getParent().getDsContext();
if (parentDsContext != null) {
dsContextLoader = new DsContextLoader(parentDsContext.getDataSupplier());
} else {
dsContextLoader = new DsContextLoader(new GenericDataSupplier());
}
dsContext = dsContextLoader.loadDatasources(dsContextElement, parentDsContext, getComponentContext().getAliasesMap());
((ComponentLoaderContext) context).setDsContext(dsContext);
}
if (dsContext != null) {
FrameOwner frameOwner = getComponentContext().getFrame().getFrameOwner();
if (frameOwner instanceof LegacyFrame) {
LegacyFrame frame = (LegacyFrame) frameOwner;
frame.setDsContext(dsContext);
for (Datasource ds : dsContext.getAll()) {
if (ds instanceof DatasourceImplementation) {
((DatasourceImplementation) ds).initialized();
}
}
dsContext.setFrameContext(resultComponent.getContext());
}
}
}
use of com.haulmont.cuba.gui.screen.FrameOwner in project cuba by cuba-platform.
the class RuntimePropertiesFrameLoader method createComponent.
@Override
public void createComponent() {
String src = element.attributeValue("src");
String screenId = element.attributeValue("id");
if (src == null) {
src = DEFAULT_DESCRIPTOR;
}
String fragmentId = screenId != null ? screenId : src;
FragmentHelper fragmentHelper = getFragmentHelper();
WindowInfo windowInfo = fragmentHelper.createFakeWindowInfo(src, fragmentId);
Fragment fragment = factory.create(Fragment.NAME);
ScreenFragment controller = fragmentHelper.createController(windowInfo, fragment);
// setup screen and controller
ComponentLoaderContext parentContext = (ComponentLoaderContext) getContext();
FrameOwner hostController = parentContext.getFrame().getFrameOwner();
// setup screen and controller
setHostController(controller, hostController);
setWindowId(controller, windowInfo.getId());
setFrame(controller, fragment);
setScreenContext(controller, new ScreenContextImpl(windowInfo, parentContext.getOptions(), getScreenContext(hostController)));
setScreenData(controller, new ScreenDataImpl());
FragmentImplementation fragmentImpl = (FragmentImplementation) fragment;
fragmentImpl.setFrameOwner(controller);
fragmentImpl.setId(fragmentId);
FragmentContextImpl frameContext = new FragmentContextImpl(fragment, innerContext);
((FrameImplementation) fragment).setContext(frameContext);
if (windowInfo.getTemplate() != null) {
String frameId = fragmentId;
if (parentContext.getFullFrameId() != null) {
frameId = parentContext.getFullFrameId() + "." + frameId;
}
innerContext = new ComponentLoaderContext(getContext().getOptions());
innerContext.setMessagesPack(fragmentHelper.getMessagePack(windowInfo.getTemplate()));
innerContext.setCurrentFrameId(fragmentId);
innerContext.setFullFrameId(frameId);
innerContext.setFrame(fragment);
innerContext.setParent(parentContext);
LayoutLoader layoutLoader = getLayoutLoader(innerContext);
ScreenXmlLoader screenXmlLoader = beanLocator.get(ScreenXmlLoader.NAME);
Element rootElement = screenXmlLoader.load(windowInfo.getTemplate(), windowInfo.getId(), getContext().getParams());
String messagesPack = rootElement.attributeValue("messagesPack");
if (messagesPack != null) {
innerContext.setMessagesPack(messagesPack);
}
this.fragmentLoader = layoutLoader.createFragmentContent(fragment, rootElement);
}
this.resultComponent = fragment;
}
use of com.haulmont.cuba.gui.screen.FrameOwner in project cuba by cuba-platform.
the class TokenListLoader method loadOptionsContainer.
protected void loadOptionsContainer(TokenList component, Element element) {
String containerId = element.attributeValue("optionsContainer");
if (containerId != null) {
FrameOwner frameOwner = getComponentContext().getFrame().getFrameOwner();
ScreenData screenData = UiControllerUtils.getScreenData(frameOwner);
InstanceContainer container = screenData.getContainer(containerId);
if (!(container instanceof CollectionContainer)) {
throw new GuiDevelopmentException("Not a CollectionContainer: " + containerId, context);
}
// noinspection unchecked
component.setOptions(new ContainerOptions((CollectionContainer) container));
}
}
use of com.haulmont.cuba.gui.screen.FrameOwner in project cuba by cuba-platform.
the class TreeLoader method loadTreeChildren.
@SuppressWarnings("unchecked")
protected void loadTreeChildren() {
Element itemsElem = element.element("treechildren");
String containerId = element.attributeValue("dataContainer");
if (containerId != null) {
FrameOwner frameOwner = getComponentContext().getFrame().getFrameOwner();
ScreenData screenData = UiControllerUtils.getScreenData(frameOwner);
InstanceContainer container = screenData.getContainer(containerId);
CollectionContainer collectionContainer;
if (container instanceof CollectionContainer) {
collectionContainer = (CollectionContainer) container;
} else {
throw new GuiDevelopmentException("Not a CollectionContainer: " + containerId, context);
}
String hierarchyProperty = element.attributeValue("hierarchyProperty");
if (hierarchyProperty == null && itemsElem != null) {
// legacy behaviour
hierarchyProperty = itemsElem.attributeValue("hierarchyProperty");
}
if (Strings.isNullOrEmpty(hierarchyProperty)) {
throw new GuiDevelopmentException("Tree doesn't have 'hierarchyProperty' attribute of the 'treechildren' element", context, "Tree ID", element.attributeValue("id"));
}
String showOrphansAttr = element.attributeValue("showOrphans");
boolean showOrphans = showOrphansAttr == null || Boolean.parseBoolean(showOrphansAttr);
resultComponent.setItems(new ContainerTreeItems(collectionContainer, hierarchyProperty, showOrphans));
} else if (itemsElem != null) {
String datasource = itemsElem.attributeValue("datasource");
if (!StringUtils.isBlank(datasource)) {
HierarchicalDatasource ds = (HierarchicalDatasource) getComponentContext().getDsContext().get(datasource);
resultComponent.setDatasource(ds);
}
}
String captionProperty = element.attributeValue("captionProperty");
if (captionProperty == null && itemsElem != null) {
captionProperty = itemsElem.attributeValue("captionProperty");
}
if (!StringUtils.isEmpty(captionProperty)) {
resultComponent.setCaptionProperty(captionProperty);
resultComponent.setCaptionMode(CaptionMode.PROPERTY);
}
}
Aggregations