Bug 352968 - Returned command in getAfterDestroyReferenceCommand in EditHelperAdvice causes original command to fail partially
Summary: Returned command in getAfterDestroyReferenceCommand in EditHelperAdvice cause...
Status: NEW
Alias: None
Product: GMF-Runtime
Classification: Modeling
Component: General (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows 7
: P3 normal
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-07-25 03:05 EDT by Greg CLA
Modified: 2011-09-19 05:17 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Greg CLA 2011-07-25 03:05:08 EDT
Build Identifier: 20110301-1815

In a test environment for this issue I simply had two nodes (TestSource and TestTarget) and a reference between them (TestSource_test). Both nodes have a label (TestSourceLabel and TestTargetLabel).

After adding a custom EditHelperAdvice which was supposed to edit the target's label after removing the connection between those two nodes (getAfterDestroyReferenceCommand), the reference disappeared graphically but remained in the properties of the source node. After saving the diagram I restarted it and the reference was back, even graphically.

The method that reacted on the creation of the reference did not show any side effects. That method was getAfterCreateRelationshipCommand which is implemented in the EditHelperAdvice that is connected to the target node.

After adding a delete command, created from the original delete request, to the returned command in the getAfterDestroyReferenceCommand method it worked again.

This is the changed content in the plugin.xml:

...
   <extension point="org.eclipse.gmf.runtime.emf.type.core.elementTypes" id="element-types">
...
            <metamodel nsURI=".../testproject/1.0"><!--Forum didn't allow http-->
               <adviceBinding
                     class="testproject.extend.advice.TestTargetAdvice"
                     id="TestProject.diagram.TestTargetAdvice"
                     inheritance="all"
                     typeId="TestProject.diagram.TestTarget_2002">
               </adviceBinding>
                              <adviceBinding
                     class="testproject.extend.advice.TestSourceAdvice"
                     id="TestProject.diagram.TestSourceAdvice"
                     inheritance="all"
                     typeId="TestProject.diagram.TestSource_2001">
               </adviceBinding>
            </metamodel>
   </extension>

... 

   <extension point="org.eclipse.gmf.runtime.emf.type.core.elementTypeBindings" id="element-types-bindings">
...
      <binding context="TestProject.diagram.TypeContext">
...
         <advice ref="TestProject.diagram.TestTargetAdvice"></advice>
         <advice ref="TestProject.diagram.TestSourceAdvice"></advice>
      </binding>
   </extension>
...

This is the important content of the not working EditHelperAdvice:

package testproject.extend.advice;

...

public class TestSourceAdvice extends AbstractEditHelperAdvice {
	@Override
	protected ICommand getAfterDestroyReferenceCommand(
			DestroyReferenceRequest request) {

		if (request.getReferencedObject() != null
				&& request.getReferencedObject() instanceof TestTargetImpl) {

			SetValueCommand newSetCommand = new SetValueCommand(new SetRequest(
					(EObject) request.getReferencedObject(),
					TestprojectPackageImpl.eINSTANCE
							.getTestTarget_TestTargetLabel(), "deleted"));

			ICommand command = super.getAfterDestroyReferenceCommand(request);

			ICompositeCommand compositeCommand = new CompositeCommand("delete");

			if (command != null) {
				compositeCommand.add(command);
			}

			compositeCommand.add(newSetCommand);

			return compositeCommand;
		} else

			return super.getAfterDestroyReferenceCommand(request);
	}
}

Adding the delete command fixes it (but it shouldn't be necessary):

DestroyReferenceCommand newDestroyCommand = new DestroyReferenceCommand(request);
compositeCommand.add(newDestroyCommand);

The whole issue also is described in this forum entry:
http://www.eclipse.org/forums/index.php/t/221480/

Reproducible: Always

Steps to Reproduce:
Preparation:
1. Create an Ecore model as described in the details (TestSource -test->   TestTarget[TestTargetLabel])
2. Generate the model and the diagram editor
3. Create the custom TestSourceAdvice
4. Edit the plugin.xml to add the TestSourceAdvice to the TestSourceNode

In the diagram editor:
1. Create a TestSource node and a TestTarget node
2. create a reference between them
3. delete the reference (the graphical representation of the reference should disappear)
4. Check the property view of the TestSource node -> It still contains the reference to the TestTarget
5. Save the diagram
6. Reopen the diagram and the reference reappears even graphically