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

E4/Doc/Adapting Objects

< E4‎ | Doc

THIS IS OLD DOCUMENTATION THAT DOES NOT FOLLOW THE NEW FORMAT AND HAS NOT HAD A "SERVICE INTERVIEW" PERFORMED.

Under Construction: Please read first!

The evolution of this document is a collaborative effort between a team of students at the University of Manitoba and the wider Eclipse community. Details about the project can be found here and on our Blog.

Your input is not just welcome; it is needed! Please contribute as your expertise allows, while adhering to our template. To send your feedback and any questions or comments you may have please email us. Also, while we do our very best to be as accurate and precise as possible, it is worth noting that we are students with limited exposure to the Eclipse platform, so if you see any incorrect technical details please let us know.

Description

The Adapting Objects service allows a consumer to access shared data in a relevant way within the current context. Classes can retrieve information about various objects by adapting them to the applicable model. For example, a Javadoc view can access information necessary to render javadoc of the selected class, while an Overview view can access the structure of the class necessary to render a tree.

Consumer

In order for a class to be able to adapt an object, there needs to be a respective ModelEditor. The ModelEditor implements two interfaces which are essential for the Adapting Objects service: IAdaptable and IModelProvider. Once the ModelEditor is implemented, a client class can access the adapted object without casting.

Usage

Code Samples

Java

Getting an IAdapterManager
The adapter manager can be easily queried for by asking the Eclipse context.
private IAdapterManager getAdapterManager(IEclipseContext context) {
  return (IAdapterManager) context.get(IAdapterManager.class.getName());
}
Creating a ModelEditor
public interface IAdaptable {
 
  public <T> T getAdapter(Class<T> cls);
 
}
 
public interface IModelProvider {
 
  public Model getModel();
 
}
 
public class ModelEditor implements IAdaptable, IModelProvider {
 
  private Model model;
 
  public Model getModel() {
    return model;
  }
 
  public <T> T getAdapter(Class<T> adapter) {
    if (adapter == IModelProvider.class) {
      return (T) this;
    }
    return null;
  }
}
Adapting Objects
IModelProvider modelProvider = editor.getAdapter(IModelProvider.class);
if (modelProvider != null) {
  // do something with it
}

Related Materials

Related Services

Related API's

it would be nice to link to some actual api docs, but alas they don't live anywhere yet

See Also

Back to the top