/**
   * Builds the command which will execute the user-tasks specified operations to reorder an
   * instance role.
   *
   * @param sequenceDDiagram the DRepresentation to use for the ModelOperations
   * @param reorderTool the user-defined instance role reordering tool.
   * @param element the semantic element of the instance role which was moved.
   * @param predecessorBefore the semantic element corresponding to the instance role immediately
   *     preceding the reordered instance role before the move.
   * @param predecessorAfter the semantic element corresponding to the instance role immediately
   *     preceding the reordered instance role after the move.
   * @return a command which executes the user-specified operations with the appropriate variables
   *     set.
   */
  public static SiriusCommand buildInstanceRoleReorderCommand(
      SequenceDDiagram sequenceDDiagram,
      InstanceRoleReorderTool reorderTool,
      EObject element,
      EObject predecessorBefore,
      EObject predecessorAfter) {
    ModelAccessor modelAccessor =
        SiriusPlugin.getDefault().getModelAccessorRegistry().getModelAccessor(element);
    TransactionalEditingDomain domain = TransactionUtil.getEditingDomain(element);

    SiriusCommand result =
        new SiriusCommand(domain, new IdentifiedElementQuery(reorderTool).getLabel());
    if (reorderTool.getInstanceRoleMoved().getFirstModelOperations() != null) {
      result
          .getTasks()
          .add(
              ToolCommandBuilder.buildVariablesInitializationTask(
                  reorderTool, element, predecessorBefore, predecessorAfter));
      TaskHelper taskHelper = new TaskHelper(modelAccessor, new EMFCommandFactoryUI());
      result
          .getTasks()
          .add(
              taskHelper.buildTaskFromModelOperation(
                  sequenceDDiagram,
                  element,
                  reorderTool.getInstanceRoleMoved().getFirstModelOperations()));
    }
    return result;
  }
 private static InitInterpreterVariablesTask buildVariablesInitializationTask(
     InstanceRoleReorderTool reorderTool,
     EObject element,
     EObject predecessorBefore,
     EObject predecessorAfter) {
   Map<AbstractVariable, Object> variables = Maps.newHashMap();
   variables.put(reorderTool.getPredecessorBefore(), predecessorBefore);
   variables.put(reorderTool.getPredecessorAfter(), predecessorAfter);
   return new InitInterpreterVariablesTask(
       variables, InterpreterUtil.getInterpreter(element), null);
 }