Example usage for org.eclipse.jface.commands ToggleState ToggleState

List of usage examples for org.eclipse.jface.commands ToggleState ToggleState

Introduction

In this page you can find the example usage for org.eclipse.jface.commands ToggleState ToggleState.

Prototype

public ToggleState() 

Source Link

Document

Constructs a new ToggleState.

Usage

From source file:org.eclipse.datatools.connectivity.ui.dse.views.DataSourceExplorerView.java

License:Open Source License

/**
 * creates the initial show category handler
 */// ww w  .  ja v  a 2  s.co m
private void createHandlers() {

    // set the initial state of the ShowCategory menu & toolbar button
    IHandlerService handlerService = (IHandlerService) getSite().getService(IHandlerService.class);
    ShowCategoryAction handler = new ShowCategoryAction();
    handler.init(this);
    handlerService.activateHandler(ShowCategoryAction.HANDLER_ID, handler);
    ToggleState ts = new ToggleState();
    ts.setValue(Boolean.TRUE);
    handler.addState("STYLE", ts); //$NON-NLS-1$
}

From source file:org.eclipse.edt.debug.internal.ui.actions.EnableFiltersAction.java

License:Open Source License

public EnableFiltersAction() {
    state = new ToggleState();
    state.setValue(PreferenceUtil.getBoolean(IEGLDebugCoreConstants.PREFERENCE_TYPE_FILTERS_ENABLED, true));
    addState("STYLE", state); //$NON-NLS-1$
    PreferenceUtil.addPreferenceChangeListener(this);
}

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.
 * /*from   w w  w  . j  ava2s.  com*/
 * @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);
}