code: public CmsContainerPageElementPanel replaceContainerElement(
          CmsContainerPageElementPanel containerElement,
          CmsContainerElementData elementData)
      throws Exception {
  
          I_CmsDropContainer parentContainer = containerElement.getParentTarget();
          String containerId = parentContainer.getContainerId();
          CmsContainerPageElementPanel replacer = null;
          String elementContent = elementData.getContents().get(containerId);
          if ((elementContent != null) && (elementContent.trim().length() > 0)) {
              replacer = getContainerpageUtil().createElement(elementData, parentContainer, false);
  
              if (containerElement.isNew()) {
                  // if replacing element data has the same structure id, keep the 'new' state by setting the new type property
                  // this should only be the case when editing settings of a new element that has not been created in the VFS yet
                  String id = getServerId(containerElement.getId());
                  if (elementData.getClientId().startsWith(id)) {
                      replacer.setNewType(containerElement.getNewType());
                  }
              }
              replacer.setCreateNew(containerElement.isCreateNew());
              // replacer.setModelGroup(containerElement.isModelGroup());
              if (isGroupcontainerEditing() && (containerElement.getInheritanceInfo() != null)) {
                  // in case of inheritance container editing, keep the inheritance info
                  replacer.setInheritanceInfo(containerElement.getInheritanceInfo());
                  // set the proper element options
                  CmsInheritanceContainerEditor.getInstance().setOptionBar(replacer);
              }
              parentContainer.insert(replacer, parentContainer.getWidgetIndex(containerElement));
              containerElement.removeFromParent();
              initializeSubContainers(replacer);
          }
          cleanUpContainers();
          return replacer;
      }
docs: Replaces the given drag-element with the given container element.<p>
  
  @param containerElement the container element to replace
  @param elementData the new element data
  
  @return the container element which replaced the old one
  
  @throws Exception if something goes wrong