org.eclipse.gef.common.adapt

## Class AdaptableSupport<A extends IAdaptable>

- java.lang.Object
- - org.eclipse.gef.common.adapt.AdaptableSupport<A>

Type Parameters:
  `A` - The type of `IAdaptable` supported by this class. If passed-in adapters implement the `IAdaptable.Bound` interface, the generic type parameter of `IAdaptable.Bound` has to match this one.

All Implemented Interfaces:
  IDisposable

    public class AdaptableSupport<A extends IAdaptable>
    extends java.lang.Object
    implements IDisposable

A support class to manage adapters for a source `IAdaptable`. It offers all methods defined by `IAdaptable`, while not formally implementing the interface, and can thus be used by a source `IAdaptable` as a delegate.

### Property Summary

All Methods Instance Methods Concrete Methods
`javafx.beans.property.ReadOnlyMapProperty<AdapterKey<?>,java.lang.Object>` `adapters` Returns a read-only map property, containing the adapters mapped to their keys.

### Constructor Summary

Constructors
Constructor and Description
`AdaptableSupport(A source)` Creates a new `AdaptableSupport` for the given source `IAdaptable` and a related `PropertyChangeSupport`.

### Method Summary

All Methods Instance Methods Concrete Methods
`javafx.beans.property.ReadOnlyMapProperty<AdapterKey<?>,java.lang.Object>` `adaptersProperty()` Returns a read-only map property, containing the adapters mapped to their keys.
`void` `dispose()` Disposes this `AdaptableSupport`, which will unregister all currently registered adapters, unbind them from their source `IAdaptable` (in case they are `IAdaptable.Bound`), and dispose them (if they are `IDisposable`).
`<T> T` `getAdapter(AdapterKey<T> key)` Returns an adapter for the given `AdapterKey` if one can unambiguously be retrieved, i.e. if there is only a single adapter registered under a key that 'matches' the given `AdapterKey`.
`<T> T` `getAdapter(java.lang.Class<T> key)` Returns an adapter for the given `Class` key if one can unambiguously be retrieved.
`<T> T` `getAdapter(com.google.common.reflect.TypeToken<T> key)` Returns an adapter for the given `TypeToken` key if one can unambiguously be retrieved.
`<T> AdapterKey<T>` `getAdapterKey(T adapter)` Returns the key under which the given adapter is bound.
`javafx.collections.ObservableMap<AdapterKey<?>,java.lang.Object>` `getAdapters()` Retrieves all registered adapters, mapped to the respective `AdapterKey`s they are registered.
`<T> java.util.Map<AdapterKey<? extends T>,T>` `getAdapters(java.lang.Class<? super T> key)` Returns all adapters 'matching' the given `Class` key, i.e. all adapters whose `AdapterKey`'s `TypeToken` key `AdapterKey.getKey()`) refers to the same or a sub-type of the given `Class` key.
`<T> java.util.Map<AdapterKey<? extends T>,T>` `getAdapters(com.google.common.reflect.TypeToken<? super T> key)` Returns all adapters 'matching' the given `TypeToken` key, i.e. all adapters whose `AdapterKey`'s `TypeToken` key `AdapterKey.getKey()`) refers to the same or a sub-type or of the given `TypeToken` key.
`<T> void` `setAdapter(T adapter)` Registers the given adapter under the default role (see `AdapterKey.DEFAULT_ROLE`.
`<T> void` `setAdapter(T adapter, java.lang.String role)` Registers the given adapter under the given role .
`<T> void` `setAdapter(com.google.common.reflect.TypeToken<T> adapterType, T adapter)` Registers the given adapter under an `AdapterKey`, which will use the given `TypeToken` key as well as the default role (see `AdapterKey.DEFAULT_ROLE`.
`<T> void` `setAdapter(com.google.common.reflect.TypeToken<T> adapterType, T adapter, java.lang.String role)` Registers the given adapter under the given `AdapterKey`.
`<T> void` `unsetAdapter(T adapter)` Unregisters the adapter, returning it for convenience.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Property Detail

#### adapters

    public javafx.beans.property.ReadOnlyMapProperty<AdapterKey<?>,java.lang.Object> adaptersProperty

Returns a read-only map property, containing the adapters mapped to their keys.

See Also:
  `getAdapters()`

### Constructor Detail

#### AdaptableSupport

    public AdaptableSupport(A source)

Creates a new `AdaptableSupport` for the given source `IAdaptable` and a related `PropertyChangeSupport`.

Parameters:
  `source` - The `IAdaptable` that encloses the to be created `AdaptableSupport`, delegating calls to it. May not be `null`

### Method Detail

#### adaptersProperty

    public javafx.beans.property.ReadOnlyMapProperty<AdapterKey<?>,java.lang.Object> adaptersProperty()

Returns a read-only map property, containing the adapters mapped to their keys.

See Also:
  `getAdapters()`

#### dispose

    public void dispose()

Disposes this `AdaptableSupport`, which will unregister all currently registered adapters, unbind them from their source `IAdaptable` (in case they are `IAdaptable.Bound`), and dispose them (if they are `IDisposable`).

Specified by:
  `dispose` in interface `IDisposable`

#### getAdapter

    public <T> T getAdapter(AdapterKey<T> key)

Returns an adapter for the given `AdapterKey` if one can unambiguously be retrieved, i.e. if there is only a single adapter registered under a key that 'matches' the given `AdapterKey`.

Type Parameters:
  `T` - The adapter type.
Parameters:
  `key` - The `AdapterKey` used to retrieve a registered adapter.
Returns:
  The unambiguously retrievable adapter for the given `AdapterKey` or `null` if none could be retrieved.
See Also:
  `IAdaptable.getAdapter(AdapterKey)`

#### getAdapter

    public <T> T getAdapter(java.lang.Class<T> key)

Returns an adapter for the given `Class` key if one can unambiguously be retrieved. That is, if there is only a single adapter that 'matches' the given `Class` key, this adapter is returned, ignoring the role under which it is registered (see `AdapterKey.getRole()`).

Type Parameters:
  `T` - The adapter type.
Parameters:
  `key` - The `Class` key used to retrieve a registered adapter.
Returns:
  The unambiguously retrievable adapter for the given `Class` key or `null` if none could be retrieved.
See Also:
  `IAdaptable.getAdapter(Class)`

#### getAdapter

    public <T> T getAdapter(com.google.common.reflect.TypeToken<T> key)

Returns an adapter for the given `TypeToken` key if one can unambiguously be retrieved. That is, if there is only a single adapter that 'matches' the given `TypeToken` key, this adapter is returned, ignoring the role under which it is registered (see `AdapterKey.getRole()`).

Type Parameters:
  `T` - The adapter type.
Parameters:
  `key` - The `TypeToken` key used to retrieve a registered adapter.
Returns:
  The unambiguously retrievable adapter for the given `TypeToken` key or `null` if none could be retrieved.
See Also:
  `IAdaptable.getAdapter(TypeToken)`

#### getAdapterKey

    public <T> AdapterKey<T> getAdapterKey(T adapter)

Returns the key under which the given adapter is bound.

Type Parameters:
  `T` - The adapter type.
Parameters:
  `adapter` - The adapter whose key to retrieve.
Returns:
  The `AdapterKey` under which the respective adapter is bound, or `null` if the adapter is not registered.

#### getAdapters

    public javafx.collections.ObservableMap<AdapterKey<?>,java.lang.Object> getAdapters()

Retrieves all registered adapters, mapped to the respective `AdapterKey`s they are registered.

Returns:
  An unmodifiable observable map containing the registered adapters under their `AdapterKey`s as a copy.

#### getAdapters

    public <T> java.util.Map<AdapterKey<? extends T>,T> getAdapters(java.lang.Class<? super T> key)

Returns all adapters 'matching' the given `Class` key, i.e. all adapters whose `AdapterKey`'s `TypeToken` key `AdapterKey.getKey()`) refers to the same or a sub-type of the given `Class` key.

Type Parameters:
  `T` - The adapter type.
Parameters:
  `key` - The `Class` key to retrieve adapters for.
Returns:
  A `Map` containing all those adapters registered at this `AdaptableSupport`, whose `AdapterKey`'s `TypeToken` key (`AdapterKey.getKey()`) refers to the same or a sub-type of the given `Class` key, qualified by their respective `AdapterKey`s.
See Also:
  `IAdaptable.getAdapters(Class)`

#### getAdapters

    public <T> java.util.Map<AdapterKey<? extends T>,T> getAdapters(com.google.common.reflect.TypeToken<? super T> key)

Returns all adapters 'matching' the given `TypeToken` key, i.e. all adapters whose `AdapterKey`'s `TypeToken` key `AdapterKey.getKey()`) refers to the same or a sub-type or of the given `TypeToken` key.

Type Parameters:
  `T` - The adapter type.
Parameters:
  `key` - The `TypeToken` key to retrieve adapters for.
Returns:
  A `Map` containing all those adapters registered at this `AdaptableSupport`, whose `AdapterKey`'s `TypeToken` key (`AdapterKey.getKey()`) refers to the same or a sub-type of the given `TypeToken` key, qualified by their respective `AdapterKey`s.
See Also:
  `IAdaptable.getAdapters(TypeToken)`

#### setAdapter

    public <T> void setAdapter(T adapter)

Registers the given adapter under the default role (see `AdapterKey.DEFAULT_ROLE`.

Type Parameters:
  `T` - The adapter type.
Parameters:
  `adapter` - The adapter to register under the given `Class` key.
See Also:
  `IAdaptable.setAdapter(TypeToken, Object)`

#### setAdapter

    public <T> void setAdapter(T adapter,
                               java.lang.String role)

Registers the given adapter under the given role .

Type Parameters:
  `T` - The adapter type.
Parameters:
  `adapter` - The adapter to register.
  `role` - The role to register this adapter with.
See Also:
  `IAdaptable.setAdapter(TypeToken, Object)`

#### setAdapter

    public <T> void setAdapter(com.google.common.reflect.TypeToken<T> adapterType,
                               T adapter)

Registers the given adapter under an `AdapterKey`, which will use the given `TypeToken` key as well as the default role (see `AdapterKey.DEFAULT_ROLE`.

Type Parameters:
  `T` - The adapter type.
Parameters:
  `adapterType` - The `TypeToken` reflecting the actual type of the adapter.
  `adapter` - The adapter to register.

#### setAdapter

    public <T> void setAdapter(com.google.common.reflect.TypeToken<T> adapterType,
                               T adapter,
                               java.lang.String role)

Registers the given adapter under the given `AdapterKey`. The `AdapterKey` should provide the actual type of the adapter plus a role.

Type Parameters:
  `T` - The adapter type.
Parameters:
  `adapterType` - A `TypeToken` representing the actual type of the given adapter.
  `adapter` - The adapter to register.
  `role` - The role under which to register the adapter.

#### unsetAdapter

    public <T> void unsetAdapter(T adapter)

Unregisters the adapter, returning it for convenience.

Type Parameters:
  `T` - The adapter type.
Parameters:
  `adapter` - The adapter to unregister.
See Also:
  `IAdaptable.unsetAdapter(Object)`