Example usage for org.eclipse.jface.action LegacyActionTools removeAcceleratorText

List of usage examples for org.eclipse.jface.action LegacyActionTools removeAcceleratorText

Introduction

In this page you can find the example usage for org.eclipse.jface.action LegacyActionTools removeAcceleratorText.

Prototype

public static String removeAcceleratorText(final String text) 

Source Link

Document

Convenience method for removing any optional accelerator text from the given string.

Usage

From source file:org.eclipse.ui.internal.menus.LegacyActionPersistence.java

License:Open Source License

/**
 * 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.
 * //w w w  .ja va 2  s .  c  o m
 * @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 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) {
        mappingService.map(mappingService.getGeneratedCommandId(primaryId, secondaryId), commandId);
    }

    return new ParameterizedCommand(command, null);
}