/**
  * Returns the value to assign to the otherEnd variable.
  *
  * @return the end of the Edge before reconnection that is not represented by the SourceView
  *     variable
  */
 protected Object getOtherEndValue() {
   // If the reconnectionSource is equals to the sourceNode of the edge
   if (edge.getSourceNode().equals(reconnectionSource)) {
     // The other end will be the target node
     return edge.getTargetNode();
   } else {
     return edge.getSourceNode();
   }
 }
 /**
  * Construct a new Reconnection command builder.
  *
  * @param tool the reconnection tool
  * @param edge the edge which is reconnected
  * @param source the source of the reconnection
  * @param target the target of the reconnection
  */
 public ReconnectionCommandBuilder(
     final ReconnectEdgeDescription tool,
     final DEdge edge,
     final EdgeTarget source,
     final EdgeTarget target) {
   this.tool = tool;
   this.edge = edge;
   this.reconnectionSource = source;
   this.reconnectionTarget = target;
   this.oldTarget = edge.getTargetNode();
   this.oldSource = edge.getSourceNode();
 }
  /**
   * Generic service used to process treatments on a reconnect. The processing has to be defined by
   * overriding the corresponding caseXXX.
   *
   * @param context Element attached to the existing edge
   * @param edgeView Represents the graphical new edge
   * @param sourceView Represents the graphical element pointed by the edge before reconnecting
   * @param targetView Represents the graphical element pointed by the edge after reconnecting
   * @param source Represents the semantic element pointed by the edge before reconnecting
   * @param target Represents the semantic element pointed by the edge after reconnecting
   * @return the Element attached to the edge once it has been modified
   */
  public Element reconnectEdge(
      Element context,
      DEdge edgeView,
      EdgeTarget sourceView,
      EdgeTarget targetView,
      Element source,
      Element target) {
    final ReconnectSwitch reconnectService = new ReconnectSwitch();

    // The edge view represents the new graphical edge
    // with testing of its source and target nodes we can
    // know if the user reconnected the source or the target of the edge
    if (edgeView.getSourceNode().equals(sourceView)) {
      reconnectService.setReconnectKind(ReconnectSwitch.RECONNECT_SOURCE);
    } else {
      reconnectService.setReconnectKind(ReconnectSwitch.RECONNECT_TARGET);
    }
    reconnectService.setOldPointedElement(source);
    reconnectService.setNewPointedElement(target);
    reconnectService.setEdgeToReconnect(edgeView);
    return reconnectService.doSwitch(context);
  }