use of org.eclipse.jface.commands.ToggleState in project eclipse.platform.ui by eclipse-platform.
the class LegacyActionPersistence method convertActionToCommand.
/**
* Determine which command to use. This is slightly complicated as actions do
* not have to have commands, but the new architecture requires it. As such, we
* will auto-generate a command for the action if the definitionId is missing or
* points to a command that does not yet exist. All such command identifiers are
* prefixed with AUTOGENERATED_COMMAND_ID_PREFIX.
*
* @param element The action element from which a command must be
* generated; must not be <code>null</code>.
* @param primaryId The primary identifier to use when auto-generating a
* command; must not be <code>null</code>.
* @param secondaryId The secondary identifier to use when auto-generating a
* command; must not be <code>null</code>.
* @param warningsToLog The collection of warnings logged while reading the
* extension point; must not be <code>null</code>.
* @return the fully-parameterized command; <code>null</code> if an error
* occurred.
*/
private ParameterizedCommand convertActionToCommand(final IConfigurationElement element, final String primaryId, final String secondaryId, final List<IStatus> warningsToLog) {
String commandId = readOptional(element, ATT_DEFINITION_ID);
Command command = null;
if (commandId != null) {
command = commandService.getCommand(commandId);
}
final IActionCommandMappingService mappingService = 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) {
// $NON-NLS-1$
WorkbenchPlugin.log("MappingService unavailable");
return null;
}
// Read the label attribute.
label = readRequired(// $NON-NLS-1$
element, // $NON-NLS-1$
ATT_LABEL, // $NON-NLS-1$
warningsToLog, // $NON-NLS-1$
"Actions require a non-empty label or definitionId", 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);
}
}
// and the actionId
if (mappingService != null) {
mappingService.map(mappingService.getGeneratedCommandId(primaryId, secondaryId), commandId);
}
return new ParameterizedCommand(command, null);
}
Aggregations