use of com.haulmont.cuba.gui.xml.layout.ScreenXmlLoader 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.xml.layout.ScreenXmlLoader in project cuba by cuba-platform.
the class FragmentComponentLoader method createComponent.
@Override
public void createComponent() {
String src = element.attributeValue("src");
String screenId = element.attributeValue("screen");
if (src == null && screenId == null) {
throw new GuiDevelopmentException("Either 'src' or 'screen' must be specified for 'frame'", context, "fragment", element.attributeValue("id"));
}
String fragmentId;
if (element.attributeValue("id") != null) {
fragmentId = element.attributeValue("id");
} else if (screenId != null) {
fragmentId = screenId;
} else {
fragmentId = src;
}
FragmentHelper fragmentHelper = getFragmentHelper();
WindowInfo windowInfo;
if (src == null) {
// load screen class only once
windowInfo = getWindowConfig().getWindowInfo(screenId).resolve();
} else {
windowInfo = fragmentHelper.createFakeWindowInfo(src, fragmentId);
}
StopWatch createStopWatch = createStopWatch(ScreenLifeCycle.CREATE, windowInfo.getId());
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();
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(getComponentContext().getOptions());
innerContext.setMessagesPack(fragmentHelper.getMessagePack(windowInfo.getTemplate()));
innerContext.setCurrentFrameId(fragmentId);
innerContext.setFullFrameId(frameId);
innerContext.setFrame(fragment);
innerContext.setParent(parentContext);
innerContext.setProperties(loadProperties(element));
LayoutLoader layoutLoader = getLayoutLoader(innerContext);
ScreenXmlLoader screenXmlLoader = beanLocator.get(ScreenXmlLoader.NAME);
Element rootElement = screenXmlLoader.load(windowInfo.getTemplate(), windowInfo.getId(), getComponentContext().getParams());
String messagesPack = rootElement.attributeValue("messagesPack");
if (messagesPack != null) {
innerContext.setMessagesPack(messagesPack);
}
this.fragmentLoader = layoutLoader.createFragmentContent(fragment, rootElement);
}
createStopWatch.stop();
this.resultComponent = fragment;
}
Aggregations