The Eclipse 4 Application Platform uses a context to record the state used for injection. Normally code should not have to use or know about the context.
What is a Context?
A context (a IEclipseContext) is a transient key-value map with a parent, such that contexts are linked together to form a tree structure. When a key is not found in a context, the lookup is retried on the parent, repeating until either a value is found or the root of the tree has been reached.
Contexts are used as the sources for Dependency Injection.
The Use of Contexts in Eclipse 4
The power of contexts comes as Eclipse 4 associates a context with most model elements, such as that the context tree matches the UI hierarchy. So an MPart, its MPerspective, its MWindow, and its MApplication all have a separate contexts. Looking up a key that is not found in the part will cause the lookup to continue at the perspective, window, and application. At the top of the tree is a special node that looks up keys among the available OSGi services. Many application-, window-, and view-level services are installed by the Eclipse 4 at various levels in the context hierarchy. Thus the placement of values within the context hierarchy, such as in the perspective or window's context, provides a natural form of variable scoping.
Being able to resolve a value from somewhere in the context hierarchyis very powerful. But to change the value, we need to know where in the context hierarchy the value should be set. Rather than hard code this location, we can instead declare a context variable: we declare the variable at the appropriate context, and instead modify, rather than set, the context value: the context then looks up the chain to find the variable declaration and sets the value there. This separates defining where a context value should be placed from the code that's actually setting it.
- the context chain and the active context
- getting and setting variables vs modifying a variable
- run and tracks
- creating a context
- context functions
- creating a context
- when are contexts created?
- how do I access the current context?
Integrate stuff from http://wiki.eclipse.org/E4/Contexts