Class NavComponentBuilder<SELF extends NavComponentBuilder<SELF>>

java.lang.Object
com.foreach.across.modules.web.ui.ViewElementBuilderSupport<T,SELF>
com.foreach.across.modules.web.ui.elements.builder.ContainerViewElementBuilderSupport<T,SELF>
com.foreach.across.modules.web.ui.elements.builder.AbstractNodeViewElementBuilder<T,SELF>
com.foreach.across.modules.bootstrapui.elements.builder.AbstractHtmlSupportingNodeViewElementBuilder<T,SELF>
com.foreach.across.modules.bootstrapui.elements.builder.AbstractLinkSupportingNodeViewElementBuilder<com.foreach.across.modules.web.ui.elements.NodeViewElement,SELF>
com.foreach.across.modules.bootstrapui.components.builder.NavComponentBuilder<SELF>
All Implemented Interfaces:
com.foreach.across.modules.web.ui.elements.builder.HtmlViewElementBuilder<com.foreach.across.modules.web.ui.elements.NodeViewElement,SELF>, com.foreach.across.modules.web.ui.ViewElementBuilder<com.foreach.across.modules.web.ui.elements.NodeViewElement>
Direct Known Subclasses:
BreadcrumbNavComponentBuilder, DefaultNavComponentBuilder, PanelsNavComponentBuilder

public abstract class NavComponentBuilder<SELF extends NavComponentBuilder<SELF>> extends AbstractLinkSupportingNodeViewElementBuilder<com.foreach.across.modules.web.ui.elements.NodeViewElement,SELF>
Abstract base class for rendering Menu items to nav-like structures.
Since:
1.0.0
Author:
Arne Vandamme
See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static enum 
    Possible values for attribute ATTR_INSERT_SEPARATOR.

    Nested classes/interfaces inherited from class com.foreach.across.modules.web.ui.ViewElementBuilderSupport

    com.foreach.across.modules.web.ui.ViewElementBuilderSupport.ElementOrBuilder

    Nested classes/interfaces inherited from interface com.foreach.across.modules.web.ui.ViewElementBuilder

    com.foreach.across.modules.web.ui.ViewElementBuilder.Wither<T extends com.foreach.across.modules.web.ui.ViewElementBuilder>
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    If this attribute exists its value must be a ViewElement or ViewElementBuilder.
    static final String
    If set to true and the item has an ATTR_ICON attribute set, only the icon element will be rendered if the menu item is at the top level.
    static final String
    Can be set to a value of NavComponentBuilder.Separator.
    static final String
    Holds the custom ViewElement or ViewElementBuilder that should be used to render the list item for that Menu.
    static final String
    If set to true this group will always be rendered as a group (dropdown) even if there is only a single item.
    static final String
    If set to true the label for the group will never be replaced by the label of the selected item.
    static final String
    Holds the custom ViewElement or ViewElementBuilder that should be used to render the link inside the list item of that Menu.
    static final String
    Holds a ViewElement.WitherSetter that should be applied to the view element of an item.
    static final String
    If a custom ViewElementBuilder is being used for rendering (part of) a Menu, the ViewElementBuilderContext will contain the Menu being rendered as an attribute with this name.

    Fields inherited from class com.foreach.across.modules.web.ui.ViewElementBuilderSupport

    customTemplate, name
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    addHtmlAttributes(com.foreach.across.modules.web.ui.elements.AbstractNodeViewElement node, Map<String,Object> attributes)
    Deprecated.
    protected void
    addIconAndText(com.foreach.across.modules.web.ui.elements.AbstractNodeViewElement node, com.foreach.across.modules.web.menu.Menu item, String resolvedTitle, boolean iconAllowed, boolean iconOnly, com.foreach.across.modules.web.ui.ViewElementBuilderContext builderContext)
     
    protected LinkViewElement
    addItemLink(com.foreach.across.modules.web.ui.elements.NodeViewElement container, com.foreach.across.modules.web.menu.Menu item, boolean iconAllowed, boolean iconOnly, com.foreach.across.modules.web.ui.ViewElementBuilderContext builderContext)
     
    protected boolean
    addViewElementIfAttributeExists(com.foreach.across.modules.web.menu.Menu item, String attributeName, com.foreach.across.modules.web.ui.elements.ContainerViewElement container, com.foreach.across.modules.web.ui.ViewElementBuilderContext builderContext)
     
    protected abstract com.foreach.across.modules.web.ui.elements.NodeViewElement
    buildMenu(com.foreach.across.modules.web.menu.Menu menu, com.foreach.across.modules.web.ui.ViewElementBuilderContext builderContext)
     
    protected com.foreach.across.modules.web.ui.elements.NodeViewElement
    createElement(com.foreach.across.modules.web.ui.ViewElementBuilderContext builderContext)
     
    customizeViewElement(boolean replacePreviousRules, com.foreach.across.modules.web.ui.ViewElement.WitherSetter... setters)
    Create a registrar for the ATTR_VIEW_ELEMENT_WITHER attribute on a Menu item by combining the collection of setters into a single ViewElement.WitherSetter to be applied to the generated view element for the menu item.
    customizeViewElement(com.foreach.across.modules.web.ui.ViewElement.WitherSetter... setters)
    Create a registrar for the ATTR_VIEW_ELEMENT_WITHER attribute on a Menu item by combining the collection of setters into a single ViewElement.WitherSetter to be applied to the generated view element for the menu item.
    filter(@NonNull Predicate<com.foreach.across.modules.web.menu.Menu> predicate)
    Set a predicate that menu items should match before they will be rendered.
    protected com.foreach.across.modules.web.menu.Menu
    findFirstIncludedChild(com.foreach.across.modules.web.menu.Menu menu)
     
    protected com.foreach.across.modules.web.menu.Menu
    findItemToRender(com.foreach.across.modules.web.menu.Menu item)
     
    protected com.foreach.across.modules.web.menu.Menu
    getFirstNonGroupSelectedItem(com.foreach.across.modules.web.menu.Menu menu)
     
    static String
    htmlAttribute(String attributeName)
    Deprecated.
    protected com.foreach.across.modules.web.ui.ViewElement.WitherSetter<com.foreach.across.modules.web.ui.elements.AbstractNodeViewElement>
    htmlAttributesOf(com.foreach.across.modules.web.menu.Menu item)
    Deprecated.
    protected Stream<com.foreach.across.modules.web.menu.Menu>
    includedItems(com.foreach.across.modules.web.menu.Menu menu)
     
    includePathAsDataAttribute(boolean shouldInclude)
    Should the Menu.getPath() be included as data-ax-menu-path attribute on the list item.
    keepGroupsAsGroup(boolean keepGroupsAsGroup)
    Set to true if the behaviour for groups should be to keep them as group unless they have a ATTR_KEEP_AS_GROUP set.
    menu(com.foreach.across.modules.web.menu.Menu menu)
    Set the fixed menu to render.
    menu(String menuName)
    Set the name of the menu to render.
    protected int
    numberOfChildrenToInclude(com.foreach.across.modules.web.menu.Menu menu)
     
    protected boolean
    shouldIncludeItem(com.foreach.across.modules.web.menu.Menu item)
     
    protected boolean
    shouldKeepAsGroup(com.foreach.across.modules.web.menu.Menu item)
     
    protected com.foreach.across.modules.web.ui.ViewElement.WitherSetter
    witherAttribute(com.foreach.across.modules.web.menu.Menu itemToRender, com.foreach.across.modules.web.menu.Menu originalItem)
     

    Methods inherited from class com.foreach.across.modules.bootstrapui.elements.builder.AbstractLinkSupportingNodeViewElementBuilder

    buildLink, linkBuilder

    Methods inherited from class com.foreach.across.modules.bootstrapui.elements.builder.AbstractHtmlSupportingNodeViewElementBuilder

    escapeHtml, isEscapeHtml, resolveTextElement, toTextElement

    Methods inherited from class com.foreach.across.modules.web.ui.elements.builder.AbstractNodeViewElementBuilder

    apply, attribute, attributes, clearAttributes, css, htmlId, removeAttribute, removeCss

    Methods inherited from class com.foreach.across.modules.web.ui.elements.builder.ContainerViewElementBuilderSupport

    add, add, addAll, addFirst, addFirst, sort

    Methods inherited from class com.foreach.across.modules.web.ui.ViewElementBuilderSupport

    build, configure, customTemplate, elementSupplier, elementSupplier, name, postProcess, postProcessor, registerWebResources, with

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface com.foreach.across.modules.web.ui.elements.builder.HtmlViewElementBuilder

    data, removeData

    Methods inherited from interface com.foreach.across.modules.web.ui.ViewElementBuilder

    andThen, build, doWith, map, map, postProcess, postProcess
  • Field Details

    • ATTR_ICON

      public static final String ATTR_ICON
      If this attribute exists its value must be a ViewElement or ViewElementBuilder. If so the resulting ViewElement will be added before the item text.
      See Also:
    • ATTR_ICON_ONLY

      public static final String ATTR_ICON_ONLY
      If set to true and the item has an ATTR_ICON attribute set, only the icon element will be rendered if the menu item is at the top level. This attribute will be inherited from the group.

      Note that the actual title will still be added wrapped in a span with class nav-item-title. This supports for example collapsing navbars where the title should be visible anyway.

      See Also:
    • ATTR_ITEM_VIEW_ELEMENT

      public static final String ATTR_ITEM_VIEW_ELEMENT
      Holds the custom ViewElement or ViewElementBuilder that should be used to render the list item for that Menu. The custom element should take care of all possible child menu items.
      See Also:
    • ATTR_VIEW_ELEMENT_WITHER

      public static final String ATTR_VIEW_ELEMENT_WITHER
      Holds a ViewElement.WitherSetter that should be applied to the view element of an item. Which element will be the target depends on the component builder and item.
      See Also:
    • ATTR_KEEP_AS_GROUP

      public static final String ATTR_KEEP_AS_GROUP
      If set to true this group will always be rendered as a group (dropdown) even if there is only a single item. The default behaviour would be to then just render that item.
      See Also:
    • ATTR_KEEP_GROUP_ITEM

      public static final String ATTR_KEEP_GROUP_ITEM
      If set to true the label for the group will never be replaced by the label of the selected item. This attribute is only relevant if the builder is @ DefaultNavComponentBuilder configured with DefaultNavComponentBuilder.replaceGroupBySelectedItem().
      See Also:
    • ATTR_INSERT_SEPARATOR

      public static final String ATTR_INSERT_SEPARATOR
      Can be set to a value of NavComponentBuilder.Separator. Determines where a separator should be added if the item is rendered in a dropdown.
      See Also:
    • CTX_CURRENT_MENU_ITEM

      public static final String CTX_CURRENT_MENU_ITEM
      If a custom ViewElementBuilder is being used for rendering (part of) a Menu, the ViewElementBuilderContext will contain the Menu being rendered as an attribute with this name.
      See Also:
  • Constructor Details

    • NavComponentBuilder

      public NavComponentBuilder()
  • Method Details

    • includePathAsDataAttribute

      public SELF includePathAsDataAttribute(boolean shouldInclude)
      Should the Menu.getPath() be included as data-ax-menu-path attribute on the list item.
      Parameters:
      shouldInclude - true if data attribute should be set
      Returns:
      current builder
    • filter

      public SELF filter(@NonNull @NonNull Predicate<com.foreach.across.modules.web.menu.Menu> predicate)
      Set a predicate that menu items should match before they will be rendered. By default all menu items will match.
      Parameters:
      predicate - to match
      Returns:
      current builder
    • keepGroupsAsGroup

      public SELF keepGroupsAsGroup(boolean keepGroupsAsGroup)
      Set to true if the behaviour for groups should be to keep them as group unless they have a ATTR_KEEP_AS_GROUP set. Default is not to keep them as group but to replace them by the item if there is only one.
      Returns:
      current builder
    • createElement

      protected com.foreach.across.modules.web.ui.elements.NodeViewElement createElement(com.foreach.across.modules.web.ui.ViewElementBuilderContext builderContext)
      Specified by:
      createElement in class com.foreach.across.modules.web.ui.ViewElementBuilderSupport<com.foreach.across.modules.web.ui.elements.NodeViewElement,SELF extends NavComponentBuilder<SELF>>
    • buildMenu

      protected abstract com.foreach.across.modules.web.ui.elements.NodeViewElement buildMenu(com.foreach.across.modules.web.menu.Menu menu, com.foreach.across.modules.web.ui.ViewElementBuilderContext builderContext)
    • includedItems

      protected Stream<com.foreach.across.modules.web.menu.Menu> includedItems(com.foreach.across.modules.web.menu.Menu menu)
    • shouldIncludeItem

      protected boolean shouldIncludeItem(com.foreach.across.modules.web.menu.Menu item)
    • findItemToRender

      protected com.foreach.across.modules.web.menu.Menu findItemToRender(com.foreach.across.modules.web.menu.Menu item)
    • findFirstIncludedChild

      protected com.foreach.across.modules.web.menu.Menu findFirstIncludedChild(com.foreach.across.modules.web.menu.Menu menu)
    • htmlAttributesOf

      @Deprecated protected com.foreach.across.modules.web.ui.ViewElement.WitherSetter<com.foreach.across.modules.web.ui.elements.AbstractNodeViewElement> htmlAttributesOf(com.foreach.across.modules.web.menu.Menu item)
      Deprecated.
    • addHtmlAttributes

      @Deprecated protected void addHtmlAttributes(com.foreach.across.modules.web.ui.elements.AbstractNodeViewElement node, Map<String,Object> attributes)
      Deprecated.
    • shouldKeepAsGroup

      protected boolean shouldKeepAsGroup(com.foreach.across.modules.web.menu.Menu item)
    • getFirstNonGroupSelectedItem

      protected com.foreach.across.modules.web.menu.Menu getFirstNonGroupSelectedItem(com.foreach.across.modules.web.menu.Menu menu)
    • addItemLink

      protected LinkViewElement addItemLink(com.foreach.across.modules.web.ui.elements.NodeViewElement container, com.foreach.across.modules.web.menu.Menu item, boolean iconAllowed, boolean iconOnly, com.foreach.across.modules.web.ui.ViewElementBuilderContext builderContext)
    • addIconAndText

      protected void addIconAndText(com.foreach.across.modules.web.ui.elements.AbstractNodeViewElement node, com.foreach.across.modules.web.menu.Menu item, String resolvedTitle, boolean iconAllowed, boolean iconOnly, com.foreach.across.modules.web.ui.ViewElementBuilderContext builderContext)
    • addViewElementIfAttributeExists

      protected boolean addViewElementIfAttributeExists(com.foreach.across.modules.web.menu.Menu item, String attributeName, com.foreach.across.modules.web.ui.elements.ContainerViewElement container, com.foreach.across.modules.web.ui.ViewElementBuilderContext builderContext)
      Returns:
      true if an element was added
    • numberOfChildrenToInclude

      protected int numberOfChildrenToInclude(com.foreach.across.modules.web.menu.Menu menu)
    • witherAttribute

      protected com.foreach.across.modules.web.ui.ViewElement.WitherSetter witherAttribute(com.foreach.across.modules.web.menu.Menu itemToRender, com.foreach.across.modules.web.menu.Menu originalItem)
    • htmlAttribute

      @Deprecated public static String htmlAttribute(String attributeName)
      Deprecated.
      Turns this regular attribute name into a HTML attribute name for a Menu attribute by adding the right prefix.
      Parameters:
      attributeName - to convert
      Returns:
      attribute name for HTML attribute
    • customizeViewElement

      public static Consumer<Map<String,Object>> customizeViewElement(com.foreach.across.modules.web.ui.ViewElement.WitherSetter... setters)
      Create a registrar for the ATTR_VIEW_ELEMENT_WITHER attribute on a Menu item by combining the collection of setters into a single ViewElement.WitherSetter to be applied to the generated view element for the menu item. A previously configured value will be kept and the new setters will be executed after. If you want to replace any previously configured setters, use customizeViewElement(boolean, ViewElement.WitherSetter[]).
      Parameters:
      setters - to add when processing the view element
      Returns:
      attribute registrar
    • customizeViewElement

      public static Consumer<Map<String,Object>> customizeViewElement(boolean replacePreviousRules, com.foreach.across.modules.web.ui.ViewElement.WitherSetter... setters)
      Create a registrar for the ATTR_VIEW_ELEMENT_WITHER attribute on a Menu item by combining the collection of setters into a single ViewElement.WitherSetter to be applied to the generated view element for the menu item. Depending on the replacePreviousRules argument, the setters will be appended to or replace a previously configured value.
      Parameters:
      replacePreviousRules - true if any previous value should be ignored
      setters - to add when processing the view element
      Returns:
      attribute registrar