Search in sources :

Example 6 with ScreenFragment

use of com.haulmont.cuba.gui.screen.ScreenFragment in project cuba by cuba-platform.

the class WebDataLoadCoordinator method configureAutomatically.

private void configureAutomatically(DataLoader loader, FrameOwner frameOwner) {
    List<String> queryParameters = DataLoadersHelper.getQueryParameters(loader);
    List<String> allParameters = new ArrayList<>(queryParameters);
    allParameters.addAll(getConditionParameters(loader));
    // add triggers on container/component events
    for (String parameter : allParameters) {
        if (parameter.startsWith(containerPrefix)) {
            InstanceContainer container = UiControllerUtils.getScreenData(frameOwner).getContainer(parameter.substring(containerPrefix.length()));
            addOnContainerItemChangedLoadTrigger(loader, container, parameter);
        } else if (parameter.startsWith(componentPrefix)) {
            String componentId = parameter.substring(componentPrefix.length());
            Component component = frameOwner instanceof Screen ? ((Screen) frameOwner).getWindow().getComponentNN(componentId) : ((ScreenFragment) frameOwner).getFragment().getComponentNN(componentId);
            LikeClause likeClause = findLikeClause(loader, parameter);
            addOnComponentValueChangedLoadTrigger(loader, component, parameter, likeClause);
        }
    }
    // if the loader has no parameters in query, add trigger on BeforeShowEvent/AttachEvent
    if (queryParameters.isEmpty()) {
        Class eventClass = frameOwner instanceof Screen ? Screen.BeforeShowEvent.class : ScreenFragment.AttachEvent.class;
        addOnFrameOwnerEventLoadTrigger(loader, eventClass);
    }
}
Also used : ScreenFragment(com.haulmont.cuba.gui.screen.ScreenFragment) Screen(com.haulmont.cuba.gui.screen.Screen) ArrayList(java.util.ArrayList) InstanceContainer(com.haulmont.cuba.gui.model.InstanceContainer) Component(com.haulmont.cuba.gui.components.Component)

Example 7 with ScreenFragment

use of com.haulmont.cuba.gui.screen.ScreenFragment in project cuba by cuba-platform.

the class RuntimePropertiesFrameLoader method createComponent.

@Override
public void createComponent() {
    String src = element.attributeValue("src");
    String screenId = element.attributeValue("id");
    if (src == null) {
        src = DEFAULT_DESCRIPTOR;
    }
    String fragmentId = screenId != null ? screenId : src;
    FragmentHelper fragmentHelper = getFragmentHelper();
    WindowInfo windowInfo = fragmentHelper.createFakeWindowInfo(src, fragmentId);
    Fragment fragment = factory.create(Fragment.NAME);
    ScreenFragment controller = fragmentHelper.createController(windowInfo, fragment);
    // setup screen and controller
    ComponentLoaderContext parentContext = (ComponentLoaderContext) getContext();
    FrameOwner hostController = parentContext.getFrame().getFrameOwner();
    // setup screen and controller
    setHostController(controller, hostController);
    setWindowId(controller, windowInfo.getId());
    setFrame(controller, fragment);
    setScreenContext(controller, new ScreenContextImpl(windowInfo, parentContext.getOptions(), getScreenContext(hostController)));
    setScreenData(controller, new ScreenDataImpl());
    FragmentImplementation fragmentImpl = (FragmentImplementation) fragment;
    fragmentImpl.setFrameOwner(controller);
    fragmentImpl.setId(fragmentId);
    FragmentContextImpl frameContext = new FragmentContextImpl(fragment, innerContext);
    ((FrameImplementation) fragment).setContext(frameContext);
    if (windowInfo.getTemplate() != null) {
        String frameId = fragmentId;
        if (parentContext.getFullFrameId() != null) {
            frameId = parentContext.getFullFrameId() + "." + frameId;
        }
        innerContext = new ComponentLoaderContext(getContext().getOptions());
        innerContext.setMessagesPack(fragmentHelper.getMessagePack(windowInfo.getTemplate()));
        innerContext.setCurrentFrameId(fragmentId);
        innerContext.setFullFrameId(frameId);
        innerContext.setFrame(fragment);
        innerContext.setParent(parentContext);
        LayoutLoader layoutLoader = getLayoutLoader(innerContext);
        ScreenXmlLoader screenXmlLoader = beanLocator.get(ScreenXmlLoader.NAME);
        Element rootElement = screenXmlLoader.load(windowInfo.getTemplate(), windowInfo.getId(), getContext().getParams());
        String messagesPack = rootElement.attributeValue("messagesPack");
        if (messagesPack != null) {
            innerContext.setMessagesPack(messagesPack);
        }
        this.fragmentLoader = layoutLoader.createFragmentContent(fragment, rootElement);
    }
    this.resultComponent = fragment;
}
Also used : LayoutLoader(com.haulmont.cuba.gui.xml.layout.LayoutLoader) FragmentImplementation(com.haulmont.cuba.gui.components.sys.FragmentImplementation) Element(org.dom4j.Element) FragmentContextImpl(com.haulmont.cuba.gui.sys.FragmentContextImpl) FrameImplementation(com.haulmont.cuba.gui.components.sys.FrameImplementation) Fragment(com.haulmont.cuba.gui.components.Fragment) ScreenFragment(com.haulmont.cuba.gui.screen.ScreenFragment) WindowInfo(com.haulmont.cuba.gui.config.WindowInfo) ScreenFragment(com.haulmont.cuba.gui.screen.ScreenFragment) FrameOwner(com.haulmont.cuba.gui.screen.FrameOwner) ScreenDataImpl(com.haulmont.cuba.gui.model.impl.ScreenDataImpl) FragmentHelper(com.haulmont.cuba.gui.sys.FragmentHelper) ScreenContextImpl(com.haulmont.cuba.gui.sys.ScreenContextImpl) ScreenXmlLoader(com.haulmont.cuba.gui.xml.layout.ScreenXmlLoader)

