Class AdaptableSupport<A extends IAdaptable>

  • 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.
    • 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.
        Returns:
        A read-only map property.
      • 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​(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 AdapterKeys they are registered.
        Returns:
        An unmodifiable observable map containing the registered adapters under their AdapterKeys as a copy.
      • 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​(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,
                                   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)