How-to create a "containment" relationship?

I want to create a requirement diagram with the following elements:

  • packages containing packages
  • packages containing requirements
  • requirements containing requirements
  • requirements composed of requirements

See the attached image for a sample of all these connections.

The “Composition” relationship is easy to implement:


IRequirement req11 = IModelElementFactory.instance().createRequirement();
IDiagramElement reqDiaElem11 = diagramManager.createDiagramElement(diagram1, req11);

IRequirement req12 = IModelElementFactory.instance().createRequirement();
IDiagramElement reqDiaElem12 = diagramManager.createDiagramElement(diagram1, req12);

IAssociation association1 = IModelElementFactory.instance().createAssociation();
association1.getFromEnd().setModelElement(req11);
association1.getToEnd().setModelElement(req12);
((IAssociationEnd)association1.getFromEnd()).setAggregationKind(IAssociationEnd.AGGREGATION_KIND_COMPOSITED);

diagramManager.createConnector(diagram1, association1, reqDiaElem11, reqDiaElem12, null);

But I don’t manage to create a “Containment” relationship between two diagram elements. Does anyone have an idea how to do this?

Regards,
Michael

relationships.png

Hi,

I too would like to know how to achieve this, only between a class and its inner classes.

I have tried several permutations, including the following, but to no avail.

diagramManager.createConnector(activeDiagram, "Containment", classDiagramElement1, classDiagramElement2, null);

Thanks in advance,
Gary

Hello Gary,

Please reference to the following article on how to create containment relationship with Open API.

Best regards,
Rain