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 Summary
ConstructorDescriptionBuildMenuEvent
(T menu) BuildMenuEvent
(T menu, @NonNull PathBasedMenuBuilder menuBuilder, @NonNull org.springframework.core.ResolvableType menuResolvableType) BuildMenuEvent
(T menu, PathBasedMenuBuilder menuBuilder) -
Method Summary
Modifier and TypeMethodDescriptionvoid
addMenuPostProcessor
(Consumer<T> postProcessor) builder()
Get thePathBasedMenuBuilder
being used for configuration of theMenu
.Name for this event, same as the menu name.getMenu()
The menu item that is being built.Name of the menu being built.The modifiable list of consumers that should be applied to the generatedMenu
before theMenuFactory
hands it out.Retrieve the menu selector that is attached to this event.org.springframework.core.ResolvableType
Retrieve the item builder for a specific path, where the item should represent a group of items.boolean
isForMenuOfType
(@NonNull Class<? extends Menu> menuClass) Check if the current build event is for a menu of the given type.Retrieve the item builder for a specific path.optionalItem
(String path) Return an item builder for updating an item if it exists.void
setMenuSelector
(MenuSelector menuSelector) Set theMenuSelector
that should be used for selecting the active items, after theMenu
has been built by theMenuFactory
.
-
Constructor Details
-
BuildMenuEvent
-
-
Method Details
-
getResolvableType
public org.springframework.core.ResolvableType getResolvableType()- Specified by:
getResolvableType
in interfaceorg.springframework.core.ResolvableTypeProvider
-
getEventName
Name for this event, same as the menu name.- Specified by:
getEventName
in interfaceNamedAcrossEvent
- Returns:
- event name
-
getMenuName
Name of the menu being built.- Returns:
- menu name
-
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 theMenu
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 theMenuFactory
should use withsetMenuSelector(MenuSelector)
.- Returns:
- the MenuSelector attached to this event
- See Also:
-
isForMenuOfType
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 forbuilder().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 actualMenu
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 forbuilder().group(path)
.- Parameters:
path
- identifying the item- Returns:
- item builder
-
optionalItem
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 forbuilder().optionalItem(path)
.- Parameters:
path
- identifying the item- Returns:
- item builder
-
builder
Get thePathBasedMenuBuilder
being used for configuration of theMenu
.- Returns:
- menu builder
- See Also:
-
addMenuPostProcessor
Add a singleConsumer
for post-processing the generatedMenu
. This consumer will be called once the menu has been generated, sorted and the selector applied; but before theMenuFactory
returns to the caller.- Parameters:
postProcessor
- for the menu
-
getMenu
The menu item that is being built. Usually you do not want to make direct changes to this menu but use thebuilder()
instead. If you want to make modifications after the builder has been applied, register a custom post-processor usingaddMenuPostProcessor(Consumer)
.- Returns:
- menu being built - never
null
-
getMenuPostProcessors
The modifiable list of consumers that should be applied to the generatedMenu
before theMenuFactory
hands it out.
-