@Produces @ApplicationScoped public URLPatternMatcher createURLPatternMatcher(NavigationGraph navGraph) { URLPatternMatcher patternMatcher = new URLPatternMatcher(); Collection<PageNode<?>> pages = navGraph.getAllPages(); for(PageNode<?> page : pages) { patternMatcher.add(page.getURL(), page.name()); } if (!navGraph.isEmpty()) { PageNode<?> defaultPageNode = navGraph.getPageByRole(DefaultPage.class); patternMatcher.setAsDefaultPage(defaultPageNode.name()); } return patternMatcher; }
/** * Return all PageNode instances that have specified pageRole. * * @param pageRole * the role to find PageNodes by * @return All the pageNodes of the pages that have the specific pageRole. */ public Collection<PageNode<?>> getPagesByRole(final Class<? extends PageRole> pageRole) { return navGraph.getPagesByRole(pageRole); }
/** * Same as {@link #goTo(Class, Multimap)} but then with the page name. * * @param toPage * the name of the page node to lookup and display. */ public void goTo(final String toPage) { PageNode<?> toPageInstance = null; try { toPageInstance = navGraph.getPage(toPage); navigate(toPageInstance); } catch (final RedirectLoopException e) { throw e; } catch (final RuntimeException e) { navigationErrorHandler.handleInvalidPageNameError(e, toPage); } }
/** * Looks up the PageNode instance of the page that has the unique role set and makes the widget visible in the content * area. * * @param role * The unique role of the page that needs to be displayed. */ public void goToWithRole(final Class<? extends UniquePageRole> role) { PageNode<?> toPageInstance = null; try { toPageInstance = navGraph.getPageByRole(role); navigate(toPageInstance); } catch (final RedirectLoopException e) { throw e; } catch (final RuntimeException e) { navigationErrorHandler.handleError(e, role); } }
@PostConstruct private void init() { if (navGraph.isEmpty()) return;
/** * Same as {@link #goTo(Class, Multimap)} but then with the page name. * * @param toPage * the name of the page node to lookup and display. */ public void goTo(final String toPage) { PageNode<?> toPageInstance = null; try { toPageInstance = navGraph.getPage(toPage); navigate(toPageInstance); } catch (final RedirectLoopException e) { throw e; } catch (final RuntimeException e) { navigationErrorHandler.handleInvalidPageNameError(e, toPage); } }
/** * Looks up the PageNode instance of the page that has the unique role set and makes the widget visible in the content * area. * * @param role * The unique role of the page that needs to be displayed. */ public void goToWithRole(final Class<? extends UniquePageRole> role) { PageNode<?> toPageInstance = null; try { toPageInstance = navGraph.getPageByRole(role); navigate(toPageInstance); } catch (final RedirectLoopException e) { throw e; } catch (final RuntimeException e) { navigationErrorHandler.handleError(e, role); } }
@PostConstruct private void init() { if (navGraph.isEmpty()) return;
@Produces @ApplicationScoped public URLPatternMatcher createURLPatternMatcher(NavigationGraph navGraph) { URLPatternMatcher patternMatcher = new URLPatternMatcher(); Collection<PageNode<?>> pages = navGraph.getAllPages(); for(PageNode<?> page : pages) { patternMatcher.add(page.getURL(), page.name()); } if (!navGraph.isEmpty()) { PageNode<?> defaultPageNode = navGraph.getPageByRole(DefaultPage.class); patternMatcher.setAsDefaultPage(defaultPageNode.name()); } return patternMatcher; }
/** * Looks up the PageNode instance that provides content for the given widget type, sets the state on that page, then * makes the widget visible in the content area. * * @param toPage * The content type of the page node to look up and display. Normally, this is a Widget subclass that has * been annotated with {@code @Page}. * @param state * The state information to set on the page node before showing it. Normally the map keys correspond with the * names of fields annotated with {@code @PageState} in the widget class, but this is not required. */ public <C> void goTo(final Class<C> toPage, final Multimap<String, String> state) { PageNode<C> toPageInstance = null; try { toPageInstance = navGraph.getPage(toPage); navigate(toPageInstance, state); } catch (final RedirectLoopException e) { throw e; } catch (final RuntimeException e) { if (toPageInstance == null) // This is an extremely unlikely case, so throwing an exception is preferable to going through the navigation error handler. throw new PageNotFoundException("There is no page of type " + toPage.getName() + " in the navigation graph."); else navigationErrorHandler.handleInvalidPageNameError(e, toPageInstance.name()); } }
/** * Return all PageNode instances that have specified pageRole. * * @param pageRole * the role to find PageNodes by * @return All the pageNodes of the pages that have the specific pageRole. */ public Collection<PageNode<?>> getPagesByRole(final Class<? extends PageRole> pageRole) { return navGraph.getPagesByRole(pageRole); }
/** * Looks up the PageNode instance that provides content for the given widget type, sets the state on that page, then * makes the widget visible in the content area. * * @param toPage * The content type of the page node to look up and display. Normally, this is a Widget subclass that has * been annotated with {@code @Page}. * @param state * The state information to set on the page node before showing it. Normally the map keys correspond with the * names of fields annotated with {@code @PageState} in the widget class, but this is not required. */ public <C> void goTo(final Class<C> toPage, final Multimap<String, String> state) { PageNode<C> toPageInstance = null; try { toPageInstance = navGraph.getPage(toPage); navigate(toPageInstance, state); } catch (final RedirectLoopException e) { throw e; } catch (final RuntimeException e) { if (toPageInstance == null) // This is an extremely unlikely case, so throwing an exception is preferable to going through the navigation error handler. throw new PageNotFoundException("There is no page of type " + toPage.getName() + " in the navigation graph."); else navigationErrorHandler.handleInvalidPageNameError(e, toPageInstance.name()); } }
/** * 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); }
@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()); } } });