Example 8 with ScreenFragment

use of com.haulmont.cuba.gui.screen.ScreenFragment in project cuba by cuba-platform.

the class AbstractLookup method initLookupLayout.

@Override
public void initLookupLayout() {
    Action selectAction = getAction(LOOKUP_SELECT_ACTION_ID);
    if (selectAction != null && selectAction.getOwner() == null) {
        Fragments fragments = UiControllerUtils.getScreenContext(this).getFragments();
        ScreenFragment lookupWindowActions = fragments.create(this, "lookupWindowActions");
        lookupWindowActions.getFragment().setId("lookupWindowActions");
        lookupWindowActions.getFragment().setVisible(false);
        getFrame().add(lookupWindowActions.getFragment());
    }
    Element element = ((Component.HasXmlDescriptor) getFrame()).getXmlDescriptor();
    if (element != null) {
        String lookupComponent = element.attributeValue("lookupComponent");
        if (StringUtils.isNotEmpty(lookupComponent)) {
            Component component = getFrame().getComponent(lookupComponent);
            setLookupComponent(component);
        }
    }
    Component lookupComponent = getLookupComponent();
    if (lookupComponent instanceof LookupSelectionChangeNotifier) {
        LookupSelectionChangeNotifier selectionNotifier = (LookupSelectionChangeNotifier) lookupComponent;
        if (selectAction != null) {
            // noinspection unchecked
            selectionNotifier.addLookupValueChangeListener(valueChangeEvent -> selectAction.setEnabled(!selectionNotifier.getLookupSelectedItems().isEmpty()));
            selectAction.setEnabled(!selectionNotifier.getLookupSelectedItems().isEmpty());
        }
    }
}
Also used : BaseAction(com.haulmont.cuba.gui.components.actions.BaseAction) ScreenFragment(com.haulmont.cuba.gui.screen.ScreenFragment) Element(org.dom4j.Element) Fragments(com.haulmont.cuba.gui.Fragments) LookupSelectionChangeNotifier(com.haulmont.cuba.gui.components.LookupComponent.LookupSelectionChangeNotifier)

Example 9 with ScreenFragment

use of com.haulmont.cuba.gui.screen.ScreenFragment in project cuba by cuba-platform.

