Differences
This shows you the differences between two versions of the page.
— |
add_data_to_dynamic_menu_entry [2021/04/05 11:23] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Add data to dynamic menu entry ====== | ||
+ | |||
+ | If a dynamic menu contribution is used you can attach additional data (transient data map) to each menu item so that the handler can later work with that data. | ||
+ | |||
+ | <sxh java> | ||
+ | MCommand command = getCommandInstance(USER_ACTION_COMMAND_ID); | ||
+ | |||
+ | for (UserAction userAction : userActions) { | ||
+ | MHandledMenuItem dynamicItem = modelService.createModelElement(MHandledMenuItem.class); | ||
+ | dynamicItem.setLabel(userAction.getName()); | ||
+ | dynamicItem.setCommand(command); | ||
+ | dynamicItem.getTransientData().put(" | ||
+ | dynamicItem.getTransientData().put(" | ||
+ | |||
+ | items.add(dynamicItem); | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | The handler can then retrieve the data by getting the menu item injected. | ||
+ | |||
+ | <sxh java> | ||
+ | @Execute | ||
+ | public void execute(@Optional MMenuItem menuItem) { | ||
+ | String userActionName = menuItem.getTransientData().getOrDefault(" | ||
+ | String userActionCommand = menuItem.getTransientData().getOrDefault(" | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | {{tag> | ||