From 16154050d89243531b299a4dfbf4afc79e9e1650 Mon Sep 17 00:00:00 2001 From: Bruno Sinou Date: Fri, 19 Sep 2014 13:01:19 +0000 Subject: [PATCH] Update command utilities to enable the definition of multiple occurrences of the same command with distinct parameters in single context menu git-svn-id: https://svn.argeo.org/commons/trunk@7255 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- .../argeo/eclipse/ui/utils/CommandUtils.java | 51 ++++++++++++++++--- 1 file changed, 44 insertions(+), 7 deletions(-) diff --git a/base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/utils/CommandUtils.java b/base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/utils/CommandUtils.java index d150551bb..51de673c8 100644 --- a/base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/utils/CommandUtils.java +++ b/base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/utils/CommandUtils.java @@ -105,7 +105,23 @@ public class CommandUtils { /** * Commodities the refresh of a single command with a map of parameters in a - * Menu.aboutToShow method to simplify further development + * Menu.aboutToShow method to simplify further development Rather use + * {@link refreshParameterizedCommand()} + */ + @Deprecated + public static void refreshParametrizedCommand(IMenuManager menuManager, + IServiceLocator locator, String cmdId, String label, + ImageDescriptor icon, boolean showCommand, + Map params) { + refreshParameterizedCommand(menuManager, locator, cmdId, label, icon, + showCommand, params); + } + + /** + * Commodities the refresh the contribution of a command with a map of + * parameters in a context menu + * + * The command ID is used has contribution item ID * * @param menuManager * @param locator @@ -114,17 +130,38 @@ public class CommandUtils { * @param iconPath * @param showCommand */ - public static void refreshParametrizedCommand(IMenuManager menuManager, + public static void refreshParameterizedCommand(IMenuManager menuManager, IServiceLocator locator, String cmdId, String label, ImageDescriptor icon, boolean showCommand, Map params) { - IContributionItem ici = menuManager.find(cmdId); + refreshParameterizedCommand(menuManager, locator, cmdId, cmdId, label, + icon, showCommand, params); + } + + /** + * Commodities the refresh the contribution of a command with a map of + * parameters in a context menu + * + * @param menuManager + * @param locator + * @param contributionId + * @param commandId + * @param label + * @param icon + * @param showCommand + * @param params + */ + public static void refreshParameterizedCommand(IMenuManager menuManager, + IServiceLocator locator, String contributionId, String commandId, + String label, ImageDescriptor icon, boolean showCommand, + Map params) { + IContributionItem ici = menuManager.find(contributionId); if (ici != null) menuManager.remove(ici); - CommandContributionItemParameter contributionItemParameter = new CommandContributionItemParameter( - locator, null, cmdId, SWT.PUSH); - if (showCommand) { + CommandContributionItemParameter contributionItemParameter = new CommandContributionItemParameter( + locator, null, commandId, SWT.PUSH); + // Set Params contributionItemParameter.label = label; contributionItemParameter.icon = icon; @@ -134,7 +171,7 @@ public class CommandUtils { CommandContributionItem cci = new CommandContributionItem( contributionItemParameter); - cci.setId(cmdId); + cci.setId(contributionId); menuManager.add(cci); } } -- 2.30.2