use of com.vaadin.flow.router.LocationChangeEvent in project flow by vaadin.
the class AbstractNavigationStateRenderer method handle.
@Override
public int handle(NavigationEvent event) {
UI ui = event.getUI();
Class<? extends Component> routeTargetType = navigationState.getNavigationTarget();
List<Class<? extends RouterLayout>> routeLayoutTypes = getRouterLayoutTypes(routeTargetType);
assert routeTargetType != null;
assert routeLayoutTypes != null;
clearContinueNavigationAction(ui);
RouterUtil.checkForDuplicates(routeTargetType, routeLayoutTypes);
if (eventActionsSupported()) {
BeforeLeaveEvent beforeNavigationDeactivating = new BeforeLeaveEvent(event, routeTargetType);
Deque<BeforeLeaveHandler> leaveHandlers;
if (postponed != null) {
leaveHandlers = postponed.getLeaveObservers();
if (!leaveHandlers.isEmpty()) {
postponed = null;
}
} else {
List<BeforeLeaveHandler> beforeLeaveHandlers = new ArrayList<>(ui.getNavigationListeners(BeforeLeaveHandler.class));
beforeLeaveHandlers.addAll(EventUtil.collectBeforeLeaveObservers(ui.getElement()));
leaveHandlers = new ArrayDeque<>(beforeLeaveHandlers);
}
TransitionOutcome transitionOutcome = executeBeforeLeaveNavigation(beforeNavigationDeactivating, leaveHandlers);
if (transitionOutcome == TransitionOutcome.REROUTED) {
return reroute(event, beforeNavigationDeactivating);
} else if (transitionOutcome == TransitionOutcome.POSTPONED) {
ContinueNavigationAction currentAction = beforeNavigationDeactivating.getContinueNavigationAction();
currentAction.setReferences(this, event);
storeContinueNavigationAction(ui, currentAction);
return HttpServletResponse.SC_OK;
}
}
Component componentInstance = getRouteTarget(routeTargetType, event);
List<HasElement> chain = new ArrayList<>();
chain.add(componentInstance);
for (Class<? extends RouterLayout> parentType : routeLayoutTypes) {
chain.add(getRouteTarget(parentType, event));
}
BeforeEnterEvent beforeNavigationActivating = new BeforeEnterEvent(event, routeTargetType);
LocationChangeEvent locationChangeEvent = RouterUtil.createEvent(event, chain);
notifyNavigationTarget(componentInstance, event, beforeNavigationActivating, locationChangeEvent);
if (beforeNavigationActivating.hasRerouteTarget()) {
return reroute(event, beforeNavigationActivating);
}
@SuppressWarnings("unchecked") List<RouterLayout> routerLayouts = (List<RouterLayout>) (List<?>) chain.subList(1, chain.size());
List<BeforeEnterHandler> enterHandlers = new ArrayList<>(ui.getNavigationListeners(BeforeEnterHandler.class));
enterHandlers.addAll(EventUtil.collectEnterObservers(componentInstance, routerLayouts));
TransitionOutcome transitionOutcome = executeBeforeEnterNavigation(beforeNavigationActivating, enterHandlers);
if (eventActionsSupported() && TransitionOutcome.REROUTED.equals(transitionOutcome)) {
return reroute(event, beforeNavigationActivating);
}
ui.getInternals().showRouteTarget(event.getLocation(), navigationState.getResolvedPath(), componentInstance, routerLayouts);
RouterUtil.updatePageTitle(event, componentInstance);
int statusCode = locationChangeEvent.getStatusCode();
validateStatusCode(statusCode, routeTargetType);
List<AfterNavigationHandler> afterNavigationHandlers = new ArrayList<>(ui.getNavigationListeners(AfterNavigationHandler.class));
afterNavigationHandlers.addAll(EventUtil.collectAfterNavigationObservers(componentInstance, routerLayouts));
fireAfterNavigationListeners(new AfterNavigationEvent(locationChangeEvent), afterNavigationHandlers);
return statusCode;
}
Aggregations