/**
   * Can be displayed.
   *
   * @param connector a connector
   * @param selectedView a view used as source or target for the connector to display
   * @param domain2NotationMap the map to complete if we found source and target View on the diagram
   *     to diplsay the connector
   * @return <code>true</code> if the view can be used as source/target for the connector according
   *     to the nested path AND if we found a second view for the 2nd connector end according to the
   *     nested path
   */
  protected boolean canBeDisplayed(
      final Connector connector,
      final View selectedView,
      final Domain2Notation domain2NotationMap) {
    // we need to verify the selected view
    final EObject semanticElement = selectedView.getElement();
    ConnectorEnd endForView = null;

    // 1. look for the connector end represented by the selected view
    for (final ConnectorEnd current : connector.getEnds()) {
      if (current.getRole() == semanticElement) {
        endForView = current;
        break;
      }
    }
    Assert.isNotNull(endForView);
    // 2. verify the view of the selected connector end
    if (!isCorrectGraphicalView(endForView, selectedView)) {
      return false;
    }

    // 3. try to find a view for the second connector end
    View secondView = null;
    for (final ConnectorEnd end : connector.getEnds()) {
      final ConnectableElement role = end.getRole();
      if (role == null) {
        return false;
      }
      if (end == endForView) {
        continue;
      }

      final Set<View> views =
          CrossReferencerUtil.getCrossReferencingViewsInDiagram(role, getCurrentDiagram());
      final Iterator<View> iterOnView = views.iterator();
      while (secondView == null && iterOnView.hasNext()) {
        final View currentView = iterOnView.next();
        if (isCorrectGraphicalView(end, currentView)) {
          domain2NotationMap.putView(endForView, selectedView);
          domain2NotationMap.putView(end, currentView);
          secondView = currentView;
        }
      }
    }
    return secondView != null;
  }
  /**
   * Gets the show link command.
   *
   * @param domain the editing domain to use for this command
   * @param linkToShow a link to show
   * @param domain2NotationMap the domain2 notation map
   * @param linkDescriptors the link descriptors
   * @return the command to display the link on the diagram
   */
  @Override
  protected ICommand getShowLinkCommand(
      final TransactionalEditingDomain domain,
      final EObject linkToShow,
      final Domain2Notation domain2NotationMap,
      final Collection<? extends UpdaterLinkDescriptor> linkDescriptors) {

    if (!(linkToShow instanceof Connector)) {
      return super.getShowLinkCommand(domain, linkToShow, domain2NotationMap, linkDescriptors);
    }
    domain2NotationMap.mapModel((View) getHost().getAdapter(View.class));

    // we look for the link descriptor
    UpdaterLinkDescriptor updaterLinkDescriptor = getLinkDescriptor(linkToShow, linkDescriptors);
    ICommand showLinkCommandFromUpdaterLinkDescriptor =
        getShowLinkCommandFromUpdaterLinkDescriptor(
            linkToShow, domain2NotationMap, updaterLinkDescriptor);
    return showLinkCommandFromUpdaterLinkDescriptor;
  }
  /**
   * Gets the show link command from updater link descriptor.
   *
   * @param linkToShow the link to show
   * @param domain2NotationMap the domain2 notation map
   * @param descriptor the descriptor
   * @return the show link command from updater link descriptor
   */
  private ICommand getShowLinkCommandFromUpdaterLinkDescriptor(
      final EObject linkToShow,
      final Domain2Notation domain2NotationMap,
      UpdaterLinkDescriptor descriptor) {
    ConnectorUtils connectorUtils = new ConnectorUtils();

    if (descriptor != null) {

      Set<View> sourceViewList = domain2NotationMap.get(descriptor.getSource());
      Set<View> targetViewList = domain2NotationMap.get(descriptor.getDestination());

      final Set<View> linkSet = domain2NotationMap.get(linkToShow);

      CompositeCommand compositeCommand = new CompositeCommand("Restore All Related Links");
      for (View sourceView : sourceViewList) {
        for (View targetView : targetViewList) {
          if (canDisplayExistingLinkBetweenViews(linkToShow, sourceView, targetView)) {

            if (ConnectorUtils.canDisplayExistingConnectorBetweenViewsAccordingToNestedPaths(
                (Connector) linkToShow, sourceView, targetView)) {
              boolean alreadyDisplayed = false;
              if (linkSet != null) {
                for (View viewLink : linkSet) {
                  boolean linkForViews =
                      isLinkForViews(
                          (org.eclipse.gmf.runtime.notation.Connector) viewLink,
                          sourceView,
                          targetView);
                  alreadyDisplayed = alreadyDisplayed || linkForViews;
                }
              }

              if (!alreadyDisplayed) {
                EditPart sourceEditPart = getEditPartFromView(sourceView);
                EditPart targetEditPart = getEditPartFromView(targetView);

                // If the parts are still null...
                if (sourceEditPart == null || targetEditPart == null) {
                  return null;
                }
                String semanticHint = getSemanticHint(linkToShow);
                CreateConnectionViewRequest.ConnectionViewDescriptor viewDescriptor =
                    new CreateConnectionViewRequest.ConnectionViewDescriptor(
                        descriptor.getSemanticAdapter(),
                        semanticHint,
                        ViewUtil.APPEND,
                        false,
                        ((GraphicalEditPart) getHost()).getDiagramPreferencesHint());
                CreateConnectionViewRequest ccr = new CreateConnectionViewRequest(viewDescriptor);
                ccr.setType(org.eclipse.gef.RequestConstants.REQ_CONNECTION_START);
                ccr.setSourceEditPart(sourceEditPart);
                sourceEditPart.getCommand(ccr);
                ccr.setTargetEditPart(targetEditPart);
                ccr.setType(org.eclipse.gef.RequestConstants.REQ_CONNECTION_END);
                CommandProxy commandProxy = new CommandProxy(targetEditPart.getCommand(ccr));
                compositeCommand.add(commandProxy);
              }
            }
          }
        }
      }
      return compositeCommand;
    }
    return null;
  }