/** 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());
      }
    }
  }
 /**
  * Filter connections for EdgeImpl; Subclass ConnectorImpl will be left out.
  *
  * @param connections Connections to be filtered.
  * @return Returns filtered connections.
  */
 private static Set<ConnectionEditPart> filterForDependencyConstraints(
     final Set<ConnectionEditPart> connections) {
   final Set<ConnectionEditPart> result = new HashSet<ConnectionEditPart>();
   for (final ConnectionEditPart conn : connections) {
     final EdgeImpl edge = (EdgeImpl) conn.getModel();
     if (edge.getElement() != null && edge.getElement() instanceof Connection) {
       result.add(conn);
     }
   }
   return result;
 }
  /**
   * @param connections
   * @return Returns the given connections without intra-connections, i.e. connections between
   *     children or connections between child and parent.
   */
  private Set<ConnectionEditPart> excludeInternConnections(
      final Set<ConnectionEditPart> connections) {
    final List<EditPart> internalParts =
        EditPartService.getAllShapesInSideCompartment(compartmentToSupport);

    // connections from children to its parent are also internal
    internalParts.add(editPartOfCompartment);

    for (final ConnectionEditPart c : connections) {
      // check if connection has one end outside of compartment
      if (internalParts.contains(c.getSource()) ^ internalParts.contains(c.getTarget())) {
        connections.add(c);
      }
    }

    return connections;
  }
  /** 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);
        }
      }
    }
  }
 @Override
 public boolean test() throws Exception {
   boolean location = false;
   PointList points = ((PolylineConnectionEx) connectionEditPart.getFigure()).getPoints();
   if (checkFirstBendpoint) {
     location = !initialLocation.equals(points.getFirstPoint());
   } else if (checkLastBendpoint) {
     location = !initialLocation.equals(points.getLastPoint());
   } else if (bendpointPosition >= 0 || bendpointPosition < points.size()) {
     location = !initialLocation.equals(points.getPoint(bendpointPosition));
   }
   return location;
 }