Class PathPrefixNavGrouper

java.lang.Object
org.vaadin.addons.joelpop.appnavlayout.ui.nav.PathPrefixNavGrouper
All Implemented Interfaces:
NavGrouper

public final class PathPrefixNavGrouper extends Object implements NavGrouper
Default NavGrouper — derives the navigation hierarchy from route path segments, mirroring the structure of @Route paths.

Group metadata comes from a NavGroup resolver when set, falling back to humanised path segment labels. Leaf titles come from RouteNavUtils.leafTitle(MenuEntry). Leaf icons come from the configured viewIconGenerator (default: none). Path-based group nodes carry no icon; use a NavGroup resolver with NavGroup.icon() to assign icons to groups.

When a NavGroup resolver assigns a root group to any view, all views sharing the same first path segment are merged into that group automatically, even if they carry no annotation — provided all NavGroup-assigned views are processed by nodeFor(MenuEntry) before any path-based views are processed.

Group nodes are cached so the same NavNode instance is returned for the same group identity across multiple nodeFor(MenuEntry) calls. Group identity for a NavGroup resolver is its (parent, title()) pair, not the resolved NavGroup object itself — NavGroup declares no equals(), and a resolver that (as is natural) builds a fresh instance per call would otherwise never merge two siblings resolving to the same group.

  • Constructor Details

    • PathPrefixNavGrouper

      public PathPrefixNavGrouper()
  • Method Details

    • setNavGroupDefResolver

      public PathPrefixNavGrouper setNavGroupDefResolver(Function<com.vaadin.flow.server.menu.MenuEntry, NavGroup> resolver)
      Sets the resolver that maps a MenuEntry to its NavGroup; return null to use path-based grouping.
    • setViewIconGenerator

      public PathPrefixNavGrouper setViewIconGenerator(Function<com.vaadin.flow.server.menu.MenuEntry, Supplier<com.vaadin.flow.component.icon.Icon>> generator)
      Sets the icon generator for leaf nav nodes; default returns no icon.
    • reset

      public void reset()
      Description copied from interface: NavGrouper
      Clears any cached state so the next NavGrouper.nodeFor(MenuEntry) calls start fresh.
      Specified by:
      reset in interface NavGrouper
    • nodeFor

      public NavNode nodeFor(com.vaadin.flow.server.menu.MenuEntry entry)
      Description copied from interface: NavGrouper
      Returns the NavNode representing entry in the navigation tree. Set parent() on the returned node to encode group nesting; leave it absent for top-level items.

      Must be idempotent — see the class-level contract above.

      Specified by:
      nodeFor in interface NavGrouper