# Class Binding

java.lang.Object
org.eclipse.jface.bindings.Binding

Direct Known Subclasses:
  `KeyBinding`

public abstract class Binding extends Object

A binding is a link between user input and the triggering of a particular command. The most common example of a binding is a keyboard shortcut, but there are also mouse and gesture bindings.

Bindings are linked to particular conditions within the application. Some of these conditions change infrequently (e.g., locale, scheme), while some will tend to change quite frequently (e.g., context). This allows the bindings to be tailored to particular situations. For example, a set of bindings may be appropriate only inside a text editor. Or, perhaps, a set of bindings might be appropriate only for a given locale, such as bindings that coexist with the Input Method Editor (IME) on Chinese locales.

It is also possible to remove a particular binding. This is typically done as part of user configuration (e.g., user changing keyboard shortcuts). However, it can also be helpful when trying to change a binding on a particular locale or platform. An "unbinding" is really just a binding with no command identifier. For it to unbind a particular binding, it must match that binding in its context identifier and scheme identifier. Subclasses (e.g., `KeyBinding`) may require other properties to match (e.g., `keySequence`). If these properties match, then this is an unbinding. Note: the locale and platform can be different.

For example, imagine you have a key binding that looks like this:

    KeyBinding(command, scheme, context, "Ctrl+Shift+F")

On GTK+, the "Ctrl+Shift+F" interferes with some native behaviour. To change the binding, we first unbind the "Ctrl+Shift+F" key sequence by assigning it a null command on the gtk platform. We then create a new binding that maps the command to the "Esc Ctrl+F" key sequence.

        KeyBinding("Ctrl+Shift+F",null,scheme,context,null,gtk,null,SYSTEM)
        KeyBinding("Esc Ctrl+F",parameterizedCommand,scheme,context,null,gtk,SYSTEM)

Bindings are intended to be immutable objects.

Since:
  3.1

## Field Summary

Fields
Modifier and Type
Field
Description
`protected String`
`string`
The string representation of this binding.
`static final int`
`SYSTEM`
The type of binding that is defined by the system (i.e., by the application developer).
`static final int`
`USER`
The type of binding that is defined by the user (i.e., by the end user of the application).

## Constructor Summary

Constructors
Modifier
Constructor
Description
`protected`
`Binding(ParameterizedCommand command, String schemeId, String contextId, String locale, String platform, String windowManager, int type)`
Constructs a new instance of `Binding`.

## Method Summary

Modifier and Type
Method
Description
`final boolean`
`equals(Object object)`
Tests whether this binding is equal to another object.
`final String`
`getContextId()`
Returns the identifier of the context in which this binding applies.
`final String`
`getLocale()`
Returns the locale in which this binding applies.
`final ParameterizedCommand`
`getParameterizedCommand()`
Returns the parameterized command to which this binding applies.
`final String`
`getPlatform()`
Returns the platform on which this binding applies.
`final String`
`getSchemeId()`
Returns the identifier of the scheme in which this binding applies.
`abstract TriggerSequence`
`getTriggerSequence()`
Returns the sequence of trigger for a given binding.
`final int`
`getType()`
Returns the type for this binding.
`final int`
`hashCode()`
Computes the hash code for this key binding based on all of its attributes.
`String`
`toString()`
The string representation of this binding -- for debugging purposes only.

### Methods inherited from class Object

`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

## Field Details

### SYSTEM

public static final int SYSTEM
The type of binding that is defined by the system (i.e., by the application developer). In the case of an application based on the Eclipse workbench, this is the registry.

See Also:
  - Constant Field Values

### USER

public static final int USER
The type of binding that is defined by the user (i.e., by the end user of the application). In the case of an application based on the Eclipse workbench, this is the preference store.

See Also:
  - Constant Field Values

### string

protected transient String string
The string representation of this binding. This string is for debugging purposes only, and is not meant to be displayed to the user. This value is computed lazily.

## Constructor Details

### Binding

protected Binding(ParameterizedCommand command, String schemeId, String contextId, String locale, String platform, String windowManager, int type)
Constructs a new instance of `Binding`.

Parameters:
  `command` - The parameterized command to which this binding applies; this value may be `null` if the binding is meant to "unbind" a previously defined binding.
  `schemeId` - The scheme to which this binding belongs; this value must not be `null`.
  `contextId` - The context to which this binding applies; this value must not be `null`.
  `locale` - The locale to which this binding applies; this value may be `null` if it applies to all locales.
  `platform` - The platform to which this binding applies; this value may be `null` if it applies to all platforms.
  `windowManager` - The window manager to which this binding applies; this value may be `null` if it applies to all window managers. This value is currently ignored.
  `type` - The type of binding. This should be either `SYSTEM` or `USER`.

## Method Details

### equals

public final boolean equals(Object object)
Tests whether this binding is equal to another object. Bindings are only equal to other bindings with equivalent values.

Overrides:
  `equals` in class `Object`
Parameters:
  `object` - The object with which to compare; may be `null`.
Returns:
  `true` if the object is a binding with equivalent values for all of its properties; `false` otherwise.

### getParameterizedCommand

public final ParameterizedCommand getParameterizedCommand()
Returns the parameterized command to which this binding applies. If the identifier is `null`, then this binding is "unbinding" an existing binding.

Returns:
  The fully-parameterized command; may be `null`.

### getContextId

public final String getContextId()
Returns the identifier of the context in which this binding applies.

Returns:
  The context identifier; never `null`.

### getLocale

public final String getLocale()
Returns the locale in which this binding applies. If the locale is `null`, then this binding applies to all locales. This string is the same format as returned by `Locale.getDefault().toString()`.

Returns:
  The locale; may be `null`.

### getPlatform

public final String getPlatform()
Returns the platform on which this binding applies. If the platform is `null`, then this binding applies to all platforms. This string is the same format as returned by `SWT.getPlatform()`.

Returns:
  The platform; may be `null`.

### getSchemeId

public final String getSchemeId()
Returns the identifier of the scheme in which this binding applies.

Returns:
  The scheme identifier; never `null`.

### getTriggerSequence

public abstract TriggerSequence getTriggerSequence()
Returns the sequence of trigger for a given binding. The triggers can be anything, but above all it must be hashable. This trigger sequence is used by the binding manager to distinguish between different bindings.

Returns:
  The object representing an input event that will trigger this binding; must not be `null`.

### getType

public final int getType()
Returns the type for this binding. As it stands now, this value will either be `SYSTEM` or `USER`. In the future, more types might be added.

Returns:
  The type for this binding.

### hashCode

public final int hashCode()
Computes the hash code for this key binding based on all of its attributes.

Overrides:
  `hashCode` in class `Object`
Returns:
  The hash code for this key binding.

### toString

public String toString()
The string representation of this binding -- for debugging purposes only. This string should not be shown to an end user. This should be overridden by subclasses that add properties.

Overrides:
  `toString` in class `Object`
Returns:
  The string representation; never `null`.