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;
}
Aggregations