Package 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 ofIAdaptable
supported by this class. If passed-in adapters implement theIAdaptable.Bound
interface, the generic type parameter ofIAdaptable.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 sourceIAdaptable
. It offers all methods defined byIAdaptable
, while not formally implementing the interface, and can thus be used by a sourceIAdaptable
as a delegate.
-
-
Constructor Summary
Constructors Constructor Description AdaptableSupport(A source)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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 thisAdaptableSupport
, which will unregister all currently registered adapters, unbind them from their sourceIAdaptable
(in case they areIAdaptable.Bound
), and dispose them (if they areIDisposable
).<T> T
getAdapter(TypeToken<T> key)
Returns an adapter for the givenTypeToken
key if one can unambiguously be retrieved.<T> T
getAdapter(java.lang.Class<T> key)
Returns an adapter for the givenClass
key if one can unambiguously be retrieved.<T> T
getAdapter(AdapterKey<T> key)
Returns an adapter for the givenAdapterKey
if one can unambiguously be retrieved, i.e. if there is only a single adapter registered under a key that 'matches' the givenAdapterKey
.<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 respectiveAdapterKey
s they are registered.<T> java.util.Map<AdapterKey<? extends T>,T>
getAdapters(TypeToken<? super T> key)
Returns all adapters 'matching' the givenTypeToken
key, i.e. all adapters whoseAdapterKey
'sTypeToken
keyAdapterKey.getKey()
) refers to the same or a sub-type or of the givenTypeToken
key.<T> java.util.Map<AdapterKey<? extends T>,T>
getAdapters(java.lang.Class<? super T> key)
Returns all adapters 'matching' the givenClass
key, i.e. all adapters whoseAdapterKey
'sTypeToken
keyAdapterKey.getKey()
) refers to the same or a sub-type of the givenClass
key.<T> void
setAdapter(TypeToken<T> adapterType, T adapter)
Registers the given adapter under anAdapterKey
, which will use the givenTypeToken
key as well as the default role (seeAdapterKey.DEFAULT_ROLE
.<T> void
setAdapter(TypeToken<T> adapterType, T adapter, java.lang.String role)
Registers the given adapter under the givenAdapterKey
.<T> void
setAdapter(T adapter)
Registers the given adapter under the default role (seeAdapterKey.DEFAULT_ROLE
.<T> void
setAdapter(T adapter, java.lang.String role)
Registers the given adapter under the given role .<T> void
unsetAdapter(T adapter)
Unregisters the adapter, returning it for convenience.
-
-
-
Constructor Detail
-
AdaptableSupport
public AdaptableSupport(A source)
- Parameters:
source
- TheIAdaptable
that encloses the to be createdAdaptableSupport
, delegating calls to it. May not benull
-
-
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.
-
dispose
public void dispose()
Disposes thisAdaptableSupport
, which will unregister all currently registered adapters, unbind them from their sourceIAdaptable
(in case they areIAdaptable.Bound
), and dispose them (if they areIDisposable
).- Specified by:
dispose
in interfaceIDisposable
-
getAdapter
public <T> T getAdapter(AdapterKey<T> key)
Returns an adapter for the givenAdapterKey
if one can unambiguously be retrieved, i.e. if there is only a single adapter registered under a key that 'matches' the givenAdapterKey
.- Type Parameters:
T
- The adapter type.- Parameters:
key
- TheAdapterKey
used to retrieve a registered adapter.- Returns:
- The unambiguously retrievable adapter for the given
AdapterKey
ornull
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 givenClass
key if one can unambiguously be retrieved. That is, if there is only a single adapter that 'matches' the givenClass
key, this adapter is returned, ignoring the role under which it is registered (seeAdapterKey.getRole()
).- Type Parameters:
T
- The adapter type.- Parameters:
key
- TheClass
key used to retrieve a registered adapter.- Returns:
- The unambiguously retrievable adapter for the given
Class
key ornull
if none could be retrieved. - See Also:
IAdaptable.getAdapter(Class)
-
getAdapter
public <T> T getAdapter(TypeToken<T> key)
Returns an adapter for the givenTypeToken
key if one can unambiguously be retrieved. That is, if there is only a single adapter that 'matches' the givenTypeToken
key, this adapter is returned, ignoring the role under which it is registered (seeAdapterKey.getRole()
).- Type Parameters:
T
- The adapter type.- Parameters:
key
- TheTypeToken
key used to retrieve a registered adapter.- Returns:
- The unambiguously retrievable adapter for the given
TypeToken
key ornull
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, ornull
if the adapter is not registered.
-
getAdapters
public javafx.collections.ObservableMap<AdapterKey<?>,java.lang.Object> getAdapters()
Retrieves all registered adapters, mapped to the respectiveAdapterKey
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 givenClass
key, i.e. all adapters whoseAdapterKey
'sTypeToken
keyAdapterKey.getKey()
) refers to the same or a sub-type of the givenClass
key.- Type Parameters:
T
- The adapter type.- Parameters:
key
- TheClass
key to retrieve adapters for.- Returns:
- A
Map
containing all those adapters registered at thisAdaptableSupport
, whoseAdapterKey
'sTypeToken
key (AdapterKey.getKey()
) refers to the same or a sub-type of the givenClass
key, qualified by their respectiveAdapterKey
s. - See Also:
IAdaptable.getAdapters(Class)
-
getAdapters
public <T> java.util.Map<AdapterKey<? extends T>,T> getAdapters(TypeToken<? super T> key)
Returns all adapters 'matching' the givenTypeToken
key, i.e. all adapters whoseAdapterKey
'sTypeToken
keyAdapterKey.getKey()
) refers to the same or a sub-type or of the givenTypeToken
key.- Type Parameters:
T
- The adapter type.- Parameters:
key
- TheTypeToken
key to retrieve adapters for.- Returns:
- A
Map
containing all those adapters registered at thisAdaptableSupport
, whoseAdapterKey
'sTypeToken
key (AdapterKey.getKey()
) refers to the same or a sub-type of the givenTypeToken
key, qualified by their respectiveAdapterKey
s. - See Also:
IAdaptable.getAdapters(TypeToken)
-
setAdapter
public <T> void setAdapter(T adapter)
Registers the given adapter under the default role (seeAdapterKey.DEFAULT_ROLE
.- Type Parameters:
T
- The adapter type.- Parameters:
adapter
- The adapter to register under the givenClass
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(TypeToken<T> adapterType, T adapter)
Registers the given adapter under anAdapterKey
, which will use the givenTypeToken
key as well as the default role (seeAdapterKey.DEFAULT_ROLE
.- Type Parameters:
T
- The adapter type.- Parameters:
adapterType
- TheTypeToken
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 givenAdapterKey
. TheAdapterKey
should provide the actual type of the adapter plus a role.- Type Parameters:
T
- The adapter type.- Parameters:
adapterType
- ATypeToken
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)
-
-