Search in sources :

Example 6 with LegacyFragmentAdapter

use of com.haulmont.cuba.gui.components.compatibility.LegacyFragmentAdapter in project cuba by cuba-platform.

the class DeclarativeTrackingAction method actionPerform.

@Override
public void actionPerform(Component component) {
    if (StringUtils.isEmpty(methodName)) {
        return;
    }
    FrameOwner controller = frame.getFrameOwner();
    if (controller instanceof LegacyFragmentAdapter) {
        controller = ((LegacyFragmentAdapter) controller).getRealScreen();
    }
    Method method;
    try {
        method = controller.getClass().getMethod(methodName, Component.class);
    } catch (NoSuchMethodException e) {
        try {
            method = controller.getClass().getMethod(methodName);
        } catch (NoSuchMethodException e1) {
            throw new IllegalStateException(String.format("No suitable methods named %s for action %s", methodName, id));
        }
    }
    try {
        if (method.getParameterCount() == 1) {
            method.invoke(controller, component);
        } else {
            method.invoke(controller);
        }
    } catch (Exception e) {
        throw new RuntimeException("Exception on action handling", e);
    }
}
Also used : FrameOwner(com.haulmont.cuba.gui.screen.FrameOwner) Method(java.lang.reflect.Method) LegacyFragmentAdapter(com.haulmont.cuba.gui.components.compatibility.LegacyFragmentAdapter) Component(com.haulmont.cuba.gui.components.Component)

Example 7 with LegacyFragmentAdapter

use of com.haulmont.cuba.gui.components.compatibility.LegacyFragmentAdapter 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 8 with LegacyFragmentAdapter

use of com.haulmont.cuba.gui.components.compatibility.LegacyFragmentAdapter 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)

Example 9 with LegacyFragmentAdapter

use of com.haulmont.cuba.gui.components.compatibility.LegacyFragmentAdapter in project cuba by cuba-platform.

the class WebScreens method openFrame.

@SuppressWarnings({ "deprecation", "IncorrectCreateGuiComponent" })
@Override
public Frame openFrame(Frame parentFrame, com.haulmont.cuba.gui.components.Component parent, @Nullable String id, WindowInfo windowInfo, Map<String, Object> params) {
    ScreenFragment screenFragment;
    Fragments fragments = ui.getFragments();
    if (params != null && !params.isEmpty()) {
        screenFragment = fragments.create(parentFrame.getFrameOwner(), windowInfo.getId(), new MapScreenOptions(params));
    } else {
        screenFragment = fragments.create(parentFrame.getFrameOwner(), windowInfo.getId());
    }
    if (id != null) {
        screenFragment.getFragment().setId(id);
    }
    fragments.init(screenFragment);
    if (parent instanceof ComponentContainer) {
        ComponentContainer container = (ComponentContainer) parent;
        for (com.haulmont.cuba.gui.components.Component c : container.getComponents()) {
            if (c instanceof com.haulmont.cuba.gui.components.Component.Disposable) {
                com.haulmont.cuba.gui.components.Component.Disposable disposable = (com.haulmont.cuba.gui.components.Component.Disposable) c;
                if (!disposable.isDisposed()) {
                    disposable.dispose();
                }
            }
            container.remove(c);
        }
        container.add(screenFragment.getFragment());
    }
    if (screenFragment instanceof LegacyFragmentAdapter) {
        return ((LegacyFragmentAdapter) screenFragment).getRealScreen();
    }
    return screenFragment instanceof Frame ? (Frame) screenFragment : new ScreenFragmentWrapper(screenFragment);
}
Also used : Disposable(com.haulmont.cuba.gui.components.Component.Disposable) com.haulmont.cuba.gui.components(com.haulmont.cuba.gui.components) Disposable(com.haulmont.cuba.gui.components.Component.Disposable) com.haulmont.cuba.gui(com.haulmont.cuba.gui) LegacyFragmentAdapter(com.haulmont.cuba.gui.components.compatibility.LegacyFragmentAdapter)

Aggregations

LegacyFragmentAdapter (com.haulmont.cuba.gui.components.compatibility.LegacyFragmentAdapter)9 FrameOwner (com.haulmont.cuba.gui.screen.FrameOwner)6 Method (java.lang.reflect.Method)5 Component (com.haulmont.cuba.gui.components.Component)4 DevelopmentException (com.haulmont.cuba.core.global.DevelopmentException)2 GuiDevelopmentException (com.haulmont.cuba.gui.GuiDevelopmentException)2 Frame (com.haulmont.cuba.gui.components.Frame)2 ClientConfiguration (com.haulmont.cuba.client.ClientConfiguration)1 com.haulmont.cuba.gui (com.haulmont.cuba.gui)1 com.haulmont.cuba.gui.components (com.haulmont.cuba.gui.components)1 AbstractWindow (com.haulmont.cuba.gui.components.AbstractWindow)1 Disposable (com.haulmont.cuba.gui.components.Component.Disposable)1 Timer (com.haulmont.cuba.gui.components.Timer)1 DataSupplier (com.haulmont.cuba.gui.data.DataSupplier)1 Datasource (com.haulmont.cuba.gui.data.Datasource)1 ExportDisplay (com.haulmont.cuba.gui.export.ExportDisplay)1 DataLoader (com.haulmont.cuba.gui.model.DataLoader)1 ScreenData (com.haulmont.cuba.gui.model.ScreenData)1 ScreenFragment (com.haulmont.cuba.gui.screen.ScreenFragment)1 UiControllerUtils.getScreenData (com.haulmont.cuba.gui.screen.UiControllerUtils.getScreenData)1