/** 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()); } } }
/** * @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; }