+ /** Dynamically creates an handled menu item from a command ID. */
+ public static MHandledMenuItem createHandledMenuItem(EModelService modelService, MApplication app,
+ String commandId) {
+ MCommand command = findCommand(modelService, app, commandId);
+ if (command == null)
+ return null;
+ MHandledMenuItem handledItem = modelService.createModelElement(MHandledMenuItem.class);
+ handledItem.setCommand(command);
+ return handledItem;
+
+ }
+
+ /**
+ * Finds a command by ID.
+ *
+ * @return the {@link MCommand} or <code>null</code> if not found.
+ */
+ public static MCommand findCommand(EModelService modelService, MApplication app, String commandId) {
+ List<MCommand> cmds = modelService.findElements(app, null, MCommand.class, null);
+ for (MCommand cmd : cmds) {
+ if (cmd.getElementId().equals(commandId)) {
+ return cmd;
+ }
+ }
+ return null;
+ }
+
+ /** Dynamically creates a direct menu item from a class. */
+ public static MDirectMenuItem createDirectMenuItem(EModelService modelService, Class<?> clss, String label) {
+ MDirectMenuItem dynamicItem = modelService.createModelElement(MDirectMenuItem.class);
+ dynamicItem.setLabel(label);
+ Bundle bundle = FrameworkUtil.getBundle(clss);
+ dynamicItem.setContributionURI("bundleclass://" + bundle.getSymbolicName() + "/" + clss.getName());
+ return dynamicItem;
+ }
+
+ /** Singleton. */