Search in sources :

Example 36 with FrameOwner

use of com.haulmont.cuba.gui.screen.FrameOwner 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)

Example 37 with FrameOwner

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

the class TimerFacetProvider method addInitTimerMethodTask.

// for compatibility only
@Deprecated
protected void addInitTimerMethodTask(Timer timer, String timerMethodName, ComponentContext context) {
    FrameOwner controller = context.getFrame().getFrameOwner();
    if (controller instanceof LegacyFragmentAdapter) {
        controller = ((LegacyFragmentAdapter) controller).getRealScreen();
    }
    Class<? extends FrameOwner> windowClass = controller.getClass();
    Method timerMethod;
    try {
        timerMethod = windowClass.getMethod(timerMethodName, Timer.class);
    } catch (NoSuchMethodException e) {
        throw new GuiDevelopmentException("Unable to find invoke method for timer", context, ParamsMap.of("Timer Id", timer.getId(), "Method name", timerMethodName));
    }
    timer.addTimerActionListener(new DeclarativeTimerActionHandler(timerMethod, controller));
}
Also used : FrameOwner(com.haulmont.cuba.gui.screen.FrameOwner) Timer(com.haulmont.cuba.gui.components.Timer) WebTimer(com.haulmont.cuba.web.gui.components.WebTimer) GuiDevelopmentException(com.haulmont.cuba.gui.GuiDevelopmentException) Method(java.lang.reflect.Method) LegacyFragmentAdapter(com.haulmont.cuba.gui.components.compatibility.LegacyFragmentAdapter)

Example 38 with FrameOwner

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

the class LinkCellClickListener method callControllerInvoke.

protected void callControllerInvoke(Entity rowItem, String columnId, String invokeMethodName) {
    FrameOwner controller = table.getFrame().getFrameOwner();
    if (controller instanceof LegacyFragmentAdapter) {
        controller = ((LegacyFragmentAdapter) controller).getRealScreen();
    }
    Method method;
    method = findLinkInvokeMethod(controller.getClass(), invokeMethodName);
    if (method != null) {
        try {
            method.invoke(controller, rowItem, columnId);
        } catch (Exception e) {
            throw new RuntimeException("Unable to cal linkInvoke method for table column", e);
        }
    } else {
        try {
            method = controller.getClass().getMethod(invokeMethodName);
            try {
                method.invoke(controller);
            } catch (Exception e1) {
                throw new RuntimeException("Unable to call linkInvoke method for table column", e1);
            }
        } catch (NoSuchMethodException e1) {
            throw new IllegalStateException(String.format("No suitable methods named %s for invoke", invokeMethodName));
        }
    }
}
Also used : FrameOwner(com.haulmont.cuba.gui.screen.FrameOwner) Method(java.lang.reflect.Method) LegacyFragmentAdapter(com.haulmont.cuba.gui.components.compatibility.LegacyFragmentAdapter)

Aggregations

FrameOwner (com.haulmont.cuba.gui.screen.FrameOwner)38 GuiDevelopmentException (com.haulmont.cuba.gui.GuiDevelopmentException)15 ScreenData (com.haulmont.cuba.gui.model.ScreenData)9 Component (com.haulmont.cuba.gui.components.Component)7 InstanceContainer (com.haulmont.cuba.gui.model.InstanceContainer)7 Element (org.dom4j.Element)7 LegacyFragmentAdapter (com.haulmont.cuba.gui.components.compatibility.LegacyFragmentAdapter)6 CollectionContainer (com.haulmont.cuba.gui.model.CollectionContainer)6 ScreenFragment (com.haulmont.cuba.gui.screen.ScreenFragment)6 Method (java.lang.reflect.Method)6 MetaClass (com.haulmont.chile.core.model.MetaClass)5 Frame (com.haulmont.cuba.gui.components.Frame)5 Datasource (com.haulmont.cuba.gui.data.Datasource)5 WindowInfo (com.haulmont.cuba.gui.config.WindowInfo)4 Screen (com.haulmont.cuba.gui.screen.Screen)4 Fragment (com.haulmont.cuba.gui.components.Fragment)3 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)3 LegacyFrame (com.haulmont.cuba.gui.screen.compatibility.LegacyFrame)3 Screens (com.haulmont.cuba.gui.Screens)2 FragmentImplementation (com.haulmont.cuba.gui.components.sys.FragmentImplementation)2