*/
private final ParameterizedCommand convertActionToCommand(
final IConfigurationElement element, final String primaryId,
final String secondaryId, final List warningsToLog) {
String commandId = readOptional(element, ATT_DEFINITION_ID);
Command command = null;
if (commandId != null) {
command = commandService.getCommand(commandId);
}
final IActionCommandMappingService mappingService = (IActionCommandMappingService) window
.getService(IActionCommandMappingService.class);
String label = null;
if ((commandId == null) || (!command.isDefined())) {
// Add a mapping from this action id to the command id.
if (commandId == null && mappingService != null) {
commandId = mappingService.getGeneratedCommandId(primaryId,
secondaryId);
}
if (commandId == null) {
WorkbenchPlugin.log("MappingService unavailable"); //$NON-NLS-1$
return null;
}
// Read the label attribute.
label = readRequired(element, ATT_LABEL, warningsToLog,
"Actions require a non-empty label or definitionId", //$NON-NLS-1$
commandId);
if (label == null) {
label = WorkbenchMessages.LegacyActionPersistence_AutogeneratedCommandName;
}
/*
* Read the tooltip attribute. The tooltip is really the description
* of the command.
*/
final String tooltip = readOptional(element, ATT_TOOLTIP);
// Define the command.
command = commandService.getCommand(commandId);
final Category category = commandService.getCategory(null);
final String name = LegacyActionTools.removeAcceleratorText(Action
.removeMnemonics(label));
command.define(name, tooltip, category, null);
// TODO Decide the command state.
final String style = readOptional(element, ATT_STYLE);
if (STYLE_RADIO.equals(style)) {
final State state = new RadioState();
// TODO How to set the id?
final boolean checked = readBoolean(element, ATT_STATE, false);
state.setValue((checked) ? Boolean.TRUE : Boolean.FALSE);
command.addState(IMenuStateIds.STYLE, state);
} else if (STYLE_TOGGLE.equals(style)) {
final State state = new ToggleState();
final boolean checked = readBoolean(element, ATT_STATE, false);
state.setValue((checked) ? Boolean.TRUE : Boolean.FALSE);
command.addState(IMenuStateIds.STYLE, state);
}
}
// this allows us to look up a "commandId" give the contributionId
// and the actionId
if (mappingService != null && commandId != null) {