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 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 Details

  • Constructor Details

  • Method Details

    • adaptersProperty

      public ReadOnlyMapProperty<AdapterKey<?>,Object> adaptersProperty()
      Returns a read-only map property, containing the adapters mapped to their keys.
      See Also:
    • 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:
    • getAdapter

      public <T> T getAdapter(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:
    • getAdapter

      public <T> T getAdapter(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:
    • 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 ObservableMap<AdapterKey<?>,Object> getAdapters()
      Retrieves all registered adapters, mapped to the respective AdapterKeys they are registered.
      Returns:
      An unmodifiable observable map containing the registered adapters under their AdapterKeys as a copy.
    • getAdapters

      public <T> Map<AdapterKey<? extends T>,T> getAdapters(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 AdapterKeys.
      See Also:
    • getAdapters

      public <T> Map<AdapterKey<? extends T>,T> getAdapters(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 AdapterKeys.
      See Also:
    • 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:
    • setAdapter

      public <T> void setAdapter(T adapter, 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:
    • setAdapter

      public <T> void setAdapter(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(TypeToken<T> adapterType, T adapter, 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: