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

Bug 327698

Summary: [Diagram] Artifact refactoring doesn't update all references on diagrams
Product: [Technology] Tigerstripe Reporter: Navid Mehregani <nmehrega>
Component: UIAssignee: Yuri Strot <yuri>
Status: VERIFIED FIXED QA Contact:
Severity: major    
Priority: P3 CC: chrhartl
Version: unspecified   
Target Milestone: 0.5M0   
Hardware: PC   
OS: Mac OS X - Carbon (unsup.)   
Whiteboard:
Attachments:
Description Flags
patch_327698.txt
none
patch_327698.txt
none
327698_bug2_incomplete.txt
none
327698_bug2_hack_patch.txt
none
327698 c7 patch none

Description Navid Mehregani CLA 2010-10-13 14:21:29 EDT
Build Identifier: 

When refactoring an entity name, not all references are updated in class diagram

Reproducible: Always

Steps to Reproduce:

Steps to Reproduce:
1. Open /tigerstripe/samples/test-models/model-refactoring project;
2. Rename simple.Ent1 artifact (with using Refactor Model -> Rename... from TS Explorer);
3. Open simple.default diagram.

The artifact has new name, but references from other artifacts are still pointed to Ent1 (Ent2: +method0(Ent1):Ent1[0..1]).
Comment 1 Navid Mehregani CLA 2010-10-13 14:22:38 EDT
Dan, can you please take a look at this in the next iteration? Thanks!

Some of the work that was done in bug#326452 is related to this.
Comment 2 Chris Hartley CLA 2010-10-13 19:13:55 EDT
Suggest this should be upgraded to major as it will 'corrupt' the model.
Comment 3 Navid Mehregani CLA 2010-10-13 19:17:54 EDT
Upgrading to Major.
I have this defect in my list as a candidate for the next iteration.
Comment 4 Daniel Johnson CLA 2010-11-02 18:32:16 EDT
Created attachment 182263 [details]
patch_327698.txt

Fixes a number of issues related to synchronization (Hopefully All!). I was unable to make this patch get out of sync with any model changes(Rename or Move) both with open or closed diagrams.

Classes Changed:
ModelChangeDeltaProcessor
ClassDiagramSynchronizer
ProjectDiagramSynchronizer
ArtifactFQRenameRequest

The patch file makes it look like a whole lot has changed in ModelChangeDeltaProcessor, but really just a few lines at line 189, Added the If/Else block now at line 198 and some variable setup before that.
Comment 5 Chris Hartley CLA 2010-11-02 20:01:39 EDT
Excellent - it will be good to try this out and I'll certainly let you know if there are any remaining issues.
Comment 6 Daniel Johnson CLA 2010-11-04 16:34:13 EDT
Created attachment 182427 [details]
patch_327698.txt

New patch: merged ModelChangeDeltaProcessor with changes made yesterday.
Comment 7 Navid Mehregani CLA 2010-11-04 23:40:58 EDT
Dan, I've submitted your patch.  It seems to resolve the original problem.
However, I found another synchronization issue unrelated to your patch:

 - Create a new Model project
 - Create a class diagram
 - Create an entity in the diagram and add three methods and three attributes from the diagram.
 - Close the diagram
 - Expand entity in TS Explorer
 - Delete all attribute/methods EXCEPT the first attribute
 - Open diagram file.  In some cases the diagram doesn't open properly due to an NPE because the diagram is not synced up properly.
Comment 8 Daniel Johnson CLA 2010-11-15 18:23:29 EST
Created attachment 183176 [details]
327698_bug2_incomplete.txt

So I have pinpointed the issue, but I am not exactly sure how to solve it. The issue has to do with creating an attribute/method/literal using the buttons on the diagram (either from the tray or from the pop-up that shows up when hovering over an artifact) When using these buttons they create an extra xml element in the .wvd file of the diagram. Using the TS explorer context menu to add an attribute/method/literal does not do this, it seems to be EMF code that creates the xml element. As long as the diagram stays open when a delete happens the same eElement object that the attribute/method/literal was created on will be referenced and correctly deleted, but if the diagram is closed before deleting than the eElement object referenced is a different one, this seems to cause the failure to update the .wvd file by removing the xml element referring to the attribute/method/literal.
From what I understand I think the correct solution is to somehow not allow these xml elements to be added in the first place (might not be possible since so much is EMF code) or to somehow remove them either when the diagram is closed, or when the attribute/method/literal is deleted (I tried this but am getting an error saying my code must be in a transaction, something I know little about). 
The xml elements don't seem to be needed for everything to work correctly. However, if an xml element exists and point to an attribute/method/literal that has been deleted than this is what causes the diagram to seem corrupt.

My patch so far currently only applies to attributes on an entity. It attempts to remove any of these unwanted xml tags when an updated closed diagram is saved. If someone can help get this working than I can implement the rest. When I try to run it I get an error saying it must be in a write transaction. This patch shows the whole file replaced, but the only thing changed is the saveDiagram method along with a few constants and imports.
Comment 9 Chris Hartley CLA 2010-11-15 20:05:06 EST
So perhaps this is an EMF/GEF/GMF issue and could be referred to that team for comment on the additional XML.
Comment 10 Daniel Johnson CLA 2010-11-19 19:43:31 EST
Created attachment 183511 [details]
327698_bug2_hack_patch.txt

Changed the saveDiagram() method in ClosedDiagramSynchronizerBase
This is really just a hack that possibly could be unstable. But I tested it a bit and couldn't uncover any issues. What it does is upon updating a saved diagram when it is saving it goes through and removes all 4th level xml children in the .wvd file. In all the playing around I did this seemed to just be methods, literals, and attributes. Like I say, this is very much a hack, but could be a temporary solution to save some headache from the diagram files getting out of sync.
Comment 11 Daniel Johnson CLA 2010-11-22 12:40:15 EST
I wonder if this might actually be a problem with tigerstripe model in o.e.t.workbench.ui.visualeditor/model Trying to open almost any of these files gives errors saying that an older version of the GMF model is loaded and that it needs to be migrated. ??? Anybody familiar with this?
Comment 12 Chris Hartley CLA 2010-11-22 15:53:02 EST
That could explain why the additional XML elements are being added.
I suggest you ask Richard and or Eric re these files and if they need to be migrated.
Comment 13 Anton Salnik CLA 2010-12-16 01:15:02 EST
Created attachment 185293 [details]
327698 c7 patch

https://bugs.eclipse.org/bugs/show_bug.cgi?id=327698#c7 issue fixed. "Additional xml" is GMF's notation model and it's used to store visual configuration. Closed diagrams synchrinized updates only semantic model of diagrams, so the notation model should be updated on diagram open. Patch attached.
Comment 14 Yuri Strot CLA 2010-12-17 08:28:52 EST
Anton's patch applied.
Comment 15 Navid Mehregani CLA 2010-12-21 13:31:33 EST
We can finally put this beast to rest.  Thanks a lot Anton!!