// splitRepeatedCells must be called first in order to
// 1. update parent row if the row is the repeated rows.
// 2. update the cell itself if the cell is the column repeated cells.
void splitRepeatedCells() {
Table table = getTable();
TableTableRowElement ownerRowElement = getTableRowElement();
// 1.if the parent row is the repeated row
// the repeated row has to be separated
// after this the cell element and repeated index will be updated
// according to the new parent row
Row ownerRow = table.getRowInstance(ownerRowElement, mnRepeatedRowIndex);
if (ownerRow.getRowsRepeatedNumber() > 1) {
ownerRow.splitRepeatedRows();
// update row element, new row element maybe created.
ownerRowElement = ownerRow.maRowElement;
mnRepeatedRowIndex = 0;
}
// 2.if the cell is the column repeated cell
// this repeated cell has to be separated
int repeateNum = getColumnsRepeatedNumber();
if (repeateNum > 1) {
// change this repeated cell to three parts: repeated cell before,
// new single cell and repeated cell after.
Map<TableTableCellElementBase, Vector<Cell>> cellRepository = table.mCellRepository;
String tableNamespaceURI = OdfDocumentNamespace.TABLE.getUri();
Vector<Cell> oldList = null;
if (cellRepository.containsKey(mCellElement)) {
oldList = cellRepository.remove(mCellElement);
}
int offetAfterCurrentCell = repeateNum - mnRepeatedColIndex - 1;
TableTableCellElementBase currentCellElement = mCellElement;
TableTableCellElementBase newBeforeCellElement = null;
TableTableCellElementBase newAfterCellElement = null;
if (mnRepeatedColIndex > 0) {
newBeforeCellElement = (TableTableCellElementBase) mCellElement.cloneNode(true);
if (mnRepeatedColIndex > 1) {
newBeforeCellElement.setTableNumberColumnsRepeatedAttribute(mnRepeatedColIndex);
} else {
newBeforeCellElement.removeAttributeNS(tableNamespaceURI, "number-columns-repeated");
}
// insert new before repeated cell
ownerRowElement.insertBefore(newBeforeCellElement, currentCellElement);
// update cell cache
if (oldList != null) {
Vector<Cell> newBeforeList = new Vector<Cell>(mnRepeatedColIndex);
for (int i = 0; i < mnRepeatedColIndex && i < oldList.size(); i++) {
Cell beforeCell = oldList.get(i);
if (beforeCell != null) {
beforeCell.mCellElement = newBeforeCellElement;
newBeforeList.add(i, beforeCell);
}
}
cellRepository.put(newBeforeCellElement, newBeforeList);
}
}
currentCellElement.removeAttributeNS(tableNamespaceURI, "number-columns-repeated");
if (offetAfterCurrentCell > 0) {
newAfterCellElement = (TableTableCellElementBase) currentCellElement.cloneNode(true);
ownerRowElement.insertBefore(newAfterCellElement, currentCellElement);
currentCellElement = newAfterCellElement;
newAfterCellElement = (TableTableCellElementBase) currentCellElement.getNextSibling();
if (offetAfterCurrentCell > 1) {
newAfterCellElement.setTableNumberColumnsRepeatedAttribute(offetAfterCurrentCell);
}