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

Bug 314670

Summary: Edges are not properly synchronized with semantic element
Product: [Modeling] GMF-Tooling Reporter: Jan Koehnlein <jan>
Component: CoreAssignee: Artem Tikhomirov <tikhomirov.artem>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: borlander, brian.jakubik, chris.waniek, Holger.Schill, troygnichols, y.yu
Version: unspecified   
Target Milestone: 2.4   
Hardware: All   
OS: All   
Whiteboard:

Description Jan Koehnlein CLA 2010-05-27 10:09:28 EDT
Seems to be an issue in *all* generated diagram editors, e.g. the Ecore editor. 

Steps to reproduce:
1) Open a new Ecore diagram
2) Create an EClass with a self association
3) Save
4) Open the Ecore model in another editor, delete the EReference and save
5) Diagram is updated, but edge is not removed. Instead, it shows a missing semantic element symbol. 

Even worse:
6) Undo the change in the non-graphical editor and save
7) Edge disappears completely from the diagram. It will not reappear unless you add another edge in the diagram

Happens with GMF 2.3 RC2.
Comment 1 Holger Schill CLA 2010-06-07 11:18:37 EDT
In 2.3 R2 the generated ModelCanonicalEditPolicy does not extend the org.eclipse.gmf.runtime.diagram.ui.editpolicies.CanonicalConnectionEditPolicy any more. I really do not get it why this has been done. Even out of the comment on the method refreshSemantic in ModelCanonicalEditPolicy I do not get it. 
In the way the class ModelCanonicalEditPolicy is generated we have a refreshproblem for new created Edges and orphaned.

In org.eclipse.gmf.runtime.diagram.ui.editpolicies.CanonicalConnectionEditPolicy.refreshSemanticConnections() you could see what I mean.

makeViewsMutable(viewDescriptors);

		// now refresh all the connection containers to update the editparts
		HashSet<EditPart> ends = new HashSet<EditPart>();
		
		ListIterator<IAdaptable> li = viewDescriptors.listIterator();
		while (li.hasNext()) {
			IAdaptable adaptable = li.next();
			Edge edge = (Edge)adaptable.getAdapter(Edge.class);
			EditPart sourceEP = getEditPartFor(edge.getSource(), edge);
			if (sourceEP != null) {
				ends.add(sourceEP);
			}
			EditPart targetEP = getEditPartFor(edge.getTarget(), edge);
			if (targetEP != null) {
				ends.add(targetEP);
			}
		}

		for(EditPart end : ends) {
			end.refresh();
		}
Comment 2 Eclipse Webmaster CLA 2010-07-19 22:20:08 EDT
[GMF Restructure] Bug 319140 : product GMF and component
Generation was the original product and component for this bug
Comment 3 Yijun Yu CLA 2010-09-28 12:26:35 EDT
(In reply to comment #2)
> [GMF Restructure] Bug 319140 : product GMF and component
> Generation was the original product and component for this bug

I had a similar problem as Jan Koehnlein. After looking at the comment Holger Schill, I think the problem can be solved this way:

1) Change the CanonicalEditPolicy to CanonicalConnectionEditPolicy in the generated code;

2) Implement the 3 missing methods to allow semantic queries. Here I use the Problem Frames diagram we developed (http://sead1.open.ac.uk/pf) to illustrate the solution, you may change the semantic queries according to your own meta-models:

	@Override
	protected List<EObject> getSemanticConnectionsList() {
		View viewObject = (View) getHost().getModel();
		LinkedList<EObject> result = new LinkedList<EObject>();
		List<ProblemLinkDescriptor> childDescriptors = ProblemDiagramUpdater
				.getContainedLinks(viewObject);
		for (ProblemNodeDescriptor d : childDescriptors) {
			result.add(d.getModelElement());
		}
		return result;
	}

	@Override
	protected EObject getSourceElement(EObject relationship) {
		if (relationship instanceof Link) {
			Link l = (Link) relationship;
			return l.getFrom();
		}
		return null;
	}

	@Override
	protected EObject getTargetElement(EObject relationship) {
		if (relationship instanceof Link) {
			Link l = (Link) relationship;
			return l.getTo();
		}
		return null;
	}
Comment 4 Holger Schill CLA 2010-09-29 09:27:05 EDT
I think the changes have to be done in the GMF-Tooling templates. Otherwise GMF-Tooling is not useable.
Comment 5 Artem Tikhomirov CLA 2010-12-08 00:44:00 EST
The cause of the trouble was the difference in #refreshOnActivate() method implementation in CanonicalConnectionEditPolicy and regular CanonicalEditPolicy. Former "cheats" on GEF, forcing activation of child edit parts (which is the job done by GEF at appropriate moment of time, *after* editpolicies are activated). Post-commit notification listeners installed from EditParts' activate() method are responsible to refresh diagram according to changes CanonicalEditPolicy otherwise perfectly did.

I've added edit part activation logic prior to canonical refresh, although I believe there should be alternative approach, which doesn't require one to intervene with regular GEF approach.
Comment 6 Christian Waniek CLA 2011-02-11 08:56:32 EST
*** Bug 335955 has been marked as a duplicate of this bug. ***
Comment 7 Michael Golubev CLA 2011-07-13 19:45:59 EDT
version -> 2.4
Comment 8 Michael Golubev CLA 2011-07-14 07:51:40 EDT
Rollback, Set target to 2.4 instead of accidenatlly set Version