*/
public void applyHeading(boolean isHeading, int level) {
if (isHeading) {
if (!isHeading()) {
// create new heading element, clone children nodes.
OdfFileDom ownerDocument = (OdfFileDom) getOdfElement().getOwnerDocument();
mHeadingElement = ownerDocument.newOdfElement(TextHElement.class);
Node firstChild = mParagraphElement.getFirstChild();
while (firstChild != null) {
// mHeadingElement.appendChild(firstChild.cloneNode(true));
// firstChild = firstChild.getNextSibling();
Node thisChild = firstChild;
firstChild = firstChild.getNextSibling();
mParagraphElement.removeChild(thisChild);
mHeadingElement.appendChild(thisChild);
}
// 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);