public EObject getBindingOpposite(BindingInfo bindingInfo, EObject opposite) {
   if (bindingInfo.getLeft().equals(opposite)) {
     return bindingInfo.getRight();
   } else if (bindingInfo.getRight().equals(opposite)) {
     return bindingInfo.getLeft();
   }
   return null;
 }
 public Collection<EObject> getBoundElementsWithTarget(Category category, EObject target) {
   Collection<EObject> results = new HashSet<EObject>();
   for (BindingInfo bindingInfo : getRelatedBindingInfos(category)) {
     if (bindingInfo.getLeft().equals(target)) {
       results.add(bindingInfo.getRight());
     } else if (bindingInfo.getRight().equals(target)) {
       results.add(bindingInfo.getLeft());
     }
   }
   return results;
 }
 private Collection<ServiceDTO> getBoundDTO(BindingRegistry registry) {
   Set<ServiceDTO> dtos = new HashSet<ServiceDTO>();
   for (BindingInfo bindingInfo : registry.getBindingInfos()) {
     if (bindingInfo.getLeft() instanceof ServiceDTO) {
       dtos.add((ServiceDTO) bindingInfo.getLeft());
     }
     if (bindingInfo.getRight() instanceof ServiceDTO) {
       dtos.add((ServiceDTO) bindingInfo.getRight());
     }
   }
   return dtos;
 }
 public String computeBindingEditorName(BindingInfo bindingInfo) {
   String name = "Binding ";
   name += getBoundElementName(bindingInfo.getLeft());
   name += " - ";
   name += getBoundElementName(bindingInfo.getRight());
   return name;
 }
  public Collection<Entity> getBoundEntities(Category category) {
    List<Entity> results = new ArrayList<Entity>();

    // Get the binding infos to consider
    Collection<BindingInfo> bindingInfos = getRelatedBindingInfos(category);

    for (BindingInfo bindingInfo : bindingInfos) {
      if (bindingInfo.getLeft() instanceof Entity) {
        results.add((Entity) bindingInfo.getLeft());
      }
      if (bindingInfo.getRight() instanceof Entity) {
        results.add((Entity) bindingInfo.getRight());
      }
    }

    return results;
  }
  public BindingInfo changeBindingTarget(
      BindingInfo bindingInfo, BoundableElement firstElement, BoundableElement secondElement) {
    if (bindingInfo.getLeft().equals(firstElement)) {
      bindingInfo.setRight(secondElement);
    } else if (bindingInfo.getRight().equals(firstElement)) {
      bindingInfo.setLeft(secondElement);
    }

    return bindingInfo;
  }
  public BindingInfo reconnectBindingTarget(
      BindingInfo bindingInfo, BoundableElement oldTarget, BoundableElement newTarget) {
    if (bindingInfo.getLeft().equals(oldTarget)) {
      bindingInfo.setLeft(newTarget);
    } else if (bindingInfo.getRight().equals(oldTarget)) {
      bindingInfo.setRight(newTarget);
    }

    return bindingInfo;
  }
  public Collection<ServiceDTO> getBoundExternalDTOs(Category category) {
    List<ServiceDTO> results = new ArrayList<ServiceDTO>();

    // Collect all DTOs in this category and its direct sub-categories
    Collection<StructuredType> dtos = getDTOAndChildrenDTOs(category);

    for (BindingInfo bi : getGlobalBindingRegistry(category).getBindingInfos()) {
      if (dtos.contains(bi.getLeft())
          && !dtos.contains(bi.getRight())
          && bi.getRight() instanceof ServiceDTO) {
        results.add((ServiceDTO) bi.getRight());
      } else if (dtos.contains(bi.getRight())
          && !dtos.contains(bi.getLeft())
          && bi.getLeft() instanceof ServiceDTO) {
        results.add((ServiceDTO) bi.getLeft());
      }
    }

    return results;
  }
  public Collection<StructuredType> getAllBindableElements(
      DSemanticDiagram diagram, StructuredType structuredType) {
    // Collect all structured types
    Collection<StructuredType> bindableElements = new ArrayList<StructuredType>();

    // First get all structured types
    bindableElements.addAll(getAllStructuredTypes(structuredType));

    // Remove the target element
    bindableElements.remove(structuredType);

    // Remove elements already bound with the target
    for (BindingInfo bindingInfo : getAllBindingInfosOnDiagram(diagram)) {
      if (bindingInfo.getLeft() == structuredType) {
        bindableElements.remove(bindingInfo.getRight());
      }
      if (bindingInfo.getRight() == structuredType) {
        bindableElements.remove(bindingInfo.getLeft());
      }
    }

    return bindableElements;
  }
  public Collection<BindingInfo> getRelatedBindingInfos(Category category) {
    List<BindingInfo> results = new ArrayList<BindingInfo>();

    // Collect all DTOs in this category and its direct sub-categories
    Collection<StructuredType> dtos = getDTOAndChildrenDTOs(category);

    // Check every BindingInfo instance
    BindingRegistry registry = getGlobalBindingRegistry(category);
    for (BindingInfo bindingInfo : registry.getBindingInfos()) {
      if (dtos.contains(bindingInfo.getLeft()) || dtos.contains(bindingInfo.getRight())) {
        results.add(bindingInfo);
      }
    }

    return results;
  }
 public String computeBindingEditorName(BindingInfo bindingInfo) {
   return String.format(
       "Binding %1s - %2s",
       getBoundElementName(bindingInfo.getLeft()), getBoundElementName(bindingInfo.getRight()));
 }