/*
   * (non-Javadoc)
   *
   * @see org.eclipse.gef.commands.CompoundCommand#canExecute()
   */
  @Override
  public boolean canExecute() {
    boolean sameProvider = false;
    boolean mappingExisted = false;

    if (srcProvider != null && targetProvider != null) {
      sameProvider = srcProvider == targetProvider;
    }

    Collection<ParameterMapping> currMappings;

    if (container instanceof FlowDiagram) {
      currMappings = ((FlowDiagram) container).getParameterMappings();
    } else {
      currMappings = ((Activity) container).getParameterMappings();
    }

    for (ParameterMapping m : currMappings) {
      if (m.getSrc() == src && m.getTarget() == target) {
        mappingExisted = true;

        break;
      }
    }

    return super.canExecute() && src != target && !sameProvider && !mappingExisted;
  }
  private void init() {
    if (src != null && target != null && newMapping != null && container != null) {
      srcProvider = src.getProvider();
      targetProvider = target.getProvider();

      newMapping.setSrc(src);
      newMapping.setTarget(target);

      if (container instanceof FlowDiagram) {
        add(
            new SimpleAddEObjectCommand<FlowDiagram, ParameterMapping>(
                newMapping,
                FlowControlPackage.Literals.FLOW_DIAGRAM__PARAMETER_MAPPINGS,
                (FlowDiagram) container));
      } else if (container instanceof Activity) {
        add(
            new SimpleAddEObjectCommand<Activity, ParameterMapping>(
                newMapping, FlowControlPackage.ACTIVITY__PARAMETER_MAPPINGS, (Activity) container));
      }
    }
  }