Search in sources :

Example 1 with AbstractWindow

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

the class FragmentHelper method createController.

@SuppressWarnings("unchecked")
public ScreenFragment createController(WindowInfo windowInfo, Fragment fragment) {
    Class screenClass = windowInfo.getControllerClass();
    if (AbstractWindow.class.isAssignableFrom(screenClass)) {
        AbstractWindow legacyScreen;
        try {
            legacyScreen = (AbstractWindow) invokeConstructor(screenClass);
        } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | InstantiationException e) {
            throw new DevelopmentException("Unable to create " + screenClass);
        }
        LegacyFragmentAdapter adapter = new LegacyFragmentAdapter(legacyScreen);
        legacyScreen.setFrame(fragment);
        adapter.setWrappedFrame(fragment);
        log.warn("Fragment class '{}' should not be inherited from AbstractWindow. " + "It may cause problems with controller life cycle. " + "Fragment controllers should inherit ScreenFragment.", screenClass.getSimpleName());
        return adapter;
    }
    // new screens cannot be opened in fragments
    if (!ScreenFragment.class.isAssignableFrom(screenClass)) {
        throw new IllegalStateException(String.format("Fragment controllers should inherit ScreenFragment." + " UI controller is not ScreenFragment - %s %s", windowInfo.toString(), screenClass.getSimpleName()));
    }
    ScreenFragment controller;
    try {
        controller = (ScreenFragment) invokeConstructor(screenClass);
    } catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException e) {
        throw new RuntimeException("Unable to create instance of screen class " + screenClass);
    }
    return controller;
}
Also used : InvocationTargetException(java.lang.reflect.InvocationTargetException) DevelopmentException(com.haulmont.cuba.core.global.DevelopmentException) AbstractWindow(com.haulmont.cuba.gui.components.AbstractWindow) ScreenFragment(com.haulmont.cuba.gui.screen.ScreenFragment) LegacyFragmentAdapter(com.haulmont.cuba.gui.components.compatibility.LegacyFragmentAdapter)

Aggregations

DevelopmentException (com.haulmont.cuba.core.global.DevelopmentException)1 AbstractWindow (com.haulmont.cuba.gui.components.AbstractWindow)1 LegacyFragmentAdapter (com.haulmont.cuba.gui.components.compatibility.LegacyFragmentAdapter)1 ScreenFragment (com.haulmont.cuba.gui.screen.ScreenFragment)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1