code: private ModelElementInstance findElementToInsertAfter(ModelElementInstance elementToInsert) {
      List<ModelElementType> childElementTypes = elementType.getAllChildElementTypes();
      List<DomElement> childDomElements = domElement.getChildElements();
      Collection<ModelElementInstance> childElements = ModelUtil.getModelElementCollection(childDomElements, modelInstance);
  
      ModelElementInstance insertAfterElement = null;
      int newElementTypeIndex = ModelUtil.getIndexOfElementType(elementToInsert, childElementTypes);
      for (ModelElementInstance childElement : childElements) {
        int childElementTypeIndex = ModelUtil.getIndexOfElementType(childElement, childElementTypes);
        if (newElementTypeIndex >= childElementTypeIndex) {
          insertAfterElement = childElement;
        }
        else {
          break;
        }
      }
      return insertAfterElement;
    }
docs: Returns the element after which the new element should be inserted in the DOM document.
  
  @param elementToInsert  the new element to insert
  @return the element to insert after or null