void createDefinitionsIfMissing() {
    EList<EObject> contents = resource.getContents();

    if (contents.isEmpty() || !(contents.get(0) instanceof DocumentRoot)) {
      TransactionalEditingDomain domain = TransactionUtil.getEditingDomain(resource);

      if (domain != null) {
        final DocumentRoot docRoot = FACTORY.createDocumentRoot();
        final Definitions definitions = FACTORY.createDefinitions();
        //				definitions.setId(EcoreUtil.generateUUID());
        ModelUtil.setID(definitions, resource);
        Collaboration collaboration = FACTORY.createCollaboration();
        //				collaboration.setId(EcoreUtil.generateUUID());
        ModelUtil.setID(collaboration, resource);
        Participant participant = FACTORY.createParticipant();
        //				participant.setId(EcoreUtil.generateUUID());
        ModelUtil.setID(participant, resource);
        participant.setName("Internal");
        collaboration.getParticipants().add(participant);
        definitions.getRootElements().add(collaboration);

        domain
            .getCommandStack()
            .execute(
                new RecordingCommand(domain) {
                  @Override
                  protected void doExecute() {
                    docRoot.setDefinitions(definitions);
                    resource.getContents().add(docRoot);
                  }
                });
        return;
      }
    }
  }
  private Collaboration getOrCreateCollaboration() {
    final List<RootElement> rootElements = getDefinitions().getRootElements();

    for (RootElement element : rootElements) {
      if (element instanceof Collaboration) {
        return (Collaboration) element;
      }
    }
    TransactionalEditingDomain domain = TransactionUtil.getEditingDomain(resource);
    final Collaboration collaboration = FACTORY.createCollaboration();
    //		collaboration.setId(EcoreUtil.generateUUID());
    ModelUtil.setID(collaboration, resource);
    if (domain != null) {
      domain
          .getCommandStack()
          .execute(
              new RecordingCommand(domain) {

                @Override
                protected void doExecute() {
                  addCollaborationToRootElements(rootElements, collaboration);
                }
              });
    }
    return collaboration;
  }