use of io.jmix.ui.xml.layout.loader.ComponentLoaderContext in project jmix by jmix-framework.
the class FragmentsImpl method createFragment.
protected <T extends ScreenFragment> T createFragment(FrameOwner parent, WindowInfo windowInfo, ScreenOptions options) {
if (windowInfo.getType() != WindowInfo.Type.FRAGMENT) {
throw new IllegalArgumentException(String.format("Unable to create fragment %s it is a screen: %s", windowInfo.getId(), windowInfo.getControllerClass()));
}
Timer.Sample createSample = Timer.start(meterRegistry);
Fragment fragment = createFragmentInternal();
ScreenFragment controller = fragmentHelper.createController(windowInfo, fragment);
// setup screen and controller
setHostController(controller, parent);
setWindowId(controller, windowInfo.getId());
setFrame(controller, fragment);
setScreenContext(controller, new ScreenContextImpl(windowInfo, options, getScreenContext(parent)));
setScreenData(controller, applicationContext.getBean(ScreenData.class));
FragmentImplementation fragmentImpl = (FragmentImplementation) fragment;
fragmentImpl.setFrameOwner(controller);
fragmentImpl.setId(controller.getId());
createSample.stop(createScreenTimer(meterRegistry, ScreenLifeCycle.CREATE, windowInfo.getId()));
Timer.Sample loadSample = Timer.start(meterRegistry);
Frame parentFrame = getFrame(parent);
// fake parent loader context
ComponentLoaderContext loaderContext = createComponentLoaderContext(options);
FragmentContextImpl frameContext = new FragmentContextImpl(fragment, loaderContext);
frameContext.setManualInitRequired(true);
((FrameImplementation) fragment).setContext(frameContext);
loaderContext.setCurrentFrameId(windowInfo.getId());
loaderContext.setFullFrameId(windowInfo.getId());
loaderContext.setFrame(fragment);
loaderContext.setParent(null);
loaderContext.setScreenData(UiControllerUtils.getScreenData(parent));
// load XML if needed
if (windowInfo.getTemplate() != null) {
ComponentLoaderContext innerContext = createComponentLoaderContext(options);
innerContext.setCurrentFrameId(windowInfo.getId());
innerContext.setFullFrameId(windowInfo.getId());
innerContext.setFrame(fragment);
innerContext.setParent(loaderContext);
LayoutLoader layoutLoader = applicationContext.getBean(LayoutLoader.class, innerContext);
Element rootElement = screenXmlLoader.load(windowInfo.getTemplate(), windowInfo.getId(), emptyMap());
innerContext.setMessageGroup(fragmentHelper.findMessageGroup(rootElement, windowInfo.getTemplate()));
loadAdditionalData(rootElement, innerContext);
ComponentLoader<Fragment> fragmentLoader = layoutLoader.createFragmentContent(fragment, rootElement);
fragmentLoader.loadComponent();
loaderContext.getInjectTasks().addAll(innerContext.getInjectTasks());
loaderContext.getInitTasks().addAll(innerContext.getInitTasks());
loaderContext.getPostInitTasks().addAll(innerContext.getPostInitTasks());
}
loaderContext.addInjectTask(new FragmentLoaderInjectTask(fragment, options, applicationContext));
loaderContext.addInitTask(new FragmentLoaderInitTask(fragment, options, loaderContext, applicationContext));
loadSample.stop(createScreenTimer(meterRegistry, ScreenLifeCycle.LOAD, windowInfo.getId()));
loaderContext.executeInjectTasks();
fragmentImpl.setFrame(parentFrame);
// noinspection unchecked
return (T) controller;
}
use of io.jmix.ui.xml.layout.loader.ComponentLoaderContext in project jmix by jmix-framework.
the class CubaScreens method initDsContext.
protected void initDsContext(Screen screen, Element screenDescriptor, ComponentLoaderContext context) {
DsContext dsContext = loadDsContext(screenDescriptor);
initDatasources(screen.getWindow(), dsContext, context.getParams());
((com.haulmont.cuba.gui.xml.layout.loaders.ComponentLoaderContext) context).setDsContext(dsContext);
}
use of io.jmix.ui.xml.layout.loader.ComponentLoaderContext in project jmix by jmix-framework.
the class FragmentsImpl method init.
@Override
public void init(ScreenFragment controller) {
checkNotNullArgument(controller);
FragmentContextImpl fragmentContext = (FragmentContextImpl) controller.getFragment().getContext();
if (fragmentContext.isInitialized()) {
throw new IllegalStateException("Fragment is already initialized " + controller.getId());
}
ComponentLoaderContext loaderContext = fragmentContext.getLoaderContext();
loaderContext.executeInitTasks();
loaderContext.executePostInitTasks();
fragmentContext.setInitialized(true);
}
use of io.jmix.ui.xml.layout.loader.ComponentLoaderContext in project jmix by jmix-framework.
the class ScreensImpl method createScreen.
protected <T extends Screen> T createScreen(WindowInfo windowInfo, OpenMode openMode, ScreenOptions options) {
if (windowInfo.getType() != WindowInfo.Type.SCREEN) {
throw new IllegalArgumentException(String.format("Unable to create screen %s with type %s", windowInfo.getId(), windowInfo.getType()));
}
@SuppressWarnings("unchecked") Class<T> resolvedScreenClass = (Class<T>) windowInfo.getControllerClass();
// load XML document here in order to get metadata before Window creation, e.g. forceDialog from <dialogMode>
Element element = loadScreenXml(windowInfo, options);
ScreenOpenDetails openDetails = prepareScreenOpenDetails(resolvedScreenClass, element, openMode);
checkPermissions(openDetails.getOpenMode(), windowInfo);
Timer.Sample createSample = Timer.start(meterRegistry);
Window window = createWindow(windowInfo, resolvedScreenClass, openDetails);
T controller = createController(windowInfo, window, resolvedScreenClass);
// setup screen and controller
setWindowId(controller, windowInfo.getId());
setFrame(controller, window);
setScreenContext(controller, new ScreenContextImpl(windowInfo, options, this, ui.getDialogs(), ui.getNotifications(), ui.getFragments(), ui.getUrlRouting(), ui.getWebBrowserTools()));
setScreenData(controller, applicationContext.getBean(ScreenData.class));
WindowImplementation windowImpl = (WindowImplementation) window;
windowImpl.setFrameOwner(controller);
windowImpl.setId(controller.getId());
createSample.stop(createScreenTimer(meterRegistry, ScreenLifeCycle.CREATE, windowInfo.getId()));
// load UI from XML
Timer.Sample loadSample = Timer.start(meterRegistry);
ComponentLoaderContext componentLoaderContext = createComponentLoaderContext(options);
componentLoaderContext.setFullFrameId(windowInfo.getId());
componentLoaderContext.setCurrentFrameId(windowInfo.getId());
componentLoaderContext.setMessageGroup(getPackage(resolvedScreenClass));
componentLoaderContext.setFrame(window);
if (element != null) {
loadWindowFromXml(element, windowInfo, window, controller, componentLoaderContext);
}
loadSample.stop(createScreenTimer(meterRegistry, ScreenLifeCycle.LOAD, windowInfo.getId()));
// inject top level screen dependencies
Timer.Sample injectSample = Timer.start(meterRegistry);
dependencyManager.inject(controller, options);
injectSample.stop(createScreenTimer(meterRegistry, ScreenLifeCycle.INJECTION, windowInfo.getId()));
// perform injection in nested fragments
componentLoaderContext.executeInjectTasks();
// run init
Timer.Sample initSample = Timer.start(meterRegistry);
fireScreenInitEvent(controller, InitEvent.class, new InitEvent(controller, options));
initSample.stop(createScreenTimer(meterRegistry, ScreenLifeCycle.INIT, windowInfo.getId()));
componentLoaderContext.executeInitTasks();
componentLoaderContext.executePostInitTasks();
fireScreenAfterInitEvent(controller, AfterInitEvent.class, new AfterInitEvent(controller, options));
return controller;
}
Aggregations