use of com.haulmont.cuba.gui.screen.Screen in project cuba by cuba-platform.
the class ScreenNavigationHandler method createScreen.
protected Screen createScreen(NavigationState requestedState, String screenRoute, WindowInfo windowInfo, AppUI ui) {
Screen screen;
if (isEditor(windowInfo)) {
screen = createEditor(windowInfo, screenRoute, requestedState, ui);
} else {
OpenMode openMode = getScreenOpenMode(requestedState.getNestedRoute(), screenRoute, ui);
screen = ui.getScreens().create(windowInfo.getId(), openMode);
}
return screen;
}
use of com.haulmont.cuba.gui.screen.Screen in project cuba by cuba-platform.
the class ScreenNavigationHandler method createEditor.
protected Screen createEditor(WindowInfo windowInfo, String screenRoute, NavigationState requestedState, AppUI ui) {
Map<String, Object> options = createEditorScreenOptions(windowInfo, requestedState, ui);
if (MapUtils.isEmpty(options)) {
log.info("Unable to load entity for editor: '{}'. " + "Subscribe for 'UrlParamsChangedEvent' to obtain its serialized id", windowInfo.getId());
}
Screen editor;
OpenMode openMode = getScreenOpenMode(requestedState.getNestedRoute(), screenRoute, ui);
if (isLegacyScreen(windowInfo.getControllerClass())) {
editor = ui.getScreens().create(windowInfo.getId(), openMode, new MapScreenOptions(options));
} else {
editor = ui.getScreens().create(windowInfo.getId(), openMode);
}
if (MapUtils.isNotEmpty(options)) {
Entity entity = (Entity) options.get(WindowParams.ITEM.name());
// noinspection unchecked
((EditorScreen<Entity>) editor).setEntityToEdit(entity);
}
return editor;
}
use of com.haulmont.cuba.gui.screen.Screen in project cuba by cuba-platform.
the class ScreenNavigationHandler method openScreen.
protected void openScreen(NavigationState requestedState, String screenRoute, WindowInfo windowInfo, AppUI ui) {
UrlChangeHandler urlChangeHandler = ui.getUrlChangeHandler();
if (!urlChangeHandler.isPermittedToNavigate(requestedState, windowInfo)) {
return;
}
Screen screen = createScreen(requestedState, screenRoute, windowInfo, ui);
if (screen == null) {
log.info("Unable to open screen '{}' for requested route '{}'", windowInfo.getId(), requestedState.getNestedRoute());
urlChangeHandler.revertNavigationState();
return;
}
if (requestedState.getNestedRoute().endsWith(screenRoute)) {
Map<String, String> params = requestedState.getParams();
if (MapUtils.isNotEmpty(params)) {
UiControllerUtils.fireEvent(screen, UrlParamsChangedEvent.class, new UrlParamsChangedEvent(screen, params));
}
((WebWindow) screen.getWindow()).setResolvedState(requestedState);
} else {
((WebWindow) screen.getWindow()).setResolvedState(getNestedScreenState(screenRoute, requestedState));
}
screen.show();
}
use of com.haulmont.cuba.gui.screen.Screen in project cuba by cuba-platform.
the class ScreenNavigationHandler method doHandle.
@Override
public boolean doHandle(NavigationState requestedState, AppUI ui) {
UrlChangeHandler urlChangeHandler = ui.getUrlChangeHandler();
if (urlChangeHandler.isEmptyState(requestedState) || !isScreenChanged(requestedState, ui)) {
return false;
}
String requestedRoute = requestedState.getNestedRoute();
if (StringUtils.isEmpty(requestedRoute)) {
log.info("Unable to handle state with empty route '{}'", requestedState);
urlChangeHandler.revertNavigationState();
return true;
}
String[] routeParts = { requestedRoute };
if (windowConfig.findWindowInfoByRoute(requestedRoute) == null) {
routeParts = requestedRoute.split("/");
}
if (routeParts.length > MAX_SUB_ROUTES) {
log.info("Unable to perform navigation to requested state '{}'. Only {} sub routes are supported", requestedRoute, MAX_SUB_ROUTES);
urlChangeHandler.revertNavigationState();
return true;
}
List<Pair<String, WindowInfo>> routeWindowInfos = Arrays.stream(routeParts).map(subRoute -> new Pair<>(subRoute, windowConfig.findWindowInfoByRoute(subRoute))).collect(Collectors.toList());
for (Pair<String, WindowInfo> entry : routeWindowInfos) {
WindowInfo routeWindowInfo = entry.getSecond();
if (routeWindowInfo == null) {
log.info("No registered screen found for route: '{}'", entry.getFirst());
urlChangeHandler.revertNavigationState();
handle404(entry.getFirst(), ui);
return true;
}
if (urlChangeHandler.shouldRedirect(routeWindowInfo)) {
urlChangeHandler.redirect(requestedState);
return true;
}
if (urlChangeHandler.isRootRoute(routeWindowInfo)) {
log.info("Unable navigate to '{}' as nested screen", routeWindowInfo.getId());
urlChangeHandler.revertNavigationState();
return true;
}
}
return navigate(requestedState, ui, routeWindowInfos);
}
use of com.haulmont.cuba.gui.screen.Screen in project cuba by cuba-platform.
the class RootNavigationHandler method rootChanged.
protected boolean rootChanged(NavigationState requestedState, AppUI ui) {
Screen rootScreen = ui.getScreens().getOpenedScreens().getRootScreenOrNull();
if (rootScreen == null) {
return false;
}
String rootRoute = ((WebWindow) rootScreen.getWindow()).getResolvedState().getRoot();
return !StringUtils.equals(rootRoute, requestedState.getRoot());
}
Aggregations