Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 323075 - [RCP] Headless usage of Eclipse 4 RCP (without a Window) - Context of model elements should be explicitly created and filled
Summary: [RCP] Headless usage of Eclipse 4 RCP (without a Window) - Context of model e...
Status: RESOLVED WORKSFORME
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.3.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Platform UI Triaged CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-08-18 14:33 EDT by Oleg Besedin CLA
Modified: 2020-06-02 04:36 EDT (History)
11 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Oleg Besedin CLA 2010-08-18 14:33:21 EDT
At present the context for model elements is created by the PartRenderingEngine#createGUI().

That's problematic in a number of levels:

- there is no place to fill in the context for a given element type (say, I'd like to make a service available on MWindow level)

- the lifecycle of model element is tied to its visibility. As an extreme example, how about headless app that wants to do some query or transformation on the model?

- most interestingly: 
The model's XML seems like a good place to put description of services avaiable, thus fixing the problem of guessing which services are available. (In a nutshell, the XML we now use for the chain: Interface -> Declarative Services -> OSGI context -> model element context would be much more straightforward if we were to put description of services in the model's XML.)
Comment 1 Paul Webster CLA 2010-08-18 14:47:20 EDT
Just some thoughts on the many things we currently do that are related or that we might need to consider while looking at this.

Section 1: Services

1) we create a number in the E4Application, creating a default app context

2) we use DS and OSGi to provide some services or service creation functions

3) We use ContextFunctions to create the mediator services (See section 2).  These often use #1 or #2 to get into the context chain.

4) In the compatibility layer, we have hardcoded places in Workbench/WorkbenchWindow/WorkbenchPage/PartSite/PageSite that also adds to the context.

5) We have a lifecycle object or pattern that can be used to modify the system.  Is it just one?

6) We have the ModelProcessors, which can be model fragments (preferred) or actual processors.  They run before the deltas start up (and are a good candidate for processing Extension Points).  These aren't really about services but about contributing to the stable part of the model.

7) We have the Add-Ons.  I'm not sure when these get processed, but they seem to be a good candidate for setting up event handlers to respond to model change

8) IEventBroker handlers - it seems to me that these can be written to supply some specific services.  ex: When an MWindow Context becomes available (a new WorkbenchWindow, for example) the appropriate service or CF can be added to that context.


Section 2: mediator services.

Mediator services deal with their requesting IEclipseContext.  They provide one or more of the following 3:

1) scope lookup of information

2) change the behaviour of a service request

3) lifecycle management - i.e. listeners to that service are cleaned up automatically when the context (and Model object and service) are disposed.

PW
Comment 2 Remy Suen CLA 2010-08-18 14:52:04 EDT
(In reply to comment #1)
> 5) We have a lifecycle object or pattern that can be used to modify the system.
>  Is it just one?

Yes, I just checked, it's only one.
Comment 3 Lars Vogel CLA 2012-02-03 10:11:22 EST
+1

Currently a Window is required in the application model, it think this limits the usage of Eclipse 4. I assume there would be nice use cases for headless Eclipse 4 applications.
Comment 4 Eric Moffatt CLA 2012-12-06 16:00:30 EST
I agree that you should not need any ui elements in the model in order to go through the startup cycle (yo may be putting up a dialog as to which UI you want to open...;-). If this not working we should have a defect for it.

We've discussed various approaches, including have the 'getContext()' method create one if it's not already there but there are issues with this. For example if we ask for the context of an MPart we'd *have* to also create the contexts of every parent MContext element in order to get the chaining correct.

As far as adding services into a particular context I'd just add a listener for MContext's 'context' going non-null, checking the element type to see if it's an MWindow (or whatever) and adding the services there. Note that this happens before the widget is rendered so the new services will be available.
Comment 5 Lars Vogel CLA 2020-06-02 04:36:37 EDT
We do this in our tests.