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 "E4/Contexts"

< E4
(IServiceLocator)
(IServiceLocator)
Line 24: Line 24:
 
</source>
 
</source>
  
Each service is hierarchical and mirrors the IServiceLocator hierarchy.  Services are created lazily on the call to getService(Class).  The lookup algorithm is:
+
Each service is hierarchical and mirrors the IServiceLocator hierarchy.  Services are created lazily on the call to <code>getService(Class)</code>.  The lookup algorithm is:
  
 
#Check our cache to see if we already have an instance of the service
 
#Check our cache to see if we already have an instance of the service
 
#Check our local <code>org.eclipse.ui.services.AbstractServiceFactory</code> to see if we can create a local override version
 
#Check our local <code>org.eclipse.ui.services.AbstractServiceFactory</code> to see if we can create a local override version
#Go to the '''org.eclipse.ui.services''' registry, org.eclipse.ui.internal.services.WorkbenchServiceRegistry to see if we can create the service
+
#Go to the '''org.eclipse.ui.services''' registry, <code>org.eclipse.ui.internal.services.WorkbenchServiceRegistry</code> to see if we can create the service
 
#Use the parent locator to try and look up the service
 
#Use the parent locator to try and look up the service
 +
 +
When creating a service, you have access to:
 +
<source lang="java">
 +
Object create(Class serviceInterface, IServiceLocator parentLocator, IServiceLocator locator);
 +
</source>
 +
 +
*serviceInterface: the service we need to create
 +
*parentLocator: A locator that can return a parent service instance if desired
 +
*locator: the service locator which can be used to retrieve dependent services
  
 
== IEvaluationContext ==
 
== IEvaluationContext ==
  
 
Provided by '''org.eclipse.core.expressions''' this is the application context used in 3.x by the IEvaluationService (and hence all declarative expressions like enabledWhen/activeWhen/visibleWhen)
 
Provided by '''org.eclipse.core.expressions''' this is the application context used in 3.x by the IEvaluationService (and hence all declarative expressions like enabledWhen/activeWhen/visibleWhen)

Revision as of 10:04, 9 January 2009

Contexts

In the general, execution or evaluation contexts, that can provide information to the currently executing code.

IEquinoxContext

Bug 259423 Add notion of "context" that can be injected into objects

IServiceLocator

In Eclipse 3.x we have the notion of part hierarchy: Workbench, WorkbenchWindow, WorkbenchPart (Editor/View), and nested part (MultiPageEditorPart or PageBookView).

Bug 92646 comment #11 [Workbench] [RCP] Allow developers to register Workbench services

There is a description of our services/service locator hierarchy in comment #11, basically we use this model to support 3 things:

  • A service behaviour accessed through a local context (not PlatformUI :-)
  • Scoping of the service to the local context
  • Local service lifecycle, allowing the de-activation of contributions and listener clean up
IContextService contextService = (IContextService) getSite().getService(IContextService.class);
contextService.activateContext("org.eclipse.ui.textScope");

Each service is hierarchical and mirrors the IServiceLocator hierarchy. Services are created lazily on the call to getService(Class). The lookup algorithm is:

  1. Check our cache to see if we already have an instance of the service
  2. Check our local org.eclipse.ui.services.AbstractServiceFactory to see if we can create a local override version
  3. Go to the org.eclipse.ui.services registry, org.eclipse.ui.internal.services.WorkbenchServiceRegistry to see if we can create the service
  4. Use the parent locator to try and look up the service

When creating a service, you have access to:

Object create(Class serviceInterface, IServiceLocator parentLocator, IServiceLocator locator);
  • serviceInterface: the service we need to create
  • parentLocator: A locator that can return a parent service instance if desired
  • locator: the service locator which can be used to retrieve dependent services

IEvaluationContext

Provided by org.eclipse.core.expressions this is the application context used in 3.x by the IEvaluationService (and hence all declarative expressions like enabledWhen/activeWhen/visibleWhen)

Back to the top