the class FragmentComponentLoader 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, "fragment", element.attributeValue("id"));
    }
    String fragmentId;
    if (element.attributeValue("id") != null) {
        fragmentId = element.attributeValue("id");
    } else if (screenId != null) {
        fragmentId = screenId;
    } else {
        fragmentId = src;
    }
    FragmentHelper fragmentHelper = getFragmentHelper();
    WindowInfo windowInfo;
    if (src == null) {
        // load screen class only once
        windowInfo = getWindowConfig().getWindowInfo(screenId).resolve();
    } else {
        windowInfo = fragmentHelper.createFakeWindowInfo(src, fragmentId);
    }
    StopWatch createStopWatch = createStopWatch(ScreenLifeCycle.CREATE, windowInfo.getId());
    Fragment fragment = factory.create(Fragment.NAME);
    ScreenFragment controller = fragmentHelper.createController(windowInfo, fragment);
    // setup screen and controller
    ComponentLoaderContext parentContext = (ComponentLoaderContext) getContext();
    FrameOwner hostController = parentContext.getFrame().getFrameOwner();
    setHostController(controller, hostController);
    setWindowId(controller, windowInfo.getId());
    setFrame(controller, fragment);
    setScreenContext(controller, new ScreenContextImpl(windowInfo, parentContext.getOptions(), getScreenContext(hostController)));
    setScreenData(controller, new ScreenDataImpl());
    FragmentImplementation fragmentImpl = (FragmentImplementation) fragment;
    fragmentImpl.setFrameOwner(controller);
    fragmentImpl.setId(fragmentId);
    FragmentContextImpl frameContext = new FragmentContextImpl(fragment, innerContext);
    ((FrameImplementation) fragment).setContext(frameContext);
    if (windowInfo.getTemplate() != null) {
        String frameId = fragmentId;
        if (parentContext.getFullFrameId() != null) {
            frameId = parentContext.getFullFrameId() + "." + frameId;
        }
        innerContext = new ComponentLoaderContext(getComponentContext().getOptions());
        innerContext.setMessagesPack(fragmentHelper.getMessagePack(windowInfo.getTemplate()));
        innerContext.setCurrentFrameId(fragmentId);
        innerContext.setFullFrameId(frameId);
        innerContext.setFrame(fragment);
        innerContext.setParent(parentContext);
        innerContext.setProperties(loadProperties(element));
        LayoutLoader layoutLoader = getLayoutLoader(innerContext);
        ScreenXmlLoader screenXmlLoader = beanLocator.get(ScreenXmlLoader.NAME);
        Element rootElement = screenXmlLoader.load(windowInfo.getTemplate(), windowInfo.getId(), getComponentContext().getParams());
        String messagesPack = rootElement.attributeValue("messagesPack");
        if (messagesPack != null) {
            innerContext.setMessagesPack(messagesPack);
        }
        this.fragmentLoader = layoutLoader.createFragmentContent(fragment, rootElement);
    }
    createStopWatch.stop();
    this.resultComponent = fragment;
}
Also used : LayoutLoader(com.haulmont.cuba.gui.xml.layout.LayoutLoader) FragmentImplementation(com.haulmont.cuba.gui.components.sys.FragmentImplementation) Element(org.dom4j.Element) FragmentContextImpl(com.haulmont.cuba.gui.sys.FragmentContextImpl) FrameImplementation(com.haulmont.cuba.gui.components.sys.FrameImplementation) Fragment(com.haulmont.cuba.gui.components.Fragment) ScreenFragment(com.haulmont.cuba.gui.screen.ScreenFragment) WindowInfo(com.haulmont.cuba.gui.config.WindowInfo) UIPerformanceLogger.createStopWatch(com.haulmont.cuba.gui.logging.UIPerformanceLogger.createStopWatch) StopWatch(org.perf4j.StopWatch) ScreenFragment(com.haulmont.cuba.gui.screen.ScreenFragment) FrameOwner(com.haulmont.cuba.gui.screen.FrameOwner) ScreenDataImpl(com.haulmont.cuba.gui.model.impl.ScreenDataImpl) FragmentHelper(com.haulmont.cuba.gui.sys.FragmentHelper) GuiDevelopmentException(com.haulmont.cuba.gui.GuiDevelopmentException) ScreenContextImpl(com.haulmont.cuba.gui.sys.ScreenContextImpl) ScreenXmlLoader(com.haulmont.cuba.gui.xml.layout.ScreenXmlLoader)

Aggregations

ScreenFragment (com.haulmont.cuba.gui.screen.ScreenFragment)9 FrameOwner (com.haulmont.cuba.gui.screen.FrameOwner)6 Screen (com.haulmont.cuba.gui.screen.Screen)4 Element (org.dom4j.Element)3 Component (com.haulmont.cuba.gui.components.Component)2 Fragment (com.haulmont.cuba.gui.components.Fragment)2 FragmentImplementation (com.haulmont.cuba.gui.components.sys.FragmentImplementation)2 FrameImplementation (com.haulmont.cuba.gui.components.sys.FrameImplementation)2 WindowInfo (com.haulmont.cuba.gui.config.WindowInfo)2 ScreenDataImpl (com.haulmont.cuba.gui.model.impl.ScreenDataImpl)2 FragmentContextImpl (com.haulmont.cuba.gui.sys.FragmentContextImpl)2 FragmentHelper (com.haulmont.cuba.gui.sys.FragmentHelper)2 ScreenContextImpl (com.haulmont.cuba.gui.sys.ScreenContextImpl)2 LayoutLoader (com.haulmont.cuba.gui.xml.layout.LayoutLoader)2 ScreenXmlLoader (com.haulmont.cuba.gui.xml.layout.ScreenXmlLoader)2 Nullable (javax.annotation.Nullable)2 DevelopmentException (com.haulmont.cuba.core.global.DevelopmentException)1 Fragments (com.haulmont.cuba.gui.Fragments)1 GuiDevelopmentException (com.haulmont.cuba.gui.GuiDevelopmentException)1 AbstractWindow (com.haulmont.cuba.gui.components.AbstractWindow)1