Example usage for org.eclipse.jface.commands ActionHandler getAction

List of usage examples for org.eclipse.jface.commands ActionHandler getAction

Introduction

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

Prototype

public final IAction getAction() 

Source Link

Document

Returns the action associated with this handler

Usage

From source file:com.mousefeed.eclipse.ActionActionDescGenerator.java

License:Open Source License

/**
 * Gets accelerator for the bindings data.
 * // w w  w.  j a va  2 s  .c om
 * @param action
 *            the action. Assumed not null.
 * @param actionClass
 *            effective action class. Assumed not null.
 * @param triggerSequence
 *            the binding trigger sequence. Assumed not null.
 * @param handler
 *            the action handler. Assumed not null.
 * @return the accelerator if found, <code>null</code> otherwise.
 */
private String getFromBindingData(final IAction action, final Class<? extends IAction> actionClass,
        final TriggerSequence triggerSequence, final IHandler handler) {
    final ActionHandler actionHandler = (ActionHandler) handler;
    final IAction boundAction = actionHandler.getAction();
    if (boundAction == null) {
        return null;
    }
    if (boundAction.getClass().equals(actionClass)) {
        return triggerSequence.toString();
    }
    if (!(boundAction instanceof RetargetAction)) {
        return null;
    }
    final IAction searchTarget = ((RetargetAction) boundAction).getActionHandler();
    if (searchTarget == null) {
        return null;
    }
    if (searchTarget.getClass().equals(actionClass)) {
        return triggerSequence.toString();
    }
    if (actionSearcher.isSearchable(searchTarget)) {
        final String id = actionSearcher.findActionDefinitionId(action, searchTarget);
        return findAcceleratorForActionDefinition(id);
    }
    return null;
}

From source file:org.apache.directory.studio.utils.ActionUtils.java

License:Apache License

/**
 * Deactivates the action handler, if the handler's action is equal to 
 * the given action.// w ww .  j  a v  a 2s. co m
 * 
 * @param action the action
 */
public static void deactivateActionHandler(IAction action) {
    ICommandService commandService = PlatformUI.getWorkbench().getAdapter(ICommandService.class);

    if (commandService != null) {
        Command command = commandService.getCommand(action.getActionDefinitionId());
        IHandler handler = command.getHandler();

        if (handler instanceof ActionHandler) {
            ActionHandler actionHandler = (ActionHandler) handler;

            if (actionHandler.getAction() == action) {
                command.setHandler(null);
            }
        } else if (handler != null) {
            command.setHandler(null);
        }
    }
}