IEditorPart editor = IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(),
beanFile);
IModelManager modelManager = StructuredModelManager.getModelManager();
model = (DOMModelImpl) modelManager.getModelForEdit(beanFile);
IDOMDocument document = model.getDocument();
model.beginRecording(this);
Node nextSibling = null;
IDOMElement parentNode;
if (existingBean != null) {
nextSibling = existingBean.getNextSibling();
parentNode = (IDOMElement) existingBean.getParentNode();
parentNode.removeChild(existingBean);
}
else {
parentNode = (IDOMElement) document.getDocumentElement();
}
IDOMElement bean = (IDOMElement) document.importNode(newBean, true);
if (nextSibling != null) {
parentNode.insertBefore(bean, nextSibling);
}
else {
parentNode.appendChild(bean);