// update style
mHeadingElement.setStyleName(mParagraphElement.getStyleName());
// unregister component
Component.unregisterComponent(mParagraphElement);
// replace paragraph with heading
OdfElement parentOdfElement = (OdfElement) mParagraphElement.getParentNode();
parentOdfElement.replaceChild(mHeadingElement, mParagraphElement);
mParagraphElement = null;
// re-register component.
Component.registerComponent(this, mHeadingElement);
}
// update outline level.
mHeadingElement.setTextOutlineLevelAttribute(level);
} else {
if (isHeading()) {
// need create new paragraph element and clone content.
OdfFileDom ownerDocument = (OdfFileDom) getOdfElement().getOwnerDocument();
mParagraphElement = ownerDocument.newOdfElement(TextPElement.class);
Node firstChild = mHeadingElement.getFirstChild();
while (firstChild != null) {
Node thisChild = firstChild;
firstChild = firstChild.getNextSibling();
mHeadingElement.removeChild(thisChild);
mParagraphElement.appendChild(thisChild);
}
// update style
mParagraphElement.setStyleName(mHeadingElement.getStyleName());
// unregister component
Component.unregisterComponent(mHeadingElement);
// replace heading with paragraph
OdfElement parentOdfElement = (OdfElement) mHeadingElement.getParentNode();
parentOdfElement.replaceChild(mParagraphElement, mHeadingElement);
mHeadingElement = null;
// re-register component.
Component.registerComponent(this, mParagraphElement);
}
}