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

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

Introduction

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

Prototype

public Scheme getActiveScheme() 

Source Link

Document

Gets the currently active scheme.

Usage

From source file:org.csstudio.iter.css.product.util.WorkbenchUtil.java

License:Open Source License

/**
 * Unbind F11 KeyBinding of org.eclipse.debug.ui to avoid conflict with
 * org.csstudio.opibuilder plugin//from   w w  w.j a  v a  2  s . co  m
 */
public static void unbindDebugLast() {
    IBindingService bindingService = (IBindingService) PlatformUI.getWorkbench()
            .getAdapter(IBindingService.class);
    BindingManager localChangeManager = new BindingManager(new ContextManager(), new CommandManager());

    final Scheme[] definedSchemes = bindingService.getDefinedSchemes();
    try {
        for (int i = 0; i < definedSchemes.length; i++) {
            final Scheme scheme = definedSchemes[i];
            final Scheme copy = localChangeManager.getScheme(scheme.getId());
            copy.define(scheme.getName(), scheme.getDescription(), scheme.getParentId());
        }
        localChangeManager.setActiveScheme(bindingService.getActiveScheme());
    } catch (final NotDefinedException e) {
        e.printStackTrace();
    }
    localChangeManager.setLocale(bindingService.getLocale());
    localChangeManager.setPlatform(bindingService.getPlatform());
    localChangeManager.setBindings(bindingService.getBindings());

    KeyBinding opiFullScreenBinding = null;
    int nbBinding = 0;

    Binding[] bArray = bindingService.getBindings();
    if (bArray != null) {
        for (Binding binding : bArray) {
            if (binding instanceof KeyBinding) {
                KeyBinding kBind = (KeyBinding) binding;
                if (kBind.getParameterizedCommand() != null
                        && kBind.getParameterizedCommand().getCommand() != null) {
                    if ("org.eclipse.debug.ui.commands.DebugLast"
                            .equals(kBind.getParameterizedCommand().getCommand().getId())) {
                        KeySequence triggerSequence = kBind.getKeySequence();
                        String contextId = kBind.getContextId();
                        String schemeId = kBind.getSchemeId();
                        KeyBinding deleteBinding = new KeyBinding(triggerSequence, null, schemeId, contextId,
                                null, null, null, Binding.USER);
                        localChangeManager.addBinding(deleteBinding);
                        try {
                            bindingService.savePreferences(localChangeManager.getActiveScheme(),
                                    localChangeManager.getBindings());
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                    } else if ("org.csstudio.opibuilder.actions.fullscreen"
                            .equals(kBind.getParameterizedCommand().getCommand().getId())) {
                        if (opiFullScreenBinding == null)
                            opiFullScreenBinding = kBind;
                        nbBinding++;
                    }
                }
            }
        }
    }

    // Rebind OPI runner full screen command if it exists only one time
    if (nbBinding == 1) {
        KeySequence triggerSequence = opiFullScreenBinding.getKeySequence();
        String contextId = opiFullScreenBinding.getContextId();
        String schemeId = opiFullScreenBinding.getSchemeId();

        KeyBinding updateBinding = new KeyBinding(triggerSequence,
                opiFullScreenBinding.getParameterizedCommand(), schemeId, contextId, null, null, null,
                Binding.USER);
        localChangeManager.addBinding(updateBinding);
        try {
            bindingService.savePreferences(localChangeManager.getActiveScheme(),
                    localChangeManager.getBindings());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

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$
    }/* ww  w .  j  a  v a2  s .  com*/
    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.keys.model.SchemeModel.java

License:Open Source License

/**
 * @param bindingManager/*w w w .ja  v a 2s.c  o  m*/
 */
public void init(BindingManager bindingManager) {
    schemes = new ArrayList();
    Scheme[] definedSchemes = bindingManager.getDefinedSchemes();
    for (int i = 0; i < definedSchemes.length; i++) {
        SchemeElement se = new SchemeElement(controller);
        se.init(definedSchemes[i]);
        se.setParent(this);
        schemes.add(se);
        if (definedSchemes[i] == bindingManager.getActiveScheme()) {
            setSelectedElement(se);
        }
    }
}

From source file:org.limy.eclipse.qalab.action.KeyBindAction.java

License:Open Source License

@Override
public void doRun(ISelection selection, IProgressMonitor monitor) throws CoreException {

    IBindingService bindingService = (IBindingService) getWindow().getWorkbench()
            .getService(IBindingService.class);

    KeybindWindow keyWindow = new KeybindWindow(getWindow().getShell(), bindingService);
    keyWindow.setBlockOnOpen(true);/*www  .j av a 2  s.  c  om*/
    keyWindow.open();
    Map<Binding, KeySequence> results = keyWindow.getResults();
    if (results != null) {

        BindingManager localChangeManager;
        try {
            localChangeManager = createLocalManager(bindingService);
        } catch (NotDefinedException e) {
            throw new WorkbenchException(e.getMessage(), e);
        }
        Binding[] bindings = bindingService.getBindings();

        for (Entry<Binding, KeySequence> entry : results.entrySet()) {
            Binding systemBinding = entry.getKey();
            String contextId = systemBinding.getContextId();
            String schemeId = systemBinding.getSchemeId();
            String commandId = systemBinding.getParameterizedCommand().getId();

            // L?[oCh??
            for (Binding binding : bindings) {
                ParameterizedCommand command = binding.getParameterizedCommand();

                if (command != null && commandId.equals(command.getId()) && binding.getType() == Binding.USER) {

                    localChangeManager.removeBindings(binding.getTriggerSequence(), schemeId, contextId, null,
                            null, null, Binding.USER);
                }
            }

            // L?[oCho^
            final ParameterizedCommand command = systemBinding.getParameterizedCommand();
            localChangeManager.addBinding(new KeyBinding(entry.getValue(), command, schemeId, contextId, null,
                    null, null, Binding.USER));

        }

        try {
            bindingService.savePreferences(localChangeManager.getActiveScheme(),
                    localChangeManager.getBindings());
        } catch (IOException e) {
            LimyEclipsePluginUtils.log(e);
        }

    }

}

From source file:org.vimplugin.editors.VimEditorPartListener.java

License:Open Source License

private void disableKeys() {
    if (!keysDisabled) {
        logger.debug("Disabling conflicting keybindings while vim editor is focused: " + Arrays.toString(keys));
        BindingManager localChangeManager = getLocalChangeManager();
        String schemeId = localChangeManager.getActiveScheme().getId();
        for (KeySequence keySequence : keySequences) {
            for (String contextId : CONTEXT_IDS) {
                localChangeManager.removeBindings(keySequence, schemeId, contextId, null, null, null,
                        Binding.USER);
                localChangeManager.addBinding(
                        new KeyBinding(keySequence, null, schemeId, contextId, null, null, null, Binding.USER));
            }/*from  ww w .j a  v a2  s .co  m*/
        }
        keysDisabled = true;
        saveKeyChanges(localChangeManager);
    }
}

From source file:org.vimplugin.editors.VimEditorPartListener.java

License:Open Source License

private void enableKeys() {
    if (keysDisabled) {
        logger.debug("Re-enabling conflicting keybindings.");
        BindingManager localChangeManager = getLocalChangeManager();
        String schemeId = localChangeManager.getActiveScheme().getId();
        for (KeySequence keySequence : keySequences) {
            for (String contextId : CONTEXT_IDS) {
                localChangeManager.removeBindings(keySequence, schemeId, contextId, null, null, null,
                        Binding.USER);
            }//from  ww w.  ja  v  a 2s  . com
        }
        keysDisabled = false;
        saveKeyChanges(localChangeManager);
    }
}

From source file:org.vimplugin.editors.VimEditorPartListener.java

License:Open Source License

private void saveKeyChanges(BindingManager localChangeManager) {
    try {/*from   w  w w .  ja va 2 s .c  o m*/
        bindingService.savePreferences(localChangeManager.getActiveScheme(), localChangeManager.getBindings());
    } catch (Exception e) {
        logger.error("Error persisting key bindings.", e);
    }
}