use of com.haulmont.cuba.gui.xml.layout.ComponentLoader in project cuba by cuba-platform.
the class WindowManager method openFrame.
public Frame openFrame(Frame parentFrame, Component parent, @Nullable String id, WindowInfo windowInfo, Map<String, Object> params) {
if (params == null) {
params = Collections.emptyMap();
}
// Parameters can be useful later
params = createParametersMap(windowInfo, params);
String src = windowInfo.getTemplate();
ComponentLoaderContext context = new ComponentLoaderContext(params);
context.setDsContext(parentFrame.getDsContext());
context.setFullFrameId(windowInfo.getId());
context.setCurrentFrameId(windowInfo.getId());
LayoutLoader loader = new LayoutLoader(context, AppConfig.getFactory(), LayoutLoaderConfig.getFrameLoaders());
loader.setLocale(getLocale());
loader.setMessagesPack(parentFrame.getMessagesPack());
StopWatch loadDescriptorWatch = new Slf4JStopWatch(windowInfo.getId() + "#" + LifeCycle.LOAD, LoggerFactory.getLogger(UIPerformanceLogger.class));
Frame component;
String frameId = id != null ? id : windowInfo.getId();
Pair<ComponentLoader, Element> loaderElementPair = loader.createFrameComponent(src, frameId, context.getParams());
component = (Frame) loaderElementPair.getFirst().getResultComponent();
if (parent != null) {
showFrame(parent, component);
} else {
component.setFrame(parentFrame);
}
loaderElementPair.getFirst().loadComponent();
if (component.getMessagesPack() == null) {
component.setMessagesPack(parentFrame.getMessagesPack());
}
context.executeInjectTasks();
context.setFrame(component);
context.executePostWrapTasks();
// init of frame
context.executeInitTasks();
context.executePostInitTasks();
loadDescriptorWatch.stop();
initDebugIds(component);
userActionsLog.trace("Frame {} was opened", windowInfo.getId());
return component;
}
use of com.haulmont.cuba.gui.xml.layout.ComponentLoader in project cuba by cuba-platform.
the class WindowManager method createWindow.
protected Window createWindow(WindowInfo windowInfo, OpenType openType, Map<String, Object> params, LayoutLoaderConfig layoutConfig, boolean topLevel) {
if (!topLevel) {
checkPermission(windowInfo);
}
StopWatch loadDescriptorWatch = new Slf4JStopWatch(windowInfo.getId() + "#" + LifeCycle.LOAD, LoggerFactory.getLogger(UIPerformanceLogger.class));
Element element = screenXmlLoader.load(windowInfo.getTemplate(), windowInfo.getId(), params);
// try to load main screen class to resolve dynamic compilation dependencies issues
preloadMainScreenClass(element);
ComponentLoaderContext componentLoaderContext = new ComponentLoaderContext(params);
componentLoaderContext.setFullFrameId(windowInfo.getId());
componentLoaderContext.setCurrentFrameId(windowInfo.getId());
ComponentLoader windowLoader = createLayout(windowInfo, element, componentLoaderContext, layoutConfig);
Window clientSpecificWindow = (Window) windowLoader.getResultComponent();
Window windowWrapper = wrapByCustomClass(clientSpecificWindow, element);
screenViewsLoader.deployViews(element);
DsContext dsContext = loadDsContext(element);
initDatasources(clientSpecificWindow, dsContext, params);
componentLoaderContext.setDsContext(dsContext);
WindowContext windowContext = new WindowContextImpl(clientSpecificWindow, openType, params);
clientSpecificWindow.setContext(windowContext);
dsContext.setFrameContext(windowContext);
// noinspection unchecked
windowLoader.loadComponent();
clientSpecificWindow.setWindowManager(this);
loadDescriptorWatch.stop();
initWrapperFrame(windowWrapper, componentLoaderContext, element, params);
componentLoaderContext.setFrame(windowWrapper);
componentLoaderContext.executePostInitTasks();
if (configuration.getConfig(GlobalConfig.class).getTestMode()) {
initDebugIds(clientSpecificWindow);
}
StopWatch uiPermissionsWatch = new Slf4JStopWatch(windowInfo.getId() + "#" + LifeCycle.UI_PERMISSIONS, LoggerFactory.getLogger(UIPerformanceLogger.class));
// apply ui permissions
WindowCreationHelper.applyUiPermissions(clientSpecificWindow);
uiPermissionsWatch.stop();
return windowWrapper;
}
use of com.haulmont.cuba.gui.xml.layout.ComponentLoader in project cuba by cuba-platform.
the class AccordionLoader method createComponent.
@Override
public void createComponent() {
resultComponent = (Accordion) factory.createComponent(Accordion.NAME);
loadId(resultComponent, element);
// noinspection unchecked
List<Element> tabElements = element.elements("tab");
for (Element tabElement : tabElements) {
final String name = tabElement.attributeValue("id");
boolean lazy = Boolean.parseBoolean(tabElement.attributeValue("lazy"));
ComponentLoader tabComponentLoader = getLoader(tabElement, TabComponentLoader.class);
Accordion.Tab tab;
if (lazy) {
tab = resultComponent.addLazyTab(name, tabElement, tabComponentLoader);
} else {
tabComponentLoader.createComponent();
Component tabComponent = tabComponentLoader.getResultComponent();
tab = resultComponent.addTab(name, tabComponent);
pendingLoadComponents.add(tabComponentLoader);
}
pendingLoadTabs.put(tabElement, tab);
}
}
use of com.haulmont.cuba.gui.xml.layout.ComponentLoader in project cuba by cuba-platform.
the class FrameComponentLoader 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.getFullFrameId());
}
if (src == null) {
WindowConfig windowConfig = AppBeans.get(WindowConfig.NAME);
WindowInfo windowInfo = windowConfig.getWindowInfo(screenId);
src = windowInfo.getTemplate();
if (src == null) {
throw new GuiDevelopmentException("Screen " + screenId + " doesn't have template path configured", context.getFullFrameId());
}
}
if (element.attributeValue("id") != null) {
frameId = element.attributeValue("id");
}
LayoutLoader layoutLoader = new LayoutLoader(context, factory, LayoutLoaderConfig.getFrameLoaders());
layoutLoader.setLocale(getLocale());
layoutLoader.setMessagesPack(getMessagesPack());
String currentFrameId = context.getCurrentFrameId();
context.setCurrentFrameId(frameId);
try {
Pair<ComponentLoader, Element> loaderElementPair = layoutLoader.createFrameComponent(src, frameId, context.getParams());
frameLoader = loaderElementPair.getFirst();
resultComponent = (Frame) frameLoader.getResultComponent();
} finally {
context.setCurrentFrameId(currentFrameId);
}
}
use of com.haulmont.cuba.gui.xml.layout.ComponentLoader in project cuba by cuba-platform.
the class RuntimePropertiesFrameLoader method createComponent.
@Override
public void createComponent() {
String src = element.attributeValue("src");
if (src == null) {
src = DEFAULT_DESCRIPTOR;
}
String screenPath = src;
if (element.attributeValue("id") != null) {
screenPath = element.attributeValue("id");
}
frameId = screenPath;
LayoutLoader layoutLoader = new LayoutLoader(context, factory, LayoutLoaderConfig.getFrameLoaders());
layoutLoader.setLocale(getLocale());
layoutLoader.setMessagesPack(getMessagesPack());
String currentFrameId = context.getCurrentFrameId();
context.setCurrentFrameId(frameId);
try {
Pair<ComponentLoader, Element> loaderElementPair = layoutLoader.createFrameComponent(src, frameId, context.getParams());
frameLoader = loaderElementPair.getFirst();
resultComponent = (Frame) frameLoader.getResultComponent();
} finally {
context.setCurrentFrameId(currentFrameId);
}
}
Aggregations