use of com.haulmont.cuba.web.sys.navigation.UrlChangeHandler in project cuba by cuba-platform.
the class AppUI method setApplicationContext.
@Inject
protected void setApplicationContext(ApplicationContext applicationContext) {
Dialogs dialogs = new WebDialogs(this);
autowireContext(dialogs, applicationContext);
setDialogs(dialogs);
Notifications notifications = new WebNotifications(this);
autowireContext(notifications, applicationContext);
setNotifications(notifications);
WebBrowserTools webBrowserTools = new WebBrowserToolsImpl(this);
autowireContext(webBrowserTools, applicationContext);
setWebBrowserTools(webBrowserTools);
Fragments fragments = new WebFragments(this);
autowireContext(fragments, applicationContext);
setFragments(fragments);
Screens screens = new WebScreens(this);
autowireContext(screens, applicationContext);
setScreens(screens);
UrlRouting urlRouting = new WebUrlRouting(this);
autowireContext(urlRouting, applicationContext);
setUrlRouting(urlRouting);
History history = new WebHistory(this);
autowireContext(history, applicationContext);
setHistory(history);
UrlChangeHandler urlChangeHandler = new UrlChangeHandler(this);
autowireContext(urlChangeHandler, applicationContext);
setUrlChangeHandler(urlChangeHandler);
getPage().addPopStateListener(urlChangeHandler::handleUrlChange);
}
use of com.haulmont.cuba.web.sys.navigation.UrlChangeHandler in project cuba by cuba-platform.
the class ScreenNavigationHandler method isScreenChanged.
protected boolean isScreenChanged(NavigationState requestedState, AppUI ui) {
UrlChangeHandler urlChangeHandler = ui.getUrlChangeHandler();
if (urlChangeHandler.isEmptyState(requestedState) || urlChangeHandler.isRootState(requestedState)) {
return false;
}
Screen currentScreen = urlChangeHandler.findActiveScreenByState(ui.getHistory().getNow());
if (currentScreen == null) {
Iterator<Screen> screensIterator = ui.getScreens().getOpenedScreens().getCurrentBreadcrumbs().iterator();
currentScreen = screensIterator.hasNext() ? screensIterator.next() : null;
if (currentScreen == null) {
return true;
}
}
NavigationState currentState = urlChangeHandler.getResolvedState(currentScreen);
if (currentState == null) {
return true;
}
return !Objects.equals(currentState.getStateMark(), requestedState.getStateMark()) || !Objects.equals(currentState.getNestedRoute(), requestedState.getNestedRoute());
}
use of com.haulmont.cuba.web.sys.navigation.UrlChangeHandler in project cuba by cuba-platform.
the class ScreenNavigationHandler method createEditorScreenOptions.
@Nullable
protected Map<String, Object> createEditorScreenOptions(WindowInfo windowInfo, NavigationState requestedState, AppUI ui) {
UrlChangeHandler urlChangeHandler = ui.getUrlChangeHandler();
String idParam = MapUtils.isNotEmpty(requestedState.getParams()) ? requestedState.getParams().get("id") : NEW_ENTITY_ID;
Class<? extends Entity> entityClass = EditorTypeExtractor.extractEntityClass(windowInfo);
if (entityClass == null) {
return null;
}
MetaClass metaClass = metadata.getClassNN(entityClass);
if (!security.isEntityOpPermitted(metaClass, EntityOp.READ)) {
urlChangeHandler.revertNavigationState();
throw new AccessDeniedException(PermissionType.ENTITY_OP, EntityOp.READ, entityClass.getSimpleName());
}
if (NEW_ENTITY_ID.equals(idParam)) {
boolean createPermitted = security.isEntityOpPermitted(metaClass, EntityOp.CREATE);
if (!createPermitted) {
throw new AccessDeniedException(PermissionType.ENTITY_OP, EntityOp.CREATE, entityClass.getSimpleName());
}
return ParamsMap.of(WindowParams.ITEM.name(), metadata.create(entityClass));
}
MetaProperty primaryKeyProperty = metadataTools.getPrimaryKeyProperty(metaClass);
if (primaryKeyProperty == null) {
throw new IllegalStateException(String.format("Entity %s has no primary key", metaClass.getName()));
}
Class<?> idType = primaryKeyProperty.getJavaType();
Object id = UrlIdSerializer.deserializeId(idType, idParam);
LoadContext<?> ctx = new LoadContext(metaClass);
ctx.setId(id);
ctx.setView(View.MINIMAL);
Entity entity = dataManager.load(ctx);
if (entity == null) {
urlChangeHandler.revertNavigationState();
throw new EntityAccessException(metaClass, id);
}
return ParamsMap.of(WindowParams.ITEM.name(), entity);
}
use of com.haulmont.cuba.web.sys.navigation.UrlChangeHandler 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.web.sys.navigation.UrlChangeHandler 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);
}
Aggregations