/** * 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); }
@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; }
private Class<?> getCurrentPage() { if (navigation.getCurrentPage() != null) { return navigation.getCurrentPage().contentType(); } else { // Guaranteed to exist at compile-time. return navigation.getPagesByRole(DefaultPage.class).iterator().next().contentType(); } }
/** * 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()); } }
/** * 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."); } }
/** * 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); } }
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); }
@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; }
/** * 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); }
private Class<?> getCurrentPage() { if (navigation.getCurrentPage() != null) { return navigation.getCurrentPage().contentType(); } else { // Guaranteed to exist at compile-time. return navigation.getPagesByRole(DefaultPage.class).iterator().next().contentType(); } }
/** * 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 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); } }
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); }
@Override public void navigateBackOrHome() { // Guaranteed to exist at compile-time. final PageNode<?> defaultPageNode = navigation.getPagesByRole(DefaultPage.class).iterator().next(); navigateBackOrToPage(defaultPageNode.contentType()); }
/** * 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()); } }
@Override public void navigateBackOrHome() { // Guaranteed to exist at compile-time. final PageNode<?> defaultPageNode = navigation.getPagesByRole(DefaultPage.class).iterator().next(); navigateBackOrToPage(defaultPageNode.contentType()); }