Example #1
0
  /**
   * Adds to the underlying JGraphT graph an edge that corresponds to the specified JGraph edge. If
   * the specified JGraph edge is a dangling edge, it is NOT added to the underlying JGraphT graph.
   *
   * <p>This method is to be called only for edges that have already been added to the JGraph graph.
   *
   * @param jEdge the JGraph edge that has been added.
   */
  void handleJGraphInsertedEdge(org.jgraph.graph.Edge jEdge) {
    if (isDangling(jEdge)) {
      // JGraphT forbid dangling edges so we cannot add the edge yet. If
      // later the edge becomes connected, we will add it.
    } else {
      // FIXME hb 28-nov-05: waiting for jgraph to go generic
      Object jSource = getSourceVertex(this, jEdge);
      Object jTarget = getTargetVertex(this, jEdge);

      V jtSource = cellToVertex.get(jSource);
      V jtTarget = cellToVertex.get(jTarget);

      E jtEdge = jtGraph.addEdge(jtSource, jtTarget);

      if (jtEdge != null) {
        cellToEdge.put(jEdge, jtEdge);
        edgeToCell.put(jtEdge, jEdge);
      } else {
        // Adding failed because user is using a JGraphT graph the
        // forbids parallel edges.
        // For consistency, we remove the edge from the JGraph too.
        internalRemoveCell(jEdge);
        System.err.println(
            "Warning: an edge was deleted because the underlying "
                + "JGraphT graph refused to create it. "
                + "This situation can happen when a constraint of the "
                + "underlying graph is violated, e.g., an attempt to add "
                + "a parallel edge or a self-loop to a graph that forbids "
                + "them. To avoid this message, make sure to use a "
                + "suitable underlying JGraphT graph.");
      }
    }
  }