Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 518259

Summary: [aird editor] Model Explorer not updated when creating a representation
Product: [Modeling] Sirius Reporter: Frederic Madiot <frederic.madiot>
Component: CoreAssignee: Project inbox <sirius.core-inbox>
Status: CLOSED FIXED QA Contact: Julien Dupont <julien.dupont>
Severity: normal    
Priority: P3 CC: julien.dupont, pierre.guilet
Version: 5.0.0Keywords: triaged
Target Milestone: 5.0.1   
Hardware: PC   
OS: Windows NT   
See Also: https://git.eclipse.org/r/99515
https://git.eclipse.org/c/sirius/org.eclipse.sirius.git/commit/?id=8cf04acad92e8646077e69a5c869923168c30f54
https://git.eclipse.org/r/100187
https://git.eclipse.org/r/100325
https://git.eclipse.org/c/sirius/org.eclipse.sirius.git/commit/?id=6d22567e96e95ebd9ee69382ac5de55c9e7c5d12
Whiteboard:
Attachments:
Description Flags
screenshot none

Description Frederic Madiot CLA 2017-06-14 12:24:41 EDT
Created attachment 268911 [details]
screenshot

I have created a new representation from the aird editor and it doesn't appear  in the Model Explorer (see screenshot)
Steps to reproduce :
- Install Basic Family metamodel (Export > Deployable Plugins > Install into host)
- Install Basic Family Sample Model and Advanced Tutorial Solutions (New > Example)
- Select "Family" instance in the Model Explorer
- Select "New Representation > Other..."
- Select Person Diagram
=> the "persons" viewpoint is automatically selected and the diagram is created and displayed, but it doesn't appear in the Model Explorer
- Enter F5 => the representation appears
- Create a table from the Model Explorer => idem : created but not visible  in the Model Explorer
Comment 1 Pierre Guilet CLA 2017-06-15 09:35:13 EDT
To be more precise The "Family" instance must be select in the models block of the aird editor.
Comment 2 Pierre Guilet CLA 2017-06-15 10:00:00 EDT
Well in fact in both case it does not work.
Comment 3 Pierre Guilet CLA 2017-06-15 11:07:00 EDT
In some case it works.
To be sure to reproduce, you have to delete the aird, recreate it, load the model, then create a new representation.
Comment 4 Eclipse Genie CLA 2017-06-16 11:11:28 EDT
New Gerrit change created: https://git.eclipse.org/r/99515
Comment 5 Pierre Guilet CLA 2017-06-16 11:43:04 EDT
The problem is not always reproductible because it depends on job execution planning and speed.

One scenario I use to reproduce the problem almost all the time on my machine is the following:
- Create a new modeling projet.
- Put an ecore model with an epackage inside.
- Delete the aird.
- Create a new aird from semantic resource and select your model then finish.
- open aird editor
- in Model explorer view, select your model package then right click>other
- Select the diagram description from ecore tool design viewpoint and create a new representation with some name
- Save
- On aird editor, double click on the "design" viewpoint that has been activated by representation creation to deactivate it.
- in Model explorer view, select your model package then right click>other
- Select the diagram description from ecore tool design viewpoint and create a new representation with some name

You new representation should be visible under representation.aird item of model explorer but not under the package model element.

The problem is the following: 

When a session is loaded whereas no viewpoints have been yet activated, DAnalysisSessionImpl initializes and puts a RepresentationChangedAdapter as one of its adapter. But does not the same for SessionLazyCrossReferencer that is put when activating a viewpoint. It means the cross referencer is after the change adapter in adapters list of any adapted object.

This is a problem in the case of representation creation because to be correctly updated, the model explorer viewer must be refreshed after the reference between model element and new created representation is put in the cross referencer. We use this reference to compute the representation children of semantic elements in model explorer.

The model explorer is a listener of the changed adapter. When a representation is created, it launches an asynchrone UI job tu refresh its viewer.

So we can have some situations where the job is executed before than the cross referencer update. In this case the computed children will be missing the new representation during Model explorer refresh.

If the job is executed after, then no problems.
Comment 6 Pierre Guilet CLA 2017-06-23 04:55:43 EDT
Because the problem is difficult to reproduce, the best way to test the fix is to put a breakpoint in the first line of org.eclipse.sirius.business.internal.session.danalysis.RepresentationsChangeAdapter.registerAnalysis(DAnalysis)

Create a new aird in a modeling project referencing a semantic model.
This trigger the breakpoint. Verify that the SessionLazyCrossReferencer is already present before adding the RepresentationCHangeAdapter
Comment 8 Eclipse Genie CLA 2017-06-28 04:40:16 EDT
New Gerrit change created: https://git.eclipse.org/r/100187
Comment 9 Eclipse Genie CLA 2017-06-29 04:24:15 EDT
New Gerrit change created: https://git.eclipse.org/r/100325
Comment 11 Pierre-Charles David CLA 2017-06-30 09:46:32 EDT
Available in Sirius 5.0.1, see https://wiki.eclipse.org/Sirius/5.0.1 for details.