User Tools

Site Tools


This is an old revision of the document!

A PCRE internal error occured. This might be caused by a faulty plugin

====== 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("name", userAction.getName()); dynamicItem.getTransientData().put("command", userAction.getCommand()); items.add(dynamicItem); } </sxh> 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("name", "").toString(); String userActionCommand = menuItem.getTransientData().getOrDefault("command", "").toString(); } </sxh> {{tags: devel java e4 rcp}}

add_data_to_dynamic_menu_entry.1515225751.txt.gz · Last modified: 2018/01/06 08:02 by mihael