splitRepeatedRows();
Cell newCell = null;
Table ownerTable = getTable();
if (positionCell == null) {
if (refCell.isCoveredElement()) {
TableTableCellElement coverCellEle = (TableTableCellElement) refCell.getCoverCell().getOdfElement();
TableTableCellElement newCellEle = (TableTableCellElement) coverCellEle.cloneNode(true);
cleanCell(newCellEle);
getOdfElement().appendChild(newCellEle);
newCell = ownerTable.getCellInstance(newCellEle, 0, 0);
} else {
TableTableCellElement newCellEle = (TableTableCellElement) refCell.getOdfElement().cloneNode(true);
cleanCell(newCellEle);
getOdfElement().appendChild(newCellEle);
newCell = ownerTable.getCellInstance(newCellEle, 0, 0);
reviseStyleFromLastColumnToMedium(refCell);
}
} else {
TableTableCellElement coverRefCellEle = null;
TableTableCellElement coverPosCellEle = null;
Cell coverRefCell = null;
if (refCell.isCoveredElement()) {
// get ref cover cell
coverRefCell = refCell.getCoverCell();
coverRefCellEle = (TableTableCellElement) coverRefCell.getOdfElement();
}
if (positionCell.isCoveredElement()) {
// get position cover cell
coverPosCellEle = (TableTableCellElement) positionCell.getCoverCell().getOdfElement();
}
// is cover cell and have the same cover cell
// position cell is cover cell and refer cell covers position cell
if ((coverRefCellEle != null && coverRefCellEle == coverPosCellEle)
|| (coverPosCellEle != null && refCell.getOdfElement() == coverPosCellEle)) {
if (coverRefCellEle == null) {
coverRefCellEle = (TableTableCellElement) refCell.getOdfElement();
coverRefCell = refCell;
}
TableCoveredTableCellElement newCellEle = (TableCoveredTableCellElement) OdfXMLFactory.newOdfElement(
(OdfFileDom) ownerTable.getOdfElement().getOwnerDocument(), OdfName.newName(
OdfDocumentNamespace.TABLE, "covered-table-cell"));
getOdfElement().insertBefore(newCellEle, positionCell.getOdfElement());
if (refCell.getRowIndex() == coverRefCell.getRowIndex()) {
// the first cover line
coverRefCell.setColumnSpannedNumber(coverRefCell.getColumnSpannedNumber() + 1);
}
newCell = ownerTable.getCellInstance(newCellEle, 0, 0);
} else if (coverRefCellEle != null) {
// This is cover cell
if (refCell.getRowIndex() == coverRefCell.getRowIndex()) {
// the first cover line
TableTableCellElement newCellEle = (TableTableCellElement) coverRefCellEle.cloneNode(true);
cleanCell(newCellEle);
getOdfElement().insertBefore(newCellEle, positionCell.getOdfElement());
newCell = ownerTable.getCellInstance(newCellEle, 0, 0);
} else { // the second and other cover line
TableCoveredTableCellElement newCellEle = (TableCoveredTableCellElement) refCell.getOdfElement()
.cloneNode(true);
newCellEle.removeAttributeNS(OdfDocumentNamespace.TABLE.getUri(), "number-columns-repeated");
getOdfElement().insertBefore(newCellEle, positionCell.getOdfElement());
newCell = ownerTable.getCellInstance(newCellEle, 0, 0);
}
} else if ((refCell.getOdfElement() == positionCell.getOdfElement())
&& (refCell.getColumnsRepeatedNumber() > 1)) {
// repeated number
int repeatNum = refCell.getColumnsRepeatedNumber();
// update the cell that after the ref cell
for (int i = repeatNum - 1; i > refCell.mnRepeatedColIndex; i--) {
ownerTable.updateCellRepository(refCell.getOdfElement(), i, refCell.mnRepeatedRowIndex, refCell
.getOdfElement(), i + 1, refCell.mnRepeatedRowIndex);
}
refCell.getOdfElement().setTableNumberColumnsRepeatedAttribute(repeatNum + 1);
newCell = ownerTable.getCellInstance(refCell.getOdfElement(), refCell.mnRepeatedColIndex + 1,
refCell.mnRepeatedRowIndex);
} else {
TableTableCellElement newCellEle = (TableTableCellElement) refCell.getOdfElement().cloneNode(true);
cleanCell(newCellEle);
getOdfElement().insertBefore(newCellEle, positionCell.getOdfElement());
newCell = ownerTable.getCellInstance(newCellEle, 0, 0);
}
}