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);
}
new ShallowFormatProcessorXML().formatNode(parentNode);
new FormatProcessorXML().formatNode(bean);
model.endRecording(this);
if (editor instanceof IConfigEditor) {
IConfigEditor configEditor = (IConfigEditor) editor;
int startOffset = bean.getStartOffset();
int length = bean.getEndOffset() - startOffset;
StructuredTextViewer textViewer = configEditor.getTextViewer();
textViewer.setRangeIndication(startOffset, length, true);
textViewer.revealRange(startOffset, length);
}