aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoseph Carroll2012-08-14 10:49:46 (EDT)
committerPaul Webster2012-08-14 10:49:46 (EDT)
commit2a994703ab753f844610967441e6553293dc353e (patch)
tree9a55c159625aa18f9119953be9523abc5b5d9159
parent724d1d83a3b1790ae852bc1101bd7dff873a8896 (diff)
downloadeclipse.platform.ui-2a994703ab753f844610967441e6553293dc353e.zip
eclipse.platform.ui-2a994703ab753f844610967441e6553293dc353e.tar.gz
eclipse.platform.ui-2a994703ab753f844610967441e6553293dc353e.tar.bz2
Bug 386173 - [Refactor] HandledContributionItem parameterized command
generation Clean up the 3 codepaths that do the same thing.
-rw-r--r--bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/HandledContributionItem.java104
1 files changed, 27 insertions, 77 deletions
diff --git a/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/HandledContributionItem.java b/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/HandledContributionItem.java
index f2e1fba..257f38d 100644
--- a/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/HandledContributionItem.java
+++ b/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/HandledContributionItem.java
@@ -270,51 +270,26 @@ public class HandledContributionItem extends ContributionItem {
*
*/
private void generateCommand() {
- if (model.getCommand() == null) {
- return;
- }
- if (model.getWbCommand() == null) {
+ if (model.getCommand() != null && model.getWbCommand() == null) {
String cmdId = model.getCommand().getElementId();
- final List<MParameter> modelParms = model.getParameters();
- if (modelParms.isEmpty()) {
- final ParameterizedCommand parmCmd = commandService
- .createCommand(cmdId, null);
- Activator
- .trace(Policy.DEBUG_MENUS, "command: " + parmCmd, null); //$NON-NLS-1$
- model.setWbCommand(parmCmd);
-
- styleState = parmCmd.getCommand().getState(IMenuStateIds.STYLE);
-
- toggleState = parmCmd.getCommand().getState(
- ORG_ECLIPSE_UI_COMMANDS_TOGGLE_STATE);
- radioState = parmCmd.getCommand().getState(
- ORG_ECLIPSE_UI_COMMANDS_RADIO_STATE);
- updateState();
- if (styleState != null) {
- styleState.addListener(stateListener);
- } else if (toggleState != null) {
- toggleState.addListener(stateListener);
- } else if (radioState != null) {
- radioState.addListener(stateListener);
- }
- return;
- }
- HashMap<String, String> parms = new HashMap<String, String>();
- for (MParameter parm : modelParms) {
- parms.put(parm.getName(), parm.getValue());
+ List<MParameter> modelParms = model.getParameters();
+ Map<String, String> parameters = new HashMap<String, String>(4);
+ for (MParameter mParm : modelParms) {
+ parameters.put(mParm.getName(), mParm.getValue());
}
- final ParameterizedCommand parmCmd = commandService.createCommand(
- cmdId, parms);
+ ParameterizedCommand parmCmd = commandService.createCommand(cmdId,
+ parameters);
Activator.trace(Policy.DEBUG_MENUS, "command: " + parmCmd, null); //$NON-NLS-1$
+
model.setWbCommand(parmCmd);
styleState = parmCmd.getCommand().getState(IMenuStateIds.STYLE);
-
toggleState = parmCmd.getCommand().getState(
ORG_ECLIPSE_UI_COMMANDS_TOGGLE_STATE);
radioState = parmCmd.getCommand().getState(
ORG_ECLIPSE_UI_COMMANDS_RADIO_STATE);
updateState();
+
if (styleState != null) {
styleState.addListener(stateListener);
} else if (toggleState != null) {
@@ -553,58 +528,33 @@ public class HandledContributionItem extends ContributionItem {
} else {
item.setText(""); //$NON-NLS-1$
}
- final String tooltip = getToolTipText(model);
+ final String tooltip = getToolTipText();
item.setToolTipText(tooltip);
item.setSelection(model.isSelected());
item.setEnabled(model.isEnabled());
}
- private String getToolTipText(MItem item) {
- String text = item.getLocalizedTooltip();
- if (item instanceof MHandledItem) {
- MHandledItem handledItem = (MHandledItem) item;
- IEclipseContext context = getContext(item);
- ParameterizedCommand cmd = handledItem.getWbCommand();
- if (cmd == null) {
- cmd = generateParameterizedCommand(handledItem, context);
- }
- if (text == null) {
- try {
- text = cmd.getName();
- } catch (NotDefinedException e) {
- return null;
- }
- }
- EBindingService bs = (EBindingService) context
- .get(EBindingService.class.getName());
- if (bs != null) {
- TriggerSequence sequence = bs.getBestSequenceFor(handledItem
- .getWbCommand());
- if (sequence != null) {
- text = text + " (" + sequence.format() + ')'; //$NON-NLS-1$
- }
- }
- return text;
+ private String getToolTipText() {
+ String text = model.getLocalizedTooltip();
+ ParameterizedCommand parmCmd = model.getWbCommand();
+ if (parmCmd == null) {
+ generateCommand();
+ parmCmd = model.getWbCommand();
}
- return text;
- }
- private ParameterizedCommand generateParameterizedCommand(
- final MHandledItem item, final IEclipseContext lclContext) {
- ECommandService cmdService = (ECommandService) lclContext
- .get(ECommandService.class.getName());
- Map<String, Object> parameters = null;
- List<MParameter> modelParms = item.getParameters();
- if (modelParms != null && !modelParms.isEmpty()) {
- parameters = new HashMap<String, Object>();
- for (MParameter mParm : modelParms) {
- parameters.put(mParm.getName(), mParm.getValue());
+ if (text == null) {
+ try {
+ text = parmCmd.getName();
+ } catch (NotDefinedException e) {
+ return null;
}
}
- ParameterizedCommand cmd = cmdService.createCommand(item.getCommand()
- .getElementId(), parameters);
- item.setWbCommand(cmd);
- return cmd;
+
+ TriggerSequence sequence = bindingService.getBestSequenceFor(parmCmd);
+ if (sequence != null) {
+ text = text + " (" + sequence.format() + ')'; //$NON-NLS-1$
+ }
+ return text;
}
private void updateIcons() {