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

Bug 327389

Summary: Generated *CanonicalEditPolicy removes diagram shortcuts
Product: [Modeling] GMF-Tooling Reporter: Richard Gronback <richard.gronback>
Component: CoreAssignee: Michael Golubev <borlander>
Status: ASSIGNED --- QA Contact:
Severity: normal    
Priority: P3 CC: Angel.Roman, borlander, bruce.trask, jfbraz, laurent.lemoux, sbouchet
Version: 2.3.1Flags: borlander: juno+
Target Milestone: 3.0.SR1   
Hardware: Macintosh   
OS: Mac OS X - Carbon (unsup.)   
Whiteboard:
Attachments:
Description Flags
The requested xxCanonicalEditPolicy file none

Description Richard Gronback CLA 2010-10-09 08:00:33 EDT
Build Identifier: GMF 2.3.1

It looks like the recent refactoring of codegen templates has introduced a bug when dealing with shortcuts in the semantic refresh of a diagram.  In refreshSemantic(), the following is generated:
...
                for ( View v : getViewChildren() )
		{
			if ( isMyDiagramElement(v) )
			{
				knownViewChildren.add(v);
			}
			if ( v.getEAnnotation("Shortcut") != null && InfoDiagramUpdater.isShortcutOrphaned(v) ) {
				orphaned.add(v);
			}
		}
...

A valid shortcut element is added to knownViewChildren and not to orphaned, which seems fine until you look later at the code where the diagram's semantic elements are processed, removing all valid view->element matches from knownViewChildren.  In the end, invalid elements and valid shortcut elements are sent to the orphanage: orphaned.addAll(knownViewChildren);

A temporary solution is to override the impl::diagram::update::CanonicalUpdate::_checkOrphanedShortcuts template to remove the valid shortcut view from knownViewChildren right away.

«AROUND _checkOrphanedShortcuts(String orphanedCollectionVar, String viewVar) FOR gmfgen::GenDiagram»
«IF containsShortcutsTo->notEmpty()-»
	if («viewVar».getEAnnotation("Shortcut") != null && «editorGen.diagramUpdater.getDiagramUpdaterQualifiedClassName()».isShortcutOrphaned(«viewVar»)) {«EXPAND xpt::Common::nonNLS»
		«orphanedCollectionVar».add(«viewVar»);
	} else {
		knownViewChildren.remove(v);
	}
«ENDIF-»
«ENDAROUND»

Reproducible: Always

Steps to Reproduce:
1. Create a shortcut from a related model on the diagram
2. Close the diagram
3. Reopen the diagram to see shortcut has vanished
Comment 1 Michael Golubev CLA 2012-01-18 13:10:34 EST
Fix pushed into both 3.0 and 2.4.x maintenance stream
Comment 2 Michael Golubev CLA 2012-01-18 13:13:46 EST
*** Bug 368154 has been marked as a duplicate of this bug. ***
Comment 3 Michael Golubev CLA 2012-05-30 00:24:57 EDT
Fixed since M4, closing the bug
Comment 4 Laurent Le Moux CLA 2012-08-29 08:23:20 EDT
It seems that this problem is not solved.
GMF 3.0.0 still generates a refreshSemantic method that removes valid shortcuts from the diagram.
Comment 5 Michael Golubev CLA 2012-08-29 10:14:02 EDT
Hello, 

Looking at the problem, unable to reproduce right now, but probably understand what the problem is. 
I will try to deliver the fix to SR1.
Comment 6 Michael Golubev CLA 2012-09-04 21:20:29 EDT
Laurent, 

In the Taipan sample, after regenerating with GMFT 3.0R, I see the following code in the AquatoryCanonicalEditPolicy: 

// we care to check only views we recognize as ours and not shortcuts
LinkedList<View> knownViewChildren = new LinkedList<View>();
for (View v : getViewChildren()) {
   if (isShortcut(v)) {
      if (TaiPanDiagramUpdater.isShortcutOrphaned(v)) {
         orphaned.add(v);
      }
      continue;
   }
   if (isMyDiagramElement(v)) {
      knownViewChildren.add(v);
   }
}

To my understanding it solves the problem (almost exactly the same way as you described it earlier). 

If you still have a problem, can you please attach the problematic XXXCanonicalEP here?
Comment 7 Laurent Le Moux CLA 2012-09-05 03:37:43 EDT
Created attachment 220721 [details]
The requested xxCanonicalEditPolicy file
Comment 8 Laurent Le Moux CLA 2012-09-05 03:39:53 EDT
Hello Michael,

The problem is still there.
The shortcut is added to the knownViewChildren list, which in turn is added to the orphaned one and removed later on...

Regards,

Laurent
Comment 9 Michael Golubev CLA 2012-09-05 04:42:17 EDT
Hum, 

I see the expected generated code in your file. 
That is, at the line 140, there is a "continue;" which should prevent shrtcuts from being added to the knownViewChildren. Agree? 

I understand that you may still have a problem but its source is now different.