Example usage for org.eclipse.jface.bindings BindingManager getActiveBindingsDisregardingContextFlat

List of usage examples for org.eclipse.jface.bindings BindingManager getActiveBindingsDisregardingContextFlat

Introduction

In this page you can find the example usage for org.eclipse.jface.bindings BindingManager getActiveBindingsDisregardingContextFlat.

Prototype

public Collection getActiveBindingsDisregardingContextFlat() 

Source Link

Document

Computes the bindings for the current state of the application, but disregarding the current contexts.

Usage

From source file:org.eclipse.ui.internal.BindingToModelProcessor.java

License:Open Source License

@Execute
void process(final MApplication application, IEclipseContext context) {
    gatherContexts(application.getRootContext());
    gatherCommands(application.getCommands());
    gatherTables(application.getBindingTables());

    CommandManager commandManager = context.get(CommandManager.class);
    if (commandManager == null) {
        WorkbenchPlugin.log("Command manager was null in org.eclipse.ui.internal.BindingToModelProcessor"); //$NON-NLS-1$
    }/*from w w w  .  j  ava  2s  .c o  m*/
    ContextManager contextManager = context.get(ContextManager.class);
    if (contextManager == null) {
        WorkbenchPlugin.log("Context manager was null in org.eclipse.ui.internal.BindingToModelProcessor"); //$NON-NLS-1$
    }
    BindingManager bindingManager = new BindingManager(contextManager, commandManager);
    context.set(BindingManager.class, bindingManager);
    BindingPersistence persistence = new BindingPersistence(bindingManager, commandManager);
    persistence.read();

    // we'll make this available, although I doubt we have a use for it
    application.getTags()
            .add(EBindingService.ACTIVE_SCHEME_TAG + ':' + bindingManager.getActiveScheme().getId());

    Collection<?> activeBindingsForScheme = bindingManager.getActiveBindingsDisregardingContextFlat();

    for (Object obj : activeBindingsForScheme) {
        Binding binding = (Binding) obj;
        addBinding(application, binding);
    }

    persistence.dispose();
}

From source file:org.eclipse.ui.internal.dialogs.cpd.ItemDetailToolTip.java

License:Open Source License

/**
 * Gets the keybindings associated with a ContributionItem.
 *///from   ww  w .  j a  v a 2 s. co  m
static Binding[] getKeyBindings(WorkbenchWindow window, DisplayItem item) {
    IBindingService bindingService = (IBindingService) window.getService(IBindingService.class);

    if (!(bindingService instanceof BindingService)) {
        return new Binding[0];
    }

    String id = CustomizePerspectiveDialog.getCommandID(item);
    String param = CustomizePerspectiveDialog.getParamID(item);

    BindingManager bindingManager = ((BindingService) bindingService).getBindingManager();

    Collection<?> allBindings = bindingManager.getActiveBindingsDisregardingContextFlat();

    List<Binding> foundBindings = new ArrayList<>(2);

    for (Iterator<?> i = allBindings.iterator(); i.hasNext();) {
        Binding binding = (Binding) i.next();
        if (binding.getParameterizedCommand() == null) {
            continue;
        }
        if (binding.getParameterizedCommand().getId() == null) {
            continue;
        }
        if (binding.getParameterizedCommand().getId().equals(id)) {
            if (param == null) {
                // We found it!
                foundBindings.add(binding);
            } else {
                // command parameters are only used in the shortcuts
                Map<?, ?> m = binding.getParameterizedCommand().getParameterMap();
                String key = null;
                if (CustomizePerspectiveDialog.isNewWizard(item)) {
                    key = IWorkbenchCommandConstants.FILE_NEW_PARM_WIZARDID;
                } else if (CustomizePerspectiveDialog.isShowView(item)) {
                    key = IWorkbenchCommandConstants.VIEWS_SHOW_VIEW_PARM_ID;
                } else if (CustomizePerspectiveDialog.isShowPerspective(item)) {
                    key = IWorkbenchCommandConstants.PERSPECTIVES_SHOW_PERSPECTIVE_PARM_ID;
                }

                if (key != null) {
                    if (param.equals(m.get(key))) {
                        foundBindings.add(binding);
                    }
                }
            }
        }
    }

    Binding[] bindings = foundBindings.toArray(new Binding[foundBindings.size()]);

    return bindings;
}

