Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "GEF/GEF4/Common"

< GEF‎ | GEF4
(Adaptables)
Line 14: Line 14:
  
 
[[File:IAdaptable-IAdaptable.Bound-AdapterKey.png]]
 
[[File:IAdaptable-IAdaptable.Bound-AdapterKey.png]]
 +
 +
Adapters are registered at an IAdaptable with an AdapterKey, which combines a class key with an (optional) role. This way, adapters can be retrieved from an IAdaptable in a type-safe manner, while multiple adapters may be registered under the same class key (using different roles). The
 +
 +
If an adapter that is set/unset at an IAdaptable implements IAdaptable.Bound, the IAdaptable is responsible of setting/unsetting a back reference to itself on the adapter:
 +
 +
<source lang="java">
 +
public <T> void setAdapter(AdapterKey<? super T> key, T adapter) {
 +
  ...
 +
  if (adapter instanceof IAdaptable.Bound) {
 +
    ((IAdaptable.Bound<A>) adapter).setAdaptable(this);
 +
  ...
 +
}
 +
 +
public <T> T unsetAdapter(AdapterKey<? super T> key) {
 +
  ...
 +
  if (adapter instanceof IAdaptable.Bound) {
 +
    ((IAdaptable.Bound<A>) adapter).setAdaptable(null);
 +
  }
 +
  ...
 +
}
 +
</source>

Revision as of 03:26, 3 November 2014

Note to non-wiki readers: This documentation is generated from the Eclipse wiki - if you have corrections or additions it would be awesome if you added them in the original wiki page.


Introduction

The GEF4 Common component provides key concepts and infrastructure to be potentially used by all other GEF4 components.

Adapt

  • package: org.eclipse.gef4.common.adapt

The adapt package provides a modernized interpretation of the adapter pattern, as provided by the Eclipse Core Runtime.

File:IAdaptable-IAdaptable.Bound-AdapterKey.png

Adapters are registered at an IAdaptable with an AdapterKey, which combines a class key with an (optional) role. This way, adapters can be retrieved from an IAdaptable in a type-safe manner, while multiple adapters may be registered under the same class key (using different roles). The

If an adapter that is set/unset at an IAdaptable implements IAdaptable.Bound, the IAdaptable is responsible of setting/unsetting a back reference to itself on the adapter:

public <T> void setAdapter(AdapterKey<? super T> key, T adapter) {
  ...
  if (adapter instanceof IAdaptable.Bound) {
    ((IAdaptable.Bound<A>) adapter).setAdaptable(this);
  ...
}
 
public <T> T unsetAdapter(AdapterKey<? super T> key) {
  ...
  if (adapter instanceof IAdaptable.Bound) {
    ((IAdaptable.Bound<A>) adapter).setAdaptable(null);
  }
  ...
}

Back to the top