eclipse-emfcloud / emfcloud-modelserver

Modelserver component
Other
40 stars 21 forks source link

Undo results unexpectedly when executing another command from the command stack in a Model Server command #274

Closed ikuta-tanigawa closed 10 months ago

ikuta-tanigawa commented 10 months ago

Bug Description:

Below is a sample program for this issue. Undo operations give unexpected results when executing another command in the doExecute() method. In this example, this command leaves two histories for undo. The first undo operation returns the model to the state before executing the command. The second undo operation returns the model to the state after executing the command.

public class IssueSampleCommand extends RecordingCommand {

   private AddShapeCommand command;
   private final EditingDomain domain;

   public IssueSampleCommand(final EditingDomain domain, final URI modelUri, final GPoint classPosition, final Supplier<? extends EObject> supplier) {
      super((TransactionalEditingDomain) domain);
      this.command = new AddShapeCommand(domain, modelUri, classPosition, supplier);
      this.domain = domain;
   }

   @Override
   protected void doExecute() {
      // This code occurs error when undo
      domain.getCommandStack().execute(command);
   }
}

Steps to Reproduce:

Below is a sample program to reproduce this problem.

Sample Program

This sample program is based on Coffee Editor and executes the above IssueSampleCommand instead of AddShapeCommand in AddAutomatedTaskCompoundCommand.

  1. Add an AutomatedTask to the empty superbrewer3000.notation and confirm the file contents are follows
<?xml version="1.0" encoding="ASCII"?>
<notation:Diagram xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:notation="http://www.eclipse.org/glsp/notation">
  <semanticElement elementId="47501d49-3a8d-4cb2-bed5-6263f5e5733b"/>
  <elements xsi:type="notation:Shape">
    <semanticElement elementId="24e262bf-8fc0-4140-8b4a-e865f08c4752"/>
    <position x="-130.0" y="-290.0"/>
  </elements>
</notation:Diagram>
  1. Execute an undo operation and confirm the file contents are follows
<?xml version="1.0" encoding="ASCII"?>
<notation:Diagram xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:notation="http://www.eclipse.org/glsp/notation">
  <semanticElement elementId="47501d49-3a8d-4cb2-bed5-6263f5e5733b"/>
</notation:Diagram>
  1. Confirm the second undo operation can be executed and check the file contents are follows
<?xml version="1.0" encoding="ASCII"?>
<notation:Diagram xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:notation="http://www.eclipse.org/glsp/notation">
  <semanticElement elementId="47501d49-3a8d-4cb2-bed5-6263f5e5733b"/>
  <elements xsi:type="notation:Shape">
    <semanticElement elementId="c7db8054-94ed-4aa2-913a-69a236b123f1"/>
    <position x="90.0" y="50.0"/>
  </elements>
</notation:Diagram>
ikuta-tanigawa commented 10 months ago

I can undo normally without using CommandStack.

command.execute();