From source file:org.eclipse.ui.internal.dialogs.CustomizePerspectiveDialog.java

License:Open Source License

/**
 * Gets the keybindings associated with a ContributionItem.
 *///from w ww.  j  a  v  a2s.co  m
private Binding[] getKeyBindings(DisplayItem item) {
    IBindingService bindingService = (IBindingService) window.getService(IBindingService.class);

    if (!(bindingService instanceof BindingService))
        return new Binding[0];

    String id = getCommandID(item);
    String param = getParamID(item);

    BindingManager bindingManager = ((BindingService) bindingService).getBindingManager();

    Collection allBindings = bindingManager.getActiveBindingsDisregardingContextFlat();

    List foundBindings = new ArrayList(2);

    for (Iterator i = allBindings.iterator(); i.hasNext();) {
        Binding binding = (Binding) i.next();
        if (binding.getParameterizedCommand() == null)
            continue;
        if (binding.getParameterizedCommand().getId() == null)
            continue;
        if (binding.getParameterizedCommand().getId().equals(id)) {
            if (param == null) {
                // We found it!
                foundBindings.add(binding);
            } else {
                // command parameters are only used in the shortcuts
                Map m = binding.getParameterizedCommand().getParameterMap();
                String key = null;
                if (isNewWizard(item)) {
                    key = IWorkbenchCommandConstants.FILE_NEW_PARM_WIZARDID;
                } else if (isShowView(item)) {
                    key = IWorkbenchCommandConstants.VIEWS_SHOW_VIEW_PARM_ID;
                } else if (isShowPerspective(item)) {
                    key = IWorkbenchCommandConstants.PERSPECTIVES_SHOW_PERSPECTIVE_PARM_ID;
                }

                if (key != null) {
                    if (param.equals(m.get(key))) {
                        foundBindings.add(binding);
                    }
                }
            }
        }
    }

    Binding[] bindings = (Binding[]) foundBindings.toArray(new Binding[foundBindings.size()]);

    return bindings;
}

From source file:org.eclipse.ui.internal.keys.model.BindingModel.java

License:Open Source License

/**
 * The initialization only.//  w ww .j  a va  2 s  .  co m
 * 
 * @param locator
 * @param manager
 * @param model
 */
public void init(IServiceLocator locator, BindingManager manager, ContextModel model) {
    Set cmdsForBindings = new HashSet();
    bindingToElement = new HashMap();
    commandToElement = new HashMap();

    bindingElements = new HashSet();
    bindingManager = manager;

    Iterator i = manager.getActiveBindingsDisregardingContextFlat().iterator();
    while (i.hasNext()) {
        Binding b = (Binding) i.next();
        BindingElement be = new BindingElement(controller);
        be.init(b, model);
        be.setParent(this);
        bindingElements.add(be);
        bindingToElement.put(b, be);
        cmdsForBindings.add(b.getParameterizedCommand());
    }

    ICommandService commandService = (ICommandService) locator.getService(ICommandService.class);
    final Collection commandIds = commandService.getDefinedCommandIds();
    allParameterizedCommands = new HashSet();
    final Iterator commandIdItr = commandIds.iterator();
    while (commandIdItr.hasNext()) {
        final String currentCommandId = (String) commandIdItr.next();
        final Command currentCommand = commandService.getCommand(currentCommandId);
        try {
            allParameterizedCommands.addAll(ParameterizedCommand.generateCombinations(currentCommand));
        } catch (final NotDefinedException e) {
            // It is safe to just ignore undefined commands.
        }
    }

    i = allParameterizedCommands.iterator();
    while (i.hasNext()) {
        ParameterizedCommand cmd = (ParameterizedCommand) i.next();
        if (!cmdsForBindings.contains(cmd)) {
            BindingElement be = new BindingElement(controller);
            be.init(cmd);
            be.setParent(this);
            bindingElements.add(be);
            commandToElement.put(cmd, be);
        }
    }
}