/** Collapse edit part */
  private void collapseEditPart() {
    final Set<ConnectionEditPart> childrenConnections = getChildrenConnections();
    final Set<ConnectionEditPart> outsideConnections =
        excludeInternConnections(childrenConnections);
    final Set<ConnectionEditPart> edges = filterForDependencyConstraints(outsideConnections);

    for (final ConnectionEditPart outConnection : edges) {
      final EdgeImpl edge = (EdgeImpl) outConnection.getModel();

      // it's for undo/redo operations
      if (outConnection.getSource().getModel() != edge.getSource()
          || outConnection.getTarget().getModel() != edge.getTarget()) {
        return;
      }

      if (compartmentChildren.contains(outConnection.getSource())) {
        // readjust connection and update original source history
        // readjust at source
        edge.setSource((ShapeImpl) editPartOfCompartment.getModel());
        final Connection con = (Connection) edge.getElement();
        con.setTemp(true);
        final EList<Shape> oSources = con.getOriginalSource();
        oSources.add(con.getSource());
        con.setSource((Shape) ((ShapeImpl) editPartOfCompartment.getModel()).getElement());
      } else {
        // readjust at target
        edge.setTarget((ShapeImpl) editPartOfCompartment.getModel());
        final Connection con = (Connection) edge.getElement();
        con.setTemp(true);
        final EList<Shape> oTargets = con.getOriginalTarget();
        oTargets.add(con.getTarget());
        con.setTarget((Shape) ((ShapeImpl) editPartOfCompartment.getModel()).getElement());
      }
    }
  }
  /** Opens the edit part and restores the connections. */
  private void openEditPart() {

    final Set<ConnectionEditPart> connections = getAllConnections();

    for (final ConnectionEditPart i : connections) {
      final EdgeImpl edgeToRestore = (EdgeImpl) i.getModel();
      final Connection con = (Connection) edgeToRestore.getElement();

      if (con.isTemp()) {
        if (edgeToRestore.getSource() == editPartOfCompartment.getModel()
            && (!con.getOriginalSource().isEmpty())) {
          // readjust source
          final EList<Shape> oSources = con.getOriginalSource();
          final Shape source = oSources.remove(oSources.size() - 1);

          final NodeImpl shapeImpl = getViewFromModel(compartmentToSupport, source);

          edgeToRestore.setSource(shapeImpl);

          con.setSource(source);
        } else if (edgeToRestore.getTarget() == editPartOfCompartment.getModel()
            && (!con.getOriginalTarget().isEmpty())) {
          // readjust target
          final EList<Shape> oTargets = con.getOriginalTarget();
          final Shape target = oTargets.remove(oTargets.size() - 1);

          final NodeImpl shapeImpl = getViewFromModel(compartmentToSupport, target);
          edgeToRestore.setTarget(shapeImpl);

          con.setTarget(target);
        }
        if (con.getOriginalSource().isEmpty() && con.getOriginalTarget().isEmpty()) {
          // connection is points direct from original source to original target, thus it's not
          // temporal
          // anymore.
          con.setTemp(false);
        }
      }
    }
  }
  /**
   * This operation checks if, after resizing the ShapeNodeEditPart, all links anchors will fit
   * inside the figure in case their positions are preserved
   *
   * @param shapeEP That shape being resized
   * @param sizeDelta The SizeDelta for the resize
   * @param preserveAxis The axisxxx
   * @return The new SizeDelta to preserve anchors' positions
   */
  public static Dimension getSizeDeltaToFitAnchors(
      ShapeNodeEditPart shapeEP, Dimension sizeDelta, int preserveAxis) {

    Dimension newSizeDelta = new Dimension(sizeDelta);
    View view = (View) shapeEP.getModel();
    Rectangle figureBounds = shapeEP.getFigure().getBounds();

    List<Edge> sourceList = ViewUtil.getSourceConnections(view);
    List<Edge> targetList = ViewUtil.getTargetConnections(view);

    for (Edge edge : sourceList) {
      IdentityAnchor anchor = (IdentityAnchor) edge.getSourceAnchor();
      modifySizeDeltaToFitAnchor(anchor, newSizeDelta, preserveAxis, figureBounds);
    }
    for (Edge edge : targetList) {
      IdentityAnchor anchor = (IdentityAnchor) edge.getTargetAnchor();
      modifySizeDeltaToFitAnchor(anchor, newSizeDelta, preserveAxis, figureBounds);
    }

    return newSizeDelta;
  }