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
(Adapt)
Line 7: Line 7:
 
The GEF4 Common component provides key concepts and infrastructure to be potentially used by all other GEF4 components.
 
The GEF4 Common component provides key concepts and infrastructure to be potentially used by all other GEF4 components.
  
== Adapt ==
+
== Adaptables ==
  
 
*'''package: org.eclipse.gef4.common.adapt'''
 
*'''package: org.eclipse.gef4.common.adapt'''

Revision as of 03:42, 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.

Adaptables

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

The adapt package provides a modernized interpretation of the adapter pattern, as provided by the Eclipse Core Runtime. In contrast to the "original" pattern, adapters may now be 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 transferred getAdapter(Class<? super T>) method now is just a convenience operation that will retrieve the adapter registered under the default role (or the only adapter registered under the given class, if there is only one adapter for that class key).

File:IAdaptable-IAdaptable.Bound-AdapterKey.png

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