package org.framed.orm.ui.command.connectionkinds;



import org.eclipse.draw2d.geometry.Point;
import org.framed.orm.model.Relation;
import org.framed.orm.model.Relationship;
import org.framed.orm.model.RelationshipConstraint;

public class ORMRelationshipConstraintCreateCommand extends ORMRelationCreateCommand {


  private RelationshipConstraint relationCons;
  private Relationship rlship;

  @Override
  public boolean canExecute() {
    return target != null && source != null && relationCons != null && relcon != null && rlship != null;
  }

  @Override
  public void execute() {
    relationCons.setSource(source);
    relationCons.setTarget(target);
    relationCons.setRelationContainer(relcon);
    relationCons.setRelation(rlship);
    
    if (rlship.getRlshipConstraints().size() != 0) {
      relationCons.getDim1BP().addAll(rlship.getRlshipConstraints().get(0).getDim1BP());
      relationCons.getDim2BP().addAll(rlship.getRlshipConstraints().get(0).getDim2BP());
    }
    
    if (relationCons.getDim1BP().isEmpty()) {
      Point ps = new Point(source.getConstraints().x(), source.getConstraints().y());
      Point pt = new Point(target.getConstraints().x(), target.getConstraints().y());
      adaptRelationCreation(ps, pt);
    }
    
  }

  @Override
  public void undo() {
    relationCons.getSource().getOutgoingLinks().remove(relationCons);
    relationCons.setSource(null);
    relationCons.getTarget().getIncomingLinks().remove(relationCons);
    relationCons.setTarget(null);
    relationCons.setRelationContainer(null);
    relationCons.setRelation(null);
    relationCons.getDim1BP().clear();
    relationCons.getDim2BP().clear();
  }

  @Override
  public void setRelation(final Relation relation) {
    this.relationCons = (RelationshipConstraint) relation;
    this.relation = relation;
  }

  public void setRelationship(Relationship rlship) {
    this.rlship = rlship;
  }


  

}

@@ -515,24 +515,32 @@
 lcon != null
+%0A       
  && rlship !
@@ -547,16 +547,16 @@
 = null;%0A
-
   %7D%0A%0A  @
@@ -747,20 +747,16 @@
 lship);%0A
-    
 %0A    if 
@@ -797,12 +797,11 @@
 e() 
-!= 0
+%3E 1
 ) %7B%0A
@@ -987,57 +987,13 @@
    %7D
-%0A    %0A    if (relationCons.getDim1BP().isEmpty())
+ else
  %7B%0A 
@@ -1210,13 +1210,9 @@
   %7D%0A
-    
 %0A
+
   %7D%0A
@@ -1860,15 +1860,12 @@
 p;%0A  %7D%0A%0A
-%0A  
 %0A%0A%7D%0A

change a unnecessary if-query to a else and some formatting