Search in sources :

Example 21 with LegacyFrame

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);
}
Also used : ListAction(com.haulmont.cuba.gui.components.actions.ListAction) Action(com.haulmont.cuba.gui.components.Action) Actions(com.haulmont.cuba.gui.components.Actions) GuiDevelopmentException(com.haulmont.cuba.gui.GuiDevelopmentException) LegacyFrame(com.haulmont.cuba.gui.screen.compatibility.LegacyFrame) ListActionType(com.haulmont.cuba.gui.components.actions.ListActionType) ListAction(com.haulmont.cuba.gui.components.actions.ListAction)

Example 22 with LegacyFrame

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);
}
Also used : UserSession(com.haulmont.cuba.security.global.UserSession) LegacyFrame(com.haulmont.cuba.gui.screen.compatibility.LegacyFrame) GuiDevelopmentException(com.haulmont.cuba.gui.GuiDevelopmentException)

Example 23 with LegacyFrame

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;
}
Also used : LayoutLoader(com.haulmont.cuba.gui.xml.layout.LayoutLoader) LegacyFrame(com.haulmont.cuba.gui.screen.compatibility.LegacyFrame) Frame(com.haulmont.cuba.gui.components.Frame) FragmentImplementation(com.haulmont.cuba.gui.components.sys.FragmentImplementation) Element(org.dom4j.Element) FragmentLoaderInjectTask(com.haulmont.cuba.gui.sys.FragmentHelper.FragmentLoaderInjectTask) LegacyFrame(com.haulmont.cuba.gui.screen.compatibility.LegacyFrame) FragmentContextImpl(com.haulmont.cuba.gui.sys.FragmentContextImpl) FrameImplementation(com.haulmont.cuba.gui.components.sys.FrameImplementation) Fragment(com.haulmont.cuba.gui.components.Fragment) ComponentLoaderContext(com.haulmont.cuba.gui.xml.layout.loaders.ComponentLoaderContext) UIPerformanceLogger.createStopWatch(com.haulmont.cuba.gui.logging.UIPerformanceLogger.createStopWatch) StopWatch(org.perf4j.StopWatch) ScreenDataImpl(com.haulmont.cuba.gui.model.impl.ScreenDataImpl) ScreenContextImpl(com.haulmont.cuba.gui.sys.ScreenContextImpl) FragmentLoaderInitTask(com.haulmont.cuba.gui.sys.FragmentHelper.FragmentLoaderInitTask)

Aggregations

LegacyFrame (com.haulmont.cuba.gui.screen.compatibility.LegacyFrame)23 Entity (com.haulmont.cuba.core.entity.Entity)5 WindowConfig (com.haulmont.cuba.gui.config.WindowConfig)5 Datasource (com.haulmont.cuba.gui.data.Datasource)5 DsContext (com.haulmont.cuba.gui.data.DsContext)5 GuiDevelopmentException (com.haulmont.cuba.gui.GuiDevelopmentException)4 MetaClass (com.haulmont.chile.core.model.MetaClass)3 DsContextImplementation (com.haulmont.cuba.gui.data.impl.DsContextImplementation)3 MetaProperty (com.haulmont.chile.core.model.MetaProperty)2 SoftDelete (com.haulmont.cuba.core.entity.SoftDelete)2 DevelopmentException (com.haulmont.cuba.core.global.DevelopmentException)2 Messages (com.haulmont.cuba.core.global.Messages)2 WindowManager (com.haulmont.cuba.gui.WindowManager)2 OpenType (com.haulmont.cuba.gui.WindowManager.OpenType)2 com.haulmont.cuba.gui.components (com.haulmont.cuba.gui.components)2 Component (com.haulmont.cuba.gui.components.Component)2 Filter (com.haulmont.cuba.gui.components.Filter)2 Frame (com.haulmont.cuba.gui.components.Frame)2 WindowInfo (com.haulmont.cuba.gui.config.WindowInfo)2 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)2