use of io.jmix.ui.sys.FragmentHelper.FragmentLoaderInitTask 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.sys.FragmentHelper.FragmentLoaderInitTask in project jmix by jmix-framework.
the class FragmentComponentLoader method loadComponent.
@Override
public void loadComponent() {
loadAliases();
if (getComponentContext().getFrame() != null) {
resultComponent.setFrame(getComponentContext().getFrame());
}
String src = element.attributeValue("src");
String screenId = element.attributeValue("screen");
String screenPath = StringUtils.isEmpty(screenId) ? src : screenId;
if (element.attributeValue("id") != null) {
screenPath = element.attributeValue("id");
}
if (getComponentContext().getFrame() != null) {
String parentId = getComponentContext().getFullFrameId();
if (StringUtils.isNotEmpty(parentId)) {
screenPath = parentId + "." + screenPath;
}
}
Timer.Sample sample = Timer.start(getMeterRegistry());
if (fragmentLoader != null) {
fragmentLoader.loadComponent();
}
// load properties after inner context, they must override values defined inside of fragment
assignXmlDescriptor(resultComponent, element);
loadVisible(resultComponent, element);
loadEnable(resultComponent, element);
loadStyleName(resultComponent, element);
loadResponsive(resultComponent, element);
loadCss(resultComponent, element);
loadAlign(resultComponent, element);
loadHeight(resultComponent, element);
loadWidth(resultComponent, element);
loadIcon(resultComponent, element);
loadCaption(resultComponent, element);
loadDescription(resultComponent, element);
sample.stop(createScreenTimer(getMeterRegistry(), ScreenLifeCycle.LOAD, screenPath));
// propagate init phases
ComponentLoaderContext parentContext = (ComponentLoaderContext) getContext();
if (innerContext != null) {
parentContext.getInjectTasks().addAll(innerContext.getInjectTasks());
parentContext.getInitTasks().addAll(innerContext.getInitTasks());
parentContext.getPostInitTasks().addAll(innerContext.getPostInitTasks());
}
ScreenOptions options = parentContext.getOptions();
parentContext.addInjectTask(new FragmentLoaderInjectTask(resultComponent, options, applicationContext));
parentContext.addInitTask(new FragmentLoaderInitTask(resultComponent, options, innerContext, applicationContext));
}
Aggregations