#!/usr/bin/env python
import coral
from coral.modeler.xmidigraphbuilder import xmidibuilder
from coral.modeler.diagram import xmidi_diagrams
from coral.modeler import modeler

m=modeler.ModelerWindow()
m.main(loop=0)

L = coral.lang.UML14
X = coral.lang.XMIDI20

st = coral.Project()
m1 = L.Model()
m1.__setProject__(st)
m1.name = "Model1"
m2 = L.Model()
m2.name = "Model2"
m1.ownedElement.add(m2)


D = xmidi_diagrams.createDiagram(st, owner_elem=m1, typeinfo="ClassDiagram")

xmidibuilder(m1, D)


# Check that we have created a XMDI element for Model2
assert len(D.contained) == 1

# Focus on the diagram and check that Model2 has a widget
m.getDiagramEditorManager().editorSet.notifyFocusOn(D)

assert D.contained[0].widget.__getPyValue__()

# Check that the XMIDI element for Model2 contains a name and a bodycompartment
# This means that the model is correctly shown as a package in the diagram
assert D.contained[0].contained[0].semanticModel.typeInfo=="NameCompartment"
assert D.contained[0].contained[1].semanticModel.typeInfo=="BodyCompartment"
