use of com.haulmont.cuba.gui.screen.ScreenFragment 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;
}
use of com.haulmont.cuba.gui.screen.ScreenFragment in project cuba by cuba-platform.
the class WebSuggestionField method showSuggestions.
protected void showSuggestions(List<V> suggestions, boolean userOriginated) {
FrameOwner frameOwner = getFrame().getFrameOwner();
Collection<Screen> dialogScreens = UiControllerUtils.getScreenContext(frameOwner).getScreens().getOpenedScreens().getDialogScreens();
Screen lastDialog = null;
for (Screen dialogScreen : dialogScreens) {
lastDialog = dialogScreen;
}
if (frameOwner instanceof ScreenFragment) {
frameOwner = ComponentsHelper.getScreen((ScreenFragment) frameOwner);
}
if (lastDialog == null || Objects.equals(frameOwner, lastDialog)) {
component.showSuggestions(suggestions, userOriginated);
}
}
use of com.haulmont.cuba.gui.screen.ScreenFragment in project cuba by cuba-platform.
the class UiControllerPropertyInjector method findDatasource.
@Nullable
protected Datasource findDatasource(String datasourceId) {
Datasource datasource = null;
if (sourceScreen instanceof LegacyFrame) {
((LegacyFrame) sourceScreen).getDsContext().get(datasourceId);
}
FrameOwner frameOwner = this.frameOwner instanceof ScreenFragment ? ((ScreenFragment) this.frameOwner).getHostController() : this.frameOwner;
if (frameOwner instanceof LegacyFrame) {
datasource = ((LegacyFrame) frameOwner).getDsContext().get(datasourceId);
}
return datasource;
}
use of com.haulmont.cuba.gui.screen.ScreenFragment in project cuba by cuba-platform.
the class UiControllerPropertyInjector method findComponent.
@Nullable
protected Component findComponent(String componentId) {
Component component = null;
Window window = null;
if (sourceScreen != null) {
window = sourceScreen.getWindow();
} else if (frameOwner instanceof ScreenFragment) {
FrameOwner host = ((ScreenFragment) frameOwner).getHostController();
if (host instanceof Screen) {
window = ((Screen) host).getWindow();
}
} else if (frameOwner instanceof Screen) {
window = ((Screen) frameOwner).getWindow();
}
if (window != null) {
component = window.getComponent(componentId);
}
return component;
}
use of com.haulmont.cuba.gui.screen.ScreenFragment in project cuba by cuba-platform.
the class WebSuggestionPickerField method showSuggestions.
protected void showSuggestions(List<V> suggestions, boolean userOriginated) {
FrameOwner frameOwner = getFrame().getFrameOwner();
Collection<Screen> dialogScreens = UiControllerUtils.getScreenContext(frameOwner).getScreens().getOpenedScreens().getDialogScreens();
Screen lastDialog = null;
for (Screen dialogScreen : dialogScreens) {
lastDialog = dialogScreen;
}
if (frameOwner instanceof ScreenFragment) {
frameOwner = ComponentsHelper.getScreen((ScreenFragment) frameOwner);
}
if (lastDialog == null || Objects.equals(frameOwner, lastDialog)) {
getComponent().showSuggestions(suggestions, userOriginated);
}
}
Aggregations