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 ofIAdaptablesupported by this class. If passed-in adapters implement theIAdaptable.Boundinterface, the generic type parameter ofIAdaptable.Boundhas 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 sourceIAdaptableas 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.voiddispose()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> TgetAdapter(TypeToken<T> key)Returns an adapter for the givenTypeTokenkey if one can unambiguously be retrieved.<T> TgetAdapter(java.lang.Class<T> key)Returns an adapter for the givenClasskey if one can unambiguously be retrieved.<T> TgetAdapter(AdapterKey<T> key)Returns an adapter for the givenAdapterKeyif 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 respectiveAdapterKeys they are registered.<T> java.util.Map<AdapterKey<? extends T>,T>getAdapters(TypeToken<? super T> key)Returns all adapters 'matching' the givenTypeTokenkey, i.e. all adapters whoseAdapterKey'sTypeTokenkeyAdapterKey.getKey()) refers to the same or a sub-type or of the givenTypeTokenkey.<T> java.util.Map<AdapterKey<? extends T>,T>getAdapters(java.lang.Class<? super T> key)Returns all adapters 'matching' the givenClasskey, i.e. all adapters whoseAdapterKey'sTypeTokenkeyAdapterKey.getKey()) refers to the same or a sub-type of the givenClasskey.<T> voidsetAdapter(TypeToken<T> adapterType, T adapter)Registers the given adapter under anAdapterKey, which will use the givenTypeTokenkey as well as the default role (seeAdapterKey.DEFAULT_ROLE.<T> voidsetAdapter(TypeToken<T> adapterType, T adapter, java.lang.String role)Registers the given adapter under the givenAdapterKey.<T> voidsetAdapter(T adapter)Registers the given adapter under the default role (seeAdapterKey.DEFAULT_ROLE.<T> voidsetAdapter(T adapter, java.lang.String role)Registers the given adapter under the given role .<T> voidunsetAdapter(T adapter)Unregisters the adapter, returning it for convenience.
-
-
-
Constructor Detail
-
AdaptableSupport
public AdaptableSupport(A source)
- Parameters:
source- TheIAdaptablethat 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:
disposein interfaceIDisposable
-
getAdapter
public <T> T getAdapter(AdapterKey<T> key)
Returns an adapter for the givenAdapterKeyif 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- TheAdapterKeyused to retrieve a registered adapter.- Returns:
- The unambiguously retrievable adapter for the given
AdapterKeyornullif none could be retrieved. - See Also:
IAdaptable.getAdapter(AdapterKey)
-
getAdapter
public <T> T getAdapter(java.lang.Class<T> key)
Returns an adapter for the givenClasskey if one can unambiguously be retrieved. That is, if there is only a single adapter that 'matches' the givenClasskey, this adapter is returned, ignoring the role under which it is registered (seeAdapterKey.getRole()).- Type Parameters:
T- The adapter type.- Parameters:
key- TheClasskey used to retrieve a registered adapter.- Returns:
- The unambiguously retrievable adapter for the given
Classkey ornullif none could be retrieved. - See Also:
IAdaptable.getAdapter(Class)
-
getAdapter
public <T> T getAdapter(TypeToken<T> key)
Returns an adapter for the givenTypeTokenkey if one can unambiguously be retrieved. That is, if there is only a single adapter that 'matches' the givenTypeTokenkey, this adapter is returned, ignoring the role under which it is registered (seeAdapterKey.getRole()).- Type Parameters:
T- The adapter type.- Parameters:
key- TheTypeTokenkey used to retrieve a registered adapter.- Returns:
- The unambiguously retrievable adapter for the given
TypeTokenkey ornullif 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
AdapterKeyunder which the respective adapter is bound, ornullif the adapter is not registered.
-
getAdapters
public javafx.collections.ObservableMap<AdapterKey<?>,java.lang.Object> getAdapters()
Retrieves all registered adapters, mapped to the respectiveAdapterKeys they are registered.- Returns:
- An unmodifiable observable map containing the registered adapters
under their
AdapterKeys 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 givenClasskey, i.e. all adapters whoseAdapterKey'sTypeTokenkeyAdapterKey.getKey()) refers to the same or a sub-type of the givenClasskey.- Type Parameters:
T- The adapter type.- Parameters:
key- TheClasskey to retrieve adapters for.- Returns:
- A
Mapcontaining all those adapters registered at thisAdaptableSupport, whoseAdapterKey'sTypeTokenkey (AdapterKey.getKey()) refers to the same or a sub-type of the givenClasskey, qualified by their respectiveAdapterKeys. - 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 givenTypeTokenkey, i.e. all adapters whoseAdapterKey'sTypeTokenkeyAdapterKey.getKey()) refers to the same or a sub-type or of the givenTypeTokenkey.- Type Parameters:
T- The adapter type.- Parameters:
key- TheTypeTokenkey to retrieve adapters for.- Returns:
- A
Mapcontaining all those adapters registered at thisAdaptableSupport, whoseAdapterKey'sTypeTokenkey (AdapterKey.getKey()) refers to the same or a sub-type of the givenTypeTokenkey, qualified by their respectiveAdapterKeys. - 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 givenClasskey.- 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 givenTypeTokenkey as well as the default role (seeAdapterKey.DEFAULT_ROLE.- Type Parameters:
T- The adapter type.- Parameters:
adapterType- TheTypeTokenreflecting 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. TheAdapterKeyshould provide the actual type of the adapter plus a role.- Type Parameters:
T- The adapter type.- Parameters:
adapterType- ATypeTokenrepresenting 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)
-
-