@Override
  public Connection create(ICreateConnectionContext context) {
    Connection newConnection = null;
    // get EClasses which should be connected
    StandardNode source = getStandardNode(context.getSourcePictogramElement());
    StandardNode target = getStandardNode(context.getTargetPictogramElement());

    if (source != null && target != null && target != source) {
      // create new business object

      Link l = createLink(source, target);
      if (l == null) {
        return null;
      }

      // add connection for business object
      AddConnectionContext addContext =
          new AddConnectionContext(context.getSourceAnchor(), context.getTargetAnchor());
      addContext.setNewObject(l);
      newConnection = (Connection) getFeatureProvider().addIfPossible(addContext);

      PictogramElement pes = context.getSourcePictogramElement();
      PictogramElement pet = context.getTargetPictogramElement();

      if (source.getEdge().getChildNode().size() == 0) {
        pet.getGraphicsAlgorithm().setX(pes.getGraphicsAlgorithm().getX());
        pet.getGraphicsAlgorithm()
            .setY(pes.getGraphicsAlgorithm().getY() + pes.getGraphicsAlgorithm().getHeight() + 45);
      }
    }

    return newConnection;
  }
  @Override
  public boolean canStartConnection(ICreateConnectionContext context) {

    PictogramElement pe = context.getSourcePictogramElement();
    if (this.getBusinessObjectForPictogramElement(pe) != null) {
      if (this.getBusinessObjectForPictogramElement(pe) instanceof StandardNode) {
        StandardNode st = (StandardNode) this.getBusinessObjectForPictogramElement(pe);

        if (st.getEdge() == null
            || (st.getEdge() != null
                && st.getEdge().getComposition().getValue() != Composition.ATOMIC_VALUE)) {

          return true;
        }
      }
    }

    return false;
  }
  private Link createLink(StandardNode source, StandardNode target) {
    if (GraphBTUtil.isAncestor(target, source)) {
      return null;
    }
    if (target.isLeaf()) {
      return null;
    }
    Edge edge = source.getEdge();
    if (edge == null) {
      edge = GraphBTUtil.getBEFactory().createEdge();
      edge.setComposition(Composition.SEQUENTIAL);
      source.setEdge(edge);
      edge.setContainer(source);
    } else {
      for (int i = 0; i < edge.getChildNode().size(); i++) {
        if (edge.getChildNode().get(i).getTarget() == (target)) {
          return null;
        }
      }
      if (edge.getChildNode().size() == 1) {
        HashMap<Integer, String> map = new HashMap<Integer, String>();
        WizardDialog wizardDialog =
            new WizardDialog(
                PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                new ManageBranchWizardGraphBtFeature(map, getDiagram()));

        if (wizardDialog.open() != Window.OK) {
          return null;
        }

        edge.setBranch(Branch.get(map.get(1)));

        StandardNode sn = (StandardNode) edge.getChildNode().get(0).getTarget();

        ContainerShape cs = null;
        if (sn == null) {
          return null;
        }
        for (PictogramElement pe :
            Graphiti.getLinkService().getPictogramElements(getDiagram(), sn.getParent())) {
          if (pe instanceof ContainerShape) {
            cs = (ContainerShape) pe;
          }
        }
        //        		ContainerShape cs = (ContainerShape) pe;

        Iterator<Shape> s = cs.getChildren().iterator();
        while (s.hasNext()) {
          Shape n = s.next();

          Object bo =
              Graphiti.getLinkService()
                  .getBusinessObjectForLinkedPictogramElement((PictogramElement) n);
          if (bo instanceof AlternativeClass) {
            updatePictogramElement(n);
          }
        }
      }
    }
    Link l = GraphBTUtil.getBEFactory().createLink();
    l.setSource(source);
    l.setTarget(target);
    edge.getChildNode().add(l);
    target.setParent(source);
    target.setLeaf(true);
    return l;
  }