/** * This can be used to create a HistoryToken when navigating by page name. * * @param pageName * The name of the page. Never null. * @param state * The map of {@link PageState} keys and values. Never null. * @return A HistoryToken with the parsed URL matching information. */ public HistoryToken createHistoryToken(String pageName, Multimap<String, String> state) { URLPattern pattern = patternMatcher.getURLPattern(pageName); return new HistoryToken(pageName, ImmutableMultimap.copyOf(state), pattern); }
/** * @return The state multimap used to show the currently displayed page. If a navigation request has been submitted * this may return the state of page being navigated to before that page has actually been displayed. */ public Multimap<String, String> getCurrentState() { return (currentPageToken != null) ? currentPageToken.getState() : ImmutableMultimap.of(); }
private <C> void handleQueuedRequests(final Request<C> request, final boolean fireEvent) { if (queuedRequests.isEmpty()) { // No new navigation requests were recorded in the lifecycle methods. // This is the page which has to be displayed and the browser's history // can be updated. redirectDepth = 0; HistoryWrapper.newItem(request.state.toString(), fireEvent); } else { // Process all navigation requests captured in the lifecycle methods. while (queuedRequests.size() != 0) { navigate(queuedRequests.poll(), fireEvent); } } }
@Override public void onValueChange(final ValueChangeEvent<String> event) { HistoryToken token = null; try { logger.debug("URL value changed to " + event.getValue()); if (needsApplicationContext()) { final String context = inferAppContext(event.getValue()); logger.info("No application context defined. Inferring application context as " + context + ". Change this value by setting the variable \"erraiApplicationWebContext\" in your GWT host page" + ", or calling Navigation.setAppContext."); setAppContext(context); } token = historyTokenFactory.parseURL(event.getValue()); if (currentPage == null || !token.equals(currentPageToken)) { final PageNode<IsWidget> toPage = navGraph.getPage(token.getPageName()); navigate(new Request<>(toPage, token), false); } } catch (final Exception e) { if (token == null) navigationErrorHandler.handleInvalidURLError(e, event.getValue()); else navigationErrorHandler.handleInvalidPageNameError(e, token.getPageName()); } } });
@Override public void onValueChange(final ValueChangeEvent<String> event) { HistoryToken token = null; try { logger.debug("URL value changed to " + event.getValue()); if (needsApplicationContext()) { final String context = inferAppContext(event.getValue()); logger.info("No application context defined. Inferring application context as " + context + ". Change this value by setting the variable \"erraiApplicationWebContext\" in your GWT host page" + ", or calling Navigation.setAppContext."); setAppContext(context); } token = historyTokenFactory.parseURL(event.getValue()); if (currentPage == null || !token.equals(currentPageToken)) { final PageNode<IsWidget> toPage = navGraph.getPage(token.getPageName()); navigate(new Request<>(toPage, token), false); } } catch (final Exception e) { if (token == null) navigationErrorHandler.handleInvalidURLError(e, event.getValue()); else navigationErrorHandler.handleInvalidPageNameError(e, token.getPageName()); } } });
private <C> void handleQueuedRequests(final Request<C> request, final boolean fireEvent) { if (queuedRequests.isEmpty()) { // No new navigation requests were recorded in the lifecycle methods. // This is the page which has to be displayed and the browser's history // can be updated. redirectDepth = 0; HistoryWrapper.newItem(request.state.toString(), fireEvent); } else { // Process all navigation requests captured in the lifecycle methods. while (queuedRequests.size() != 0) { navigate(queuedRequests.poll(), fireEvent); } } }
/** * This can be used to create a HistoryToken when navigating by page name. * * @param pageName * The name of the page. Never null. * @param state * The map of {@link PageState} keys and values. Never null. * @return A HistoryToken with the parsed URL matching information. */ public HistoryToken createHistoryToken(String pageName, Multimap<String, String> state) { URLPattern pattern = patternMatcher.getURLPattern(pageName); return new HistoryToken(pageName, ImmutableMultimap.copyOf(state), pattern); }
/** * @return The state multimap used to show the currently displayed page. If a navigation request has been submitted * this may return the state of page being navigated to before that page has actually been displayed. */ public Multimap<String, String> getCurrentState() { return (currentPageToken != null) ? currentPageToken.getState() : ImmutableMultimap.of(); }
/** * Update the state of your existing page without performing a full navigation. * <br/> * This will perform a pseudo navigation updating the history token with the new states. */ public void updateState(Multimap<String, String> state) { if(currentPage != null) { currentPageToken = historyTokenFactory.createHistoryToken(currentPage.name(), state); HistoryWrapper.newItem(currentPageToken.toString(), false); currentPage.pageUpdate(currentComponent, currentPageToken); } else { logger.error("Cannot update the state before a page has loaded."); } }
return new HistoryToken(pageName, ImmutableMultimap.copyOf(state), getURLPattern(pageName));
private <C> void navigate(final PageNode<C> toPageInstance, final Multimap<String, String> state) { final HistoryToken token = historyTokenFactory.createHistoryToken(toPageInstance.name(), state); logger.debug("Navigating to " + toPageInstance.name() + " at url: " + token.toString()); navigate(new Request<>(toPageInstance, token), true); }
return new HistoryToken(pageName, ImmutableMultimap.copyOf(state), getURLPattern(pageName));
/** * Update the state of your existing page without performing a full navigation. * <br/> * This will perform a pseudo navigation updating the history token with the new states. */ public void updateState(Multimap<String, String> state) { if(currentPage != null) { currentPageToken = historyTokenFactory.createHistoryToken(currentPage.name(), state); HistoryWrapper.newItem(currentPageToken.toString(), false); currentPage.pageUpdate(currentComponent, currentPageToken); } else { logger.error("Cannot update the state before a page has loaded."); } }
private <C> void navigate(final PageNode<C> toPageInstance, final Multimap<String, String> state) { final HistoryToken token = historyTokenFactory.createHistoryToken(toPageInstance.name(), state); logger.debug("Navigating to " + toPageInstance.name() + " at url: " + token.toString()); navigate(new Request<>(toPageInstance, token), true); }
/** * Initialize the anchor's href attribute. * * @param toPage * The page type this transition goes to. Not null. * @param state * The page state. Cannot be null (but can be an empty multimap) */ private void initHref(Class<P> toPage, Multimap<String, String> state) { PageNode<P> toPageInstance = navigation.getNavGraph().getPage(toPage); HistoryToken token = htFactory.createHistoryToken(toPageInstance.name(), state); String href = "#" + token.toString(); setHref(href); }
/** * Initialize the anchor's href attribute. * * @param toPage * The page type this transition goes to. Not null. * @param state * The page state. Cannot be null (but can be an empty multimap) */ private void initHref(Class<P> toPage, Multimap<String, String> state) { PageNode<P> toPageInstance = navigation.getNavGraph().getPage(toPage); HistoryToken token = htFactory.createHistoryToken(toPageInstance.name(), state); String href = "#" + token.toString(); setHref(href); }