use of com.haulmont.cuba.gui.screen.compatibility.LegacyFrame in project cuba by cuba-platform.
the class ActionsHolderLoader method loadDeclarativeAction.
@Override
protected Action loadDeclarativeAction(ActionsHolder actionsHolder, Element element) {
String id = element.attributeValue("id");
if (StringUtils.isEmpty(id)) {
throw new GuiDevelopmentException("No action id provided", context, "ActionsHolder ID", actionsHolder.getId());
}
if (StringUtils.isEmpty(element.attributeValue("invoke"))) {
// only in legacy frames
if (context instanceof ComponentContext && ((ComponentContext) context).getFrame().getFrameOwner() instanceof LegacyFrame) {
// Try to create a standard list action
for (ListActionType type : ListActionType.values()) {
if (type.getId().equals(id)) {
Action instance = type.createAction((ListComponent) actionsHolder);
loadStandardActionProperties(instance, element);
loadActionOpenType(instance, element);
loadActionConstraint(instance, element);
loadShortcut(instance, element);
return instance;
}
}
} else {
String actionTypeId = element.attributeValue("type");
if (StringUtils.isNotEmpty(actionTypeId)) {
Actions actions = beanLocator.get(Actions.NAME);
Action instance = actions.create(actionTypeId, id);
if (instance instanceof ListAction) {
((ListAction) instance).setTarget((ListComponent) actionsHolder);
}
loadStandardActionProperties(instance, element);
loadActionConstraint(instance, element);
loadShortcut(instance, element);
loadCustomProperties(instance, element);
return instance;
}
}
}
return super.loadDeclarativeAction(actionsHolder, element);
}
use of com.haulmont.cuba.gui.screen.compatibility.LegacyFrame in project cuba by cuba-platform.
the class BulkEditorLoader method loadComponent.
@Override
public void loadComponent() {
assignXmlDescriptor(resultComponent, element);
assignFrame(resultComponent);
Window window = ComponentsHelper.getWindow(resultComponent);
if (window != null && !(window.getFrameOwner() instanceof LegacyFrame)) {
throw new GuiDevelopmentException("BulkEditor component can be used only in legacy screens based on AbstractWindow", context);
}
loadEnable(resultComponent, element);
loadVisible(resultComponent, element);
loadStyleName(resultComponent, element);
loadHtmlSanitizerEnabled(resultComponent, element);
loadCaption(resultComponent, element);
loadDescription(resultComponent, element);
loadIcon(resultComponent, element);
loadWidth(resultComponent, element);
loadAlign(resultComponent, element);
loadResponsive(resultComponent, element);
loadCss(resultComponent, element);
loadColumns(resultComponent, element);
loadTabIndex(resultComponent, element);
UserSession userSession = getUserSessionSource().getUserSession();
if (!userSession.isSpecificPermitted(BulkEditor.PERMISSION)) {
resultComponent.setVisible(false);
}
String openType = element.attributeValue("openType");
if (StringUtils.isNotEmpty(openType)) {
resultComponent.setOpenType(WindowManager.OpenType.valueOf(openType));
}
String exclude = element.attributeValue("exclude");
String includeProperties = element.attributeValue("includeProperties");
if (StringUtils.isNotBlank(exclude) && StringUtils.isNotBlank(includeProperties)) {
throw new GuiDevelopmentException("BulkEditor cannot define simultaneously exclude and includeProperties attributes", getContext());
}
if (StringUtils.isNotBlank(exclude)) {
resultComponent.setExcludePropertiesRegex(exclude.replace(" ", ""));
}
if (StringUtils.isNotBlank(includeProperties)) {
resultComponent.setIncludeProperties(Splitter.on(',').omitEmptyStrings().trimResults().splitToList(includeProperties));
}
String listComponent = element.attributeValue("for");
if (StringUtils.isEmpty(listComponent)) {
throw new GuiDevelopmentException("'for' attribute of bulk editor is not specified", context, "componentId", resultComponent.getId());
}
String loadDynamicAttributes = element.attributeValue("loadDynamicAttributes");
if (StringUtils.isNotEmpty(loadDynamicAttributes)) {
resultComponent.setLoadDynamicAttributes(Boolean.parseBoolean(loadDynamicAttributes));
}
String useConfirmDialog = element.attributeValue("useConfirmDialog");
if (StringUtils.isNotEmpty(useConfirmDialog)) {
resultComponent.setUseConfirmDialog(Boolean.parseBoolean(useConfirmDialog));
}
getComponentContext().addPostInitTask((c, w) -> {
if (resultComponent.getListComponent() == null) {
Component bindComponent = resultComponent.getFrame().getComponent(listComponent);
if (!(bindComponent instanceof ListComponent)) {
throw new GuiDevelopmentException("Specify 'for' attribute: id of table or tree", context, "componentId", resultComponent.getId());
}
resultComponent.setListComponent((ListComponent) bindComponent);
}
});
loadValidators(resultComponent, element);
loadFocusable(resultComponent, element);
}
use of com.haulmont.cuba.gui.screen.compatibility.LegacyFrame in project cuba by cuba-platform.
the class WebFragments method createFragment.
protected <T extends ScreenFragment> T createFragment(FrameOwner parent, WindowInfo windowInfo, ScreenOptions options) {
if (windowInfo.getType() != WindowInfo.Type.FRAGMENT && !AbstractWindow.class.isAssignableFrom(windowInfo.getControllerClass())) {
throw new IllegalArgumentException(String.format("Unable to create fragment %s it is a screen: %s", windowInfo.getId(), windowInfo.getControllerClass()));
}
StopWatch createStopWatch = createStopWatch(ScreenLifeCycle.CREATE, windowInfo.getId());
Fragment fragment = uiComponents.create(Fragment.NAME);
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, new ScreenDataImpl());
FragmentImplementation fragmentImpl = (FragmentImplementation) fragment;
fragmentImpl.setFrameOwner(controller);
fragmentImpl.setId(controller.getId());
createStopWatch.stop();
StopWatch loadStopWatch = createStopWatch(ScreenLifeCycle.LOAD, windowInfo.getId());
Frame parentFrame = getFrame(parent);
// fake parent loader context
ComponentLoaderContext loaderContext = new ComponentLoaderContext(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));
if (parent instanceof LegacyFrame) {
loaderContext.setDsContext(((LegacyFrame) parent).getDsContext());
}
// load XML if needed
if (windowInfo.getTemplate() != null) {
ComponentLoaderContext innerContext = new ComponentLoaderContext(options);
innerContext.setMessagesPack(fragmentHelper.getMessagePack(windowInfo.getTemplate()));
innerContext.setCurrentFrameId(windowInfo.getId());
innerContext.setFullFrameId(windowInfo.getId());
innerContext.setFrame(fragment);
innerContext.setParent(loaderContext);
LayoutLoader layoutLoader = beanLocator.getPrototype(LayoutLoader.NAME, innerContext);
Element rootElement = screenXmlLoader.load(windowInfo.getTemplate(), windowInfo.getId(), innerContext.getParams());
String messagesPack = rootElement.attributeValue("messagesPack");
if (messagesPack != null) {
innerContext.setMessagesPack(messagesPack);
}
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, beanLocator));
loaderContext.addInitTask(new FragmentLoaderInitTask(fragment, options, loaderContext, beanLocator));
loadStopWatch.stop();
loaderContext.executeInjectTasks();
fragmentImpl.setFrame(parentFrame);
// noinspection unchecked
return (T) controller;
}
Aggregations