Example usage for org.eclipse.jface.bindings Binding SYSTEM

List of usage examples for org.eclipse.jface.bindings Binding SYSTEM

Introduction

In this page you can find the example usage for org.eclipse.jface.bindings Binding SYSTEM.

Prototype

int SYSTEM

To view the source code for org.eclipse.jface.bindings Binding SYSTEM.

Click Source Link

Document

The type of binding that is defined by the system (i.e., by the application developer).

Usage

From source file:com.bdaum.zoom.ui.internal.preferences.KeyPreferencePage.java

License:Open Source License

@Override
protected void fillValues() {
    IBindingService bindingService = PlatformUI.getWorkbench().getService(IBindingService.class);
    userMap.clear();// w  w  w . j av a  2  s. c  o m
    systemMap.clear();
    commandMap.clear();
    activeSchemeId = bindingService.getActiveScheme().getId();
    Binding[] bindings = bindingService.getBindings();
    for (Binding binding : bindings) {
        if (activeSchemeId.equals(binding.getSchemeId())) {
            TriggerSequence triggerSequence = binding.getTriggerSequence();
            if (binding.getType() == Binding.SYSTEM)
                systemMap.put(triggerSequence, binding);
            else
                userMap.put(triggerSequence, binding);
        }
    }
    updateViewer();
    ISelection selection = bindingViewer.getSelection();
    if (selection.isEmpty())
        bindingViewer.setSelection(new StructuredSelection(bindingViewer.getElementAt(0)), true);
}

From source file:com.google.eclipse.mechanic.core.keybinding.KeyBindings.java

License:Open Source License

KeyBindings(MechanicLog log, Binding[] bindings) {
    this.log = log;
    List<Binding> ub = new ArrayList<Binding>();
    List<Binding> sb = new ArrayList<Binding>();

    for (Binding binding : bindings) {
        if (binding.getType() == Binding.USER) {
            ub.add(binding);//w  w w .ja va 2 s. c o  m
        } else if (binding.getType() == Binding.SYSTEM) {
            sb.add(binding);
        } else {
            throw new UnsupportedOperationException("Unexpected binding type: " + binding.getType());
        }
    }
    this.userBindings = ub;
    this.systemBindings = Collections.unmodifiableList(sb);
    this.userBindingsMap = buildQualifierToBindingMap(userBindings);
    this.systemBindingsMap = buildQualifierToBindingMap(systemBindings);
}

From source file:com.google.eclipse.mechanic.core.keybinding.KeyBindings.java

License:Open Source License

/**
 * Bind a scheme / platform / context / trigger sequence to a command.
 *///from w w  w .  j a  va 2s . c om
public void addIfNotPresent(Scheme scheme, String platform, String contextId, KeySequence triggerSequence,
        ParameterizedCommand command) {
    Map<String, String> params = commandParamMap(command);
    Binding binding = find(scheme, platform, triggerSequence, command.getId(), params);
    // If no binding exists, create the user binding, add it and return true.
    if (binding == null) {
        Binding bindingToAdd = createBinding(scheme, platform, contextId, triggerSequence, command);
        addUserBinding(bindingToAdd);
        addedBindings.add(bindingToAdd);
        return;
    }

    /*
     * If a system binding exists for this scheme / sequence, find out if there's a
     * user binding hiding it, and if so remove it.
     */
    if ((binding.getType() == Binding.SYSTEM)) {
        // Finding a user binding to a null command.
        // ZORZELLA: do we even need to supply params?
        Binding userBinding = find(scheme, platform, triggerSequence, null, params, userBindings);
        if (userBinding != null) {
            userBindings.remove(userBinding);
            return;
        }
    }
    return;
}

From source file:com.mulgasoft.emacsplus.DynamicInitializer.java

License:Open Source License

/**
 * Add the bindings to the Emacs+ scheme
 *
 * @param editor//from   ww  w .ja v a2s  .c  om
 * @param bindingResult
 */
//   public static void addBindings(ITextEditor editor, Set<MinderBinder> bindings) {
private static void addBindings(Set<MinderBinder> bindings) {

    IBindingService service = ((IBindingService) PlatformUI.getWorkbench().getService(IBindingService.class));
    if (service instanceof BindingService) {
        BindingService bindingSvc = (BindingService) service;
        for (MinderBinder mb : bindings) {
            try {
                ICommandService ics = ((ICommandService) PlatformUI.getWorkbench()
                        .getService(ICommandService.class));
                // check first, as getCommand will create it if it doesn't already exist
                if (ics.getDefinedCommandIds().contains(mb.getCommandId())) {
                    Command cmd = ics.getCommand(mb.getCommandId());
                    if (mb.getEnhancer() != null) {
                        // enhance the pre-defined command with some Emacs+ behavior
                        cmd.addExecutionListener(mb.getEnhancer());
                    }
                    Binding binding = new KeyBinding(mb.getTrigger(), new ParameterizedCommand(cmd, null),
                            mb.getSchemeId(), mb.getContextId(), null, null, null, Binding.SYSTEM); // Binding.USER
                    // this call is scheduled for API promotion sometime (after Helios)
                    bindingSvc.addBinding(binding);
                }
            } catch (ParseException e) {
                e.printStackTrace(); // won't happen
            } catch (Exception e) {
                e.printStackTrace(); // won't happen
            }
        }
    }
}

From source file:org.eclipse.e4.ui.bindings.internal.BindingServiceImpl.java

License:Open Source License

public Binding createBinding(TriggerSequence sequence, ParameterizedCommand command, String contextId,
        Map<String, String> attributes) {

    String schemeId = DEFAULT_SCHEME_ID;
    String locale = null;/*from  w ww  . ja  v  a 2 s .  c  o  m*/
    String platform = null;
    int bindingType = Binding.SYSTEM;

    if (sequence != null && !sequence.isEmpty() && contextId != null) {
        if (attributes != null) {
            String tmp = attributes.get(SCHEME_ID_ATTR_TAG);
            if (tmp != null && tmp.length() > 0) {
                schemeId = tmp;
            }
            locale = attributes.get(LOCALE_ATTR_TAG);
            platform = attributes.get(PLATFORM_ATTR_TAG);
            if (USER_TYPE.equals(attributes.get(TYPE_ATTR_TAG))) {
                bindingType = Binding.USER;
            }
        }
        return new KeyBinding((KeySequence) sequence, command, schemeId, contextId, locale, platform, null,
                bindingType);
    }
    return null;
}

From source file:org.eclipse.e4.ui.keybinding.tests.BindingInteractionsTest.java

License:Open Source License

/**
 * <p>//from  www.  ja v  a2s .  c o m
 * Tests whether two identical bindings lead to a conflict.
 * </p>
 * 
 * @throws NotDefinedException
 *             If the scheme we try to activate is not defined.
 */
public void testConflict() throws NotDefinedException {
    final Context context = contextManager.getContext("na");
    context.define("name", "description", null);

    final Scheme scheme = bindingManager.getScheme("na");
    scheme.define("name", "description", null);

    bindingManager.setActiveScheme(scheme);
    final Set activeContextIds = new HashSet();
    activeContextIds.add("na");
    contextManager.setActiveContextIds(activeContextIds);

    final Binding binding1 = new TestBinding("conflict1", "na", "na", null, null, Binding.SYSTEM, null);
    bindingManager.addBinding(binding1);
    final Binding binding2 = new TestBinding("conflict2", "na", "na", null, null, Binding.SYSTEM, null);
    bindingManager.addBinding(binding2);

    TriggerSequence[] activeBindings = bindingManager.getActiveBindingsFor(binding1.getParameterizedCommand());
    assertFalse(binding1.equals(binding2));
    assertTrue("Neither binding should be active", activeBindings.length == 0);
    activeBindings = bindingManager.getActiveBindingsFor(binding2.getParameterizedCommand());
    assertTrue("Neither binding should be active", activeBindings.length == 0);
}

From source file:org.eclipse.e4.ui.keybinding.tests.BindingInteractionsTest.java

License:Open Source License

/**
 * <p>//from  ww  w . ja v a  2s.c  o  m
 * Tests whether a plug-in developer can override a binding in a child
 * context.
 * </p>
 * 
 * @throws NotDefinedException
 *             If the scheme we try to activate is not defined.
 */
public void testContextOverride() throws NotDefinedException {
    final Context parentContext = contextManager.getContext("parent");
    parentContext.define("parent", "parent context", null);

    final Context childContext = contextManager.getContext("child");
    childContext.define("child", "child context", "parent");

    final Scheme scheme = bindingManager.getScheme("na");
    scheme.define("name", "description", null);

    bindingManager.setActiveScheme(scheme);

    final Binding binding1 = new TestBinding("parent", "na", "parent", null, null, Binding.SYSTEM, null);
    bindingManager.addBinding(binding1);
    final Binding binding2 = new TestBinding("child", "na", "child", null, null, Binding.SYSTEM, null);
    bindingManager.addBinding(binding2);

    // Only "parent"
    final Set activeContextIds = new HashSet();
    activeContextIds.add("parent");
    contextManager.setActiveContextIds(activeContextIds);
    assertEquals("When only the parent context is active, only the parent binding is active.", binding1,
            bindingManager.getPerfectMatch(TestBinding.TRIGGER_SEQUENCE));

    // Only "child"
    activeContextIds.clear();
    activeContextIds.add("child");
    contextManager.setActiveContextIds(activeContextIds);
    assertEquals("When only the child context is active, only the child binding is active.", binding2,
            bindingManager.getPerfectMatch(TestBinding.TRIGGER_SEQUENCE));

    // Both "parent" and "child"
    activeContextIds.add("parent");
    contextManager.setActiveContextIds(activeContextIds);
    assertEquals("When both contexts are active, only the child binding is active.", binding2,
            bindingManager.getPerfectMatch(TestBinding.TRIGGER_SEQUENCE));
}

From source file:org.eclipse.e4.ui.keybinding.tests.BindingInteractionsTest.java

License:Open Source License

/**
 * <p>// w w w . j  a va 2 s.c  o  m
 * Tests whether a user-defined deletion actually works.
 * </p>
 * 
 * @throws NotDefinedException
 *             If the scheme we try to activate is not defined.
 */
public void testDeletedBinding() throws NotDefinedException {
    final Context context = contextManager.getContext("na");
    context.define("name", "description", null);

    final Scheme scheme = bindingManager.getScheme("na");
    scheme.define("name", "description", null);

    bindingManager.setActiveScheme(scheme);
    final Set activeContextIds = new HashSet();
    activeContextIds.add("na");
    contextManager.setActiveContextIds(activeContextIds);

    final Binding binding1 = new TestBinding(null, "na", "na", null, null, Binding.USER, null);
    bindingManager.addBinding(binding1);
    final Binding binding2 = new TestBinding("system", "na", "na", null, null, Binding.SYSTEM, null);
    bindingManager.addBinding(binding2);
    assertEquals("The user should be able to remove bindings", null,
            bindingManager.getPerfectMatch(TestBinding.TRIGGER_SEQUENCE));
}

From source file:org.eclipse.e4.ui.keybinding.tests.BindingInteractionsTest.java

License:Open Source License

/**
 * <p>/*from   w w w .  j  a  va  2 s.c o m*/
 * Tests whether a user-defined deletion in one context will allow a binding
 * in a parent context to match.  Bug 105655.
 * </p>
 * 
 * @throws NotDefinedException
 *             If the scheme we try to activate is not defined.
 */
public void testDeletedBindingAllowsParent() throws NotDefinedException {
    final Context parentContext = contextManager.getContext("parent");
    parentContext.define("name", "description", null);
    final Context childContext = contextManager.getContext("child");
    childContext.define("name", "description", "parent");

    final Scheme scheme = bindingManager.getScheme("na");
    scheme.define("name", "description", null);

    bindingManager.setActiveScheme(scheme);
    final Set activeContextIds = new HashSet();
    activeContextIds.add("parent");
    activeContextIds.add("child");
    contextManager.setActiveContextIds(activeContextIds);

    final Binding childBinding = new TestBinding("childCommand", "na", "child", null, null, Binding.SYSTEM,
            null);
    bindingManager.addBinding(childBinding);
    final Binding deletion = new TestBinding(null, "na", "child", null, null, Binding.USER, null);
    bindingManager.addBinding(deletion);
    final Binding parentBinding = new TestBinding("parentCommand", "na", "parent", null, null, Binding.SYSTEM,
            null);
    bindingManager.addBinding(parentBinding);
    assertEquals("The user should be able to remove bindings to allow a parent binding", "parentCommand",
            bindingManager.getPerfectMatch(TestBinding.TRIGGER_SEQUENCE).getParameterizedCommand().getId());
}

From source file:org.eclipse.e4.ui.keybinding.tests.BindingInteractionsTest.java

License:Open Source License

/**
 * <p>//ww  w .  j av  a2  s. c o  m
 * Tests a common case for binding deletion. The binding is defined on all
 * platforms, then deleted on a specific platform, and defined again as
 * something else.
 * </p>
 * 
 * @throws NotDefinedException
 *             If the scheme we try to activate is not defined.
 */
public void testDeletedBindingPlatform() throws NotDefinedException {
    final String na = "na";

    final Context context = contextManager.getContext(na);
    context.define("name", "description", null);

    final Scheme scheme = bindingManager.getScheme(na);
    scheme.define("name", "description", null);

    bindingManager.setActiveScheme(scheme);
    final Set activeContextIds = new HashSet();
    activeContextIds.add("na");
    contextManager.setActiveContextIds(activeContextIds);

    final Binding allPlatforms = new TestBinding("allPlatforms", na, na, null, null, Binding.SYSTEM, null);
    bindingManager.addBinding(allPlatforms);
    final Binding deletion = new TestBinding(null, na, na, null, Util.getWS(), Binding.SYSTEM, null);
    bindingManager.addBinding(deletion);
    final Binding platformSpecific = new TestBinding("platformSpecific", na, na, null, Util.getWS(),
            Binding.SYSTEM, null);
    bindingManager.addBinding(platformSpecific);
    assertEquals("We should be able to change a binding on a particular platform", platformSpecific,
            bindingManager.getPerfectMatch(TestBinding.TRIGGER_SEQUENCE));
}