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

Bug 148021

Summary: Duplicate graphical link when linking elements from different compartments
Product: [Modeling] GMF-Runtime Reporter: eclipse.survey
Component: GeneralAssignee: Alex Shatalin <shatalin>
Status: RESOLVED INVALID QA Contact:
Severity: normal    
Priority: P3 CC: ahunter.eclipse, borna, gbialek, lding, mmo, richard.gronback
Version: 2.0Keywords: plan
Target Milestone: 2.0   
Hardware: PC   
OS: Windows 2000   
Whiteboard:
Attachments:
Description Flags
This zip archive contains the models for reproducing the problem. none

Description eclipse.survey CLA 2006-06-21 08:25:11 EDT
GMF 1.0 RC4a and GMF RC5 :

- domain model (ecore file) : I had a node element (OperationalNode) and a relationship element (Needline) linking to a source node and a target node. The node element may have sub nodes of the same type (OperationalNode).
- gmf model : the node has a compartment that shows sub nodes.
- problem :
Comment 1 eclipse.survey CLA 2006-06-21 08:33:49 EDT
Created attachment 44990 [details]
This zip archive contains the models for reproducing the problem.
Comment 2 eclipse.survey CLA 2006-06-21 08:37:42 EDT
Oups ... here is the complete description in addition to the models archive ...

GMF 1.0 RC4a and GMF RC5 :

- domain model (ecore file) : I had a node element (OperationalNode) and a
relationship element (Needline) linking to a source node and a target node. The
node element may have sub nodes of the same type (OperationalNode).
- gmf model : the node has a compartment that shows sub nodes.
- problem :
   - I create two nodes Node1 and Node2. I create a sub node Node11 for Node1 and a sub node Node21 for Node2. They are seen in the respective compartment of Node1 and Node2.
   - When I create a needline (relationship) between Node11 and Node21, there are TWO graphical links instead of one. These two graphical links relate to the same needline element (in the ecore model). When I close the diagram and I open it, the display is OK (only one graphical link is seen).
- If I create a needline between Node1 and Node21, there is no problem. Likewise if I create a needline between Node1 and Node2, there is no problem. The problem occurs only between sub nodes from different compartments.
Comment 3 Alex Shatalin CLA 2006-06-23 12:11:47 EDT
The root of this problem AFAIU is in CanonicalEditPolicy. Following sequence of calls will be executed:

- Create semantic element command called (needline link created in domain model)
- Since link contained in diagram domain model element, at the end of prev. command all the listners will be notified -> CanonicalEditPolicy for the diagram will be called and link created as a result of this edit policy execution
- Normal create view command will be called.

Moving this request to the next version - too much to chenge now. As a temporary workaround for this problem I suggest to override OperationalViewCanonicalEditPolicy.shouldHandleNotificationEvent() method and return "false" always. With corresponding modifications everything works ok.
Comment 4 Alex Shatalin CLA 2006-07-10 13:40:10 EDT
Moving to 2.0 since it requires to change CanonicalEditPolicy. Corresponding improvements are scheduled for 2.0
Comment 5 Richard Gronback CLA 2006-07-23 09:49:01 EDT
This bug also seems to be the cause of the mindmap tutorial duplicate links that result when creating Relationship links of type other than the first (iow, those represented as Specialization Types in the generator model).  A difference in the case of mindmap is that closing/reopening the diagrams does not help, and the links appear as duplicates even between top level nodes.  The bug also seems to have appeared between RC4 and the 1.0 release.

The solution files for step 2 of the tutorial can be used to reproduce this bug in mindmap, found here: http://www.eclipse.org/gmf/tutorial/mindmap_tutorial_2.zip

The recommended override of shouldHandleNotificationEvent() seems to also workaround the problem in mindmap.
Comment 6 Michael Moser CLA 2006-08-14 08:09:28 EDT
Could some kind soul describe a bit more precise, where one should add / override this "shouldHandleNotificationEvent()"?

For newbies like myself staggering through the tutorial that's a bit hard to figure out.

Michael
Comment 7 Alex Shatalin CLA 2006-08-14 08:28:16 EDT
for https://bugs.eclipse.org/bugs/show_bug.cgi?id=148021#c6: There should be only one class extending "CanonicalConnectionEditPolicy" for each generated diagram so you should override shouldHandleNotificationEvent() in this class.
Comment 8 Michael Moser CLA 2006-08-14 08:55:45 EDT
OK - thanks a lot! To spare those working through the GMF mindmap tutorial from having to search this: 

the class apparently is
  org.eclipse.gmf.examples.mindmap.diagram.edit.policies.MapCanonicalEditPolicy
  (in project org.eclipse.gmf.examples.mindmap.diagram)

I added the method:

	/**
	 * FIX: temp. workaround according to https://bugs.eclipse.org/bugs/show_bug.cgi?id=148021 / MMO
	 */
	protected boolean shouldHandleNotificationEvent(Notification event) {
		return false;
	}

But that doesn't seem to work quite as expected: I do indeed get only one connection after this, but that one now has no label!

Strange enough, the same is true for "depends" relations, while an "extends" gets properly labeled.

After closing and reopening such a diagram, however, things are even more confusing: ALL relationships now are properly labeled, but the "includes" and "depends" are doubled again while "extends" looks as expected (i.e. a single connection only with a label).

Any ideas or explanations for this one? Suggested workarounds?

Michael
Comment 9 Alex Shatalin CLA 2006-08-18 06:56:46 EDT
Answer to #8:
After small investigation, we have updated projects stored under http://www.eclipse.org/gmf/tutorial/mindmap_tutorial_2.zip. From now generated code works correctly without any changes with the models from the tutorial. You can re-load mindmap_tutorial_2.zip – links should not be duplicated anymore. 

Thank you for reporting this problem and do not hesitate to reiterate this thread if you found any additional errors.
Comment 10 Vlad Ciubotariu CLA 2006-10-06 12:40:37 EDT
(In reply to comment #7)
> for https://bugs.eclipse.org/bugs/show_bug.cgi?id=148021#c6: There should be
> only one class extending "CanonicalConnectionEditPolicy" for each generated
> diagram so you should override shouldHandleNotificationEvent() in this class.
> 

Hi Alex,

If one has a CanonicalConnection edit policy installed, one way to solve this problem is to create only the semantic element in the GraphicalNodeEditPolicy and let the CanonicalConnection policy create the view.

Thus overriding protected Command getConnectionAndRelationshipCompleteCommand()
in the GraphicalNode policy by copy & pasting the current code and commenting out the command that create the view

//cc.compose( new CommandProxy(viewCommand) );

works fine.


I have some additional comments. Basically, the framework should let the user
decide which policies to turn off.

Right now that's hard to do because 

ToggleCanonicalModeCommand resides in org.eclipse.gmf.runtime.diagram.ui.internal.commands

and GraphicalEditPart.disableCanonicalFor( final Request request ) is not protected.

Secondly, sometimes CanonicalConnection policies don't pick up connections from the model correctly. That's when the views for the ends don't exist yet. One solution is to force a refresh of the policy from the activate() method of the source/target editParts.
Comment 11 Jörg Weinmann CLA 2006-12-11 11:28:37 EST
(In reply to comment #9)
Could you give some details what you changed in your example? Is there a way to work around this bug only by changing the model files?

Thanks,
 Jörg Weinmann
Comment 12 Alex Shatalin CLA 2006-12-11 14:20:53 EST
Reply to comment #11:

I've updated link constraints to make semantic link recognition single-valued. The problem was: two different link mappings was applicable for the same link from semantic model in the same time.

This problem was caused by the different reason ("non-unique link description"). Original one could be solved by applying work-around described in comment #3
Comment 13 Jörg Weinmann CLA 2006-12-12 02:28:52 EST
(In reply to comment #12)

Thank you, Alex. The workaround you described in comment #3 says to change the source code, which can only be done by hand or by changing the gmf templates accordingly. The first one is not applicable in my case, so I guess I have to go with the second one. I had hoped that it would be sufficient to change some parameters in the gmf models. 

So thanks again,
 Jörg Weinmann
Comment 14 Anthony Hunter CLA 2007-05-01 09:22:19 EDT
Since GMF 2.0 M6 was released April 5, 2007, doing a bulk move of all open Bugzillas currently on M6 to 2.0 M7. Owners will need to access if the issue really is targetted for 2.0 M7.
Comment 15 Alex Shatalin CLA 2007-06-09 05:57:17 EDT
Can not repeat this problem anymore.
Comment 16 Anthony Hunter CLA 2007-06-20 15:03:23 EDT
*** Bug 158668 has been marked as a duplicate of this bug. ***
Comment 17 Richard Gronback CLA 2008-08-13 13:11:40 EDT
[target cleanup] 2.0 M7 was the original target milestone for this bug
Comment 18 Eclipse Webmaster CLA 2010-07-19 12:30:20 EDT
[GMF Restructure] Bug 319140 : product GMF and component
Runtime Diagram was the original product and component for this bug