Class AdapterStore
- java.lang.Object
-
- org.eclipse.gef.common.adapt.AdapterStore
-
- All Implemented Interfaces:
IAdaptable
public class AdapterStore extends java.lang.Object implements IAdaptable
AnAdapterStore
is a basicIAdaptable
implementation that can be used standalone.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.eclipse.gef.common.adapt.IAdaptable
IAdaptable.Bound<A extends IAdaptable>
-
-
Field Summary
-
Fields inherited from interface org.eclipse.gef.common.adapt.IAdaptable
ADAPTERS_PROPERTY
-
-
Constructor Summary
Constructors Constructor Description AdapterStore()
Creates a newAdapterStore
with no initial adapters.AdapterStore(TypeToken<T> adapterType, T adapter)
Creates a new AdapterStore with the single given initial adapter, using the 'default' role.AdapterStore(TypeToken<T> adapterType, T adapter, java.lang.String role)
Creates a new AdapterStore with the single given initial adapter.AdapterStore(T adapter)
Creates a new AdapterStore with the single given initial adapter, using the 'default' role.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description javafx.beans.property.ReadOnlyMapProperty<AdapterKey<?>,java.lang.Object>
adaptersProperty()
Returns an unmodifiable read-only map property that contains the registered adapters by their keys.void
clear()
Removes all registered adapters from thisAdapterStore
.<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 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()
Returns an unmodifiableObservableMap
that contains the registered adapters by their keys.<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 the 'default' role (seeAdapterKey.DEFAULT_ROLE
.<T> void
setAdapter(TypeToken<T> adapterType, T adapter, java.lang.String role)
Registers the given adapter under the given role.<T> void
setAdapter(T adapter)
Registers the given adapter under anAdapterKey
, which takes the given raw type key as well as 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 given adapter under all keys it was registered for.
-
-
-
Constructor Detail
-
AdapterStore
public AdapterStore()
Creates a newAdapterStore
with no initial adapters.
-
AdapterStore
public AdapterStore(T adapter)
Creates a new AdapterStore with the single given initial adapter, using the 'default' role.- Type Parameters:
T
- The adapter type.- Parameters:
adapter
- The adapter to be registered.
-
AdapterStore
public AdapterStore(TypeToken<T> adapterType, T adapter)
Creates a new AdapterStore with the single given initial adapter, using the 'default' role.- Type Parameters:
T
- The adapter type.- Parameters:
adapterType
- The runtime type of the adapter to be registered.adapter
- The adapter to be registered.
-
AdapterStore
public AdapterStore(TypeToken<T> adapterType, T adapter, java.lang.String role)
Creates a new AdapterStore with the single given initial adapter.- Type Parameters:
T
- The adapter type.- Parameters:
adapterType
- The runtime type of the adapter to be registered.adapter
- The adapter to be registered.role
- The role under which the adapter is to be registered.
-
-
Method Detail
-
adaptersProperty
public javafx.beans.property.ReadOnlyMapProperty<AdapterKey<?>,java.lang.Object> adaptersProperty()
Description copied from interface:IAdaptable
Returns an unmodifiable read-only map property that contains the registered adapters by their keys.- Specified by:
adaptersProperty
in interfaceIAdaptable
- Returns:
- An unmodifiable read-only map property.
-
clear
public void clear()
Removes all registered adapters from thisAdapterStore
.
-
getAdapter
public <T> T getAdapter(AdapterKey<T> key)
Description copied from interface:IAdaptable
Returns an adapter for the givenAdapterKey
if one can unambiguously be retrieved, i.e. if there is only a single adapter that 'matches' the givenAdapterKey
.An adapter 'matching' the
AdapterKey
is an adapter, which is registered with anAdapterKey
, whoseTypeToken
key (AdapterKey.getKey()
) refers to the same type or a sub-type of the givenAdapterKey
'sTypeToken
key and whose role (AdapterKey.getRole()
)) equals the role of the givenAdapterKey
's role.If there is more than one adapter that 'matches' the given
AdapterKey
, or there is no one 'matching' it,null
will be returned.- Specified by:
getAdapter
in interfaceIAdaptable
- 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.
-
getAdapter
public <T> T getAdapter(java.lang.Class<T> key)
Description copied from interface:IAdaptable
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()
).An adapter 'matching' the
Class
key is an adapter, which is registered with anAdapterKey
, whose key (AdapterKey.getKey()
) refers to the same type or a sub-type of the givenClass
key.If there is more than one adapter that 'matches' the given
Class
key, it will return the single adapter that is registered for the default role (AdapterKey.DEFAULT_ROLE
), if there is a single adapter for which this holds. Otherwise it will returnnull
.- Specified by:
getAdapter
in interfaceIAdaptable
- 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.
-
getAdapter
public <T> T getAdapter(TypeToken<T> key)
Description copied from interface:IAdaptable
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()
).An adapter 'matching' the
TypeToken
key is an adapter, which is registered with anAdapterKey
, whose key (AdapterKey.getKey()
) refers to the same type or a sub-type of the given type key.If there is more than one adapter that 'matches' the given
TypeToken
key, it will return the single adapter that is registered for the default role (AdapterKey.DEFAULT_ROLE
), if there is a single adapter for which this holds. Otherwise it will returnnull
.- Specified by:
getAdapter
in interfaceIAdaptable
- 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.
-
getAdapterKey
public <T> AdapterKey<T> getAdapterKey(T adapter)
Description copied from interface:IAdaptable
Returns the key under which the given adapter is bound.- Specified by:
getAdapterKey
in interfaceIAdaptable
- 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()
Description copied from interface:IAdaptable
Returns an unmodifiableObservableMap
that contains the registered adapters by their keys.- Specified by:
getAdapters
in interfaceIAdaptable
- Returns:
- An unmodifiable
ObservableMap
.
-
getAdapters
public <T> java.util.Map<AdapterKey<? extends T>,T> getAdapters(java.lang.Class<? super T> key)
Description copied from interface:IAdaptable
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.- Specified by:
getAdapters
in interfaceIAdaptable
- Type Parameters:
T
- The adapter type.- Parameters:
key
- TheClass
key to retrieve adapters for.- Returns:
- A
Map
containing all those adapters registered at thisIAdaptable
, 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.getAdapter(Class)
-
getAdapters
public <T> java.util.Map<AdapterKey<? extends T>,T> getAdapters(TypeToken<? super T> key)
Description copied from interface:IAdaptable
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.- Specified by:
getAdapters
in interfaceIAdaptable
- Type Parameters:
T
- The adapter type.- Parameters:
key
- TheTypeToken
key to retrieve adapters for.- Returns:
- A
Map
containing all those adapters registered at thisIAdaptable
, 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.getAdapter(TypeToken)
-
setAdapter
public <T> void setAdapter(T adapter)
Description copied from interface:IAdaptable
Registers the given adapter under anAdapterKey
, which takes the given raw type key as well as the 'default' role (seeAdapterKey.DEFAULT_ROLE
. The adapter may afterwards be retrieved by any type key 'in between' the given key type and actual raw type. If the actual type of the parameter is not a raw type but a parameterized type, it is not legitimate to use this method.If the given adapter implements
IAdaptable.Bound
, the adapter will obtain a back-reference to thisIAdaptable
via itsIAdaptable.Bound.setAdaptable(IAdaptable)
method.- Specified by:
setAdapter
in interfaceIAdaptable
- Type Parameters:
T
- The adapter type.- Parameters:
adapter
- The adapter to register under the givenClass
key.- See Also:
IAdaptable.setAdapter(Object, String)
-
setAdapter
public <T> void setAdapter(T adapter, java.lang.String role)
Description copied from interface:IAdaptable
Registers the given adapter under the given role .- Specified by:
setAdapter
in interfaceIAdaptable
- 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)
Description copied from interface:IAdaptable
Registers the given adapter under the 'default' role (seeAdapterKey.DEFAULT_ROLE
.If the given adapter implements
IAdaptable.Bound
, the adapter will obtain a back-reference to thisIAdaptable
via itsIAdaptable.Bound.setAdaptable(IAdaptable)
method.- Specified by:
setAdapter
in interfaceIAdaptable
- Type Parameters:
T
- The adapter type.- Parameters:
adapterType
- TheTypeToken
under which to register the given adapter, which should reflect the actual adapter type.adapter
- The adapter to register under the givenTypeToken
key.- See Also:
IAdaptable.setAdapter(TypeToken, Object, String)
-
setAdapter
@InjectAdapters public <T> void setAdapter(TypeToken<T> adapterType, T adapter, java.lang.String role)
Description copied from interface:IAdaptable
Registers the given adapter under the given role.If the given adapter implements
IAdaptable.Bound
, the adapter will obtain a back-reference to thisIAdaptable
via itsIAdaptable.Bound.setAdaptable(IAdaptable)
method.- Specified by:
setAdapter
in interfaceIAdaptable
- 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)
Description copied from interface:IAdaptable
Unregisters the given adapter under all keys it was registered for.If the given adapter implements
IAdaptable.Bound
, the back-reference to thisIAdaptable
will be removed via itsIAdaptable.Bound.setAdaptable(IAdaptable)
method, passing overnull
.- Specified by:
unsetAdapter
in interfaceIAdaptable
- Type Parameters:
T
- The adapter type.- Parameters:
adapter
- The adapter which should be removed.
-
-