Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 359075 - [Refactoring] The access to the ServiceRegistry should not depend on the active Papyrus Editor
Summary: [Refactoring] The access to the ServiceRegistry should not depend on the acti...
Status: RESOLVED FIXED
Alias: None
Product: Papyrus
Classification: Modeling
Component: Core (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P3 enhancement (vote)
Target Milestone: 0.9.0   Edit
Assignee: Cedric Dumoulin CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on: 370129
Blocks: 359057
  Show dependency tree
 
Reported: 2011-09-27 10:10 EDT by Camille Letavernier CLA
Modified: 2014-04-11 06:19 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Camille Letavernier CLA 2011-09-27 10:10:30 EDT
Currently, to access the active model, we use the ServiceRegistry, which in turn needs to have an active Papyrus Editor. When we are in a different context, this results in a NullPointerException.

There are two options :

- Find a general method to access the ServiceRegistry without a Papyrus editor. This may be problematic when more than one model is loaded (From different editors) : we need at least a "context".
- Send the ServiceRegistry as a parameter to each element which requires it. This may not always be possible without a major refactoring. We should investigate on that.
Comment 1 Camille Letavernier CLA 2011-09-28 08:33:07 EDT
We may investigate on the "Context"s in Eclipse e4 for solving this problem.

This seems to be a good way of solving this kind of problems :

http://www.eclipse.org/e4/resources/e4-whitepaper.php (Programming Model)
http://www.vogella.de/articles/EclipseE4/article.html#programmingmodel
http://www.eclipse.org/e4/resources/contexts.pdf
Comment 2 Cedric Dumoulin CLA 2011-10-20 09:37:26 EDT
Note that from inside papyrus code, you should NEVER access the ServiceRegistry by using the notion of current editor.
You are allowed to access the ServiceRegistry by looking for the current editor only in the case of a user interaction, i.e. from inside a command handlers.
Please see comments from the following classes that provide methods to get the ServiceRegistry in different cases:
- org.eclipse.papyrus.core.utils.ServiceUtilsForActionHandlers
- org.eclipse.papyrus.core.utils.ServiceUtils
- org.eclipse.papyrus.diagram.common.util.ServiceUtilsForGMF
Comment 3 Cedric Dumoulin CLA 2012-01-30 09:28:28 EST
The access to the ServicesRegistry do not depends on the active editor. It has never depend on the active Editor.
If you already have the ServicesRegistry, you can access it even if the currently selected editor is not Papyrus.

However, if you want to find the ServicesRegistry, you need a kind of context from which you can search for it.
- If you are in an ui handler, this certainly mean that you want the ServicesRegistry of the currently selected Editor. This can be done with the org.eclipse.papyrus.infra.core.utils.ServiceUtilsForActionHandlers. This utility class DEPENDS ON the active editor.
- If you are in a nested editor, you should have a way to get the ServiceRegistry from this editor. 
Wiki pages explain how to get the ServiceRegistry from different contexts (http://wiki.eclipse.org/Papyrus_Developer_Guide/How_To_Code_Examples#How_to_get_the_ServiceRegistry)
Comment 4 Camille Letavernier CLA 2014-04-11 06:19:09 EDT
Many different ServiceUtils* implementations are available now, which depend on a specific context element (e.g. EObject) instead of relying on the Active editor.

I close this task