Class BuildMenuEvent<T extends Menu>

java.lang.Object
com.foreach.across.modules.web.events.BuildMenuEvent<T>
Type Parameters:
T - Specific Menu implementation
All Implemented Interfaces:
AcrossEvent, NamedAcrossEvent, org.springframework.core.ResolvableTypeProvider

public class BuildMenuEvent<T extends Menu> extends Object implements NamedAcrossEvent, org.springframework.core.ResolvableTypeProvider
Event fired by the MenuFactory whenever a menu is being generated. After menu generation, a menu will be sorted and the selector applied. Customizing the menu is usually done through the PathBasedMenuBuilder, updating a Menu after generation can be done by adding a post-processor. Post-processors will receive the generated, sorted menu with active items selected using the configured MenuSelector.
See Also:
  • Constructor Details

    • BuildMenuEvent

      public BuildMenuEvent(T menu)
    • BuildMenuEvent

      public BuildMenuEvent(T menu, PathBasedMenuBuilder menuBuilder)
    • BuildMenuEvent

      public BuildMenuEvent(@NonNull T menu, @NonNull @NonNull PathBasedMenuBuilder menuBuilder, @NonNull @NonNull org.springframework.core.ResolvableType menuResolvableType)
  • Method Details

    • getResolvableType

      public org.springframework.core.ResolvableType getResolvableType()
      Specified by:
      getResolvableType in interface org.springframework.core.ResolvableTypeProvider
    • getEventName

      public String getEventName()
      Name for this event, same as the menu name.
      Specified by:
      getEventName in interface NamedAcrossEvent
      Returns:
      event name
    • getMenuName

      public String getMenuName()
      Name of the menu being built.
      Returns:
      menu name
    • getMenuSelector

      public MenuSelector getMenuSelector()
      Retrieve the menu selector that is attached to this event. A menu selector is optional, but when one is present it is expected to be used to select the Menu item that is active. This is especially useful in a web request scenario where a single menu item represents the location of the current user web request.

      You can manually set the menu selector that the MenuFactory should use with setMenuSelector(MenuSelector).

      Returns:
      the MenuSelector attached to this event
      See Also:
    • setMenuSelector

      public void setMenuSelector(MenuSelector menuSelector)
      Set the MenuSelector that should be used for selecting the active items, after the Menu has been built by the MenuFactory. But before any of the post processors are called.
      Parameters:
      menuSelector - that will be used
    • isForMenuOfType

      public boolean isForMenuOfType(@NonNull @NonNull Class<? extends Menu> menuClass)
      Check if the current build event is for a menu of the given type.
      Parameters:
      menuClass - expected type of menu
      Returns:
      true if menu is of that type
    • item

      Retrieve the item builder for a specific path. If there is none yet, one will be created.

      Short-hand for builder().item(path).

      Parameters:
      path - identifying the item
      Returns:
      item builder
    • group

      Retrieve the item builder for a specific path, where the item should represent a group of items. If there is no item builder yet, one will be created. If the item builder exists, but is not yet flagged as a group, it will be turned into a group.

      Note that flagging an item as a group simply sets the appropriate property. It has no effect on the actual Menu hierarchy being built and the fact that this item might serve as a parent for others. The latter is purely determined by the path splitting when building the menu.

      Short-hand for builder().group(path).

      Parameters:
      path - identifying the item
      Returns:
      item builder
    • optionalItem

      public final PathBasedMenuBuilder.PathBasedMenuItemBuilder optionalItem(String path)
      Return an item builder for updating an item if it exists. This will always return a valid item builder, but nothing will happen if that item did not exist before.

      Short-hand for builder().optionalItem(path).

      Parameters:
      path - identifying the item
      Returns:
      item builder
    • builder

      public PathBasedMenuBuilder builder()
      Get the PathBasedMenuBuilder being used for configuration of the Menu.
      Returns:
      menu builder
      See Also:
    • addMenuPostProcessor

      public void addMenuPostProcessor(Consumer<T> postProcessor)
      Add a single Consumer for post-processing the generated Menu. This consumer will be called once the menu has been generated, sorted and the selector applied; but before the MenuFactory returns to the caller.
      Parameters:
      postProcessor - for the menu
    • getMenu

      public T getMenu()
      The menu item that is being built. Usually you do not want to make direct changes to this menu but use the builder() instead. If you want to make modifications after the builder has been applied, register a custom post-processor using addMenuPostProcessor(Consumer).
      Returns:
      menu being built - never null
    • getMenuPostProcessors

      public Collection<Consumer<T>> getMenuPostProcessors()
      The modifiable list of consumers that should be applied to the generated Menu before the MenuFactory hands it out.