if (infoStruct.isValidationDone())
{
return infoStruct;
}
RenderNode cellNode = rowBox.getFirstChild();
int cellPosition = 0;
while (cellNode != null)
{
if (cellNode instanceof TableCellRenderBox == false)
{
cellNode = cellNode.getNext();
continue;
}
TableCellRenderBox cellBox = (TableCellRenderBox) cellNode;
// we got a cell. Now check our info-struct ..
if (cellPosition >= prevInfoStruct.getCellCount())
{
cellBox.setColumnIndex(cellPosition);
cellPosition = validateSafeCellPos(cellBox, infoStruct, cellPosition);
}
else
{
cellPosition = findCellPosition(cellPosition, prevInfoStruct, infoStruct);
// OK, so we have the insertation point. Lets add our cell there ..
final int colSpan = cellBox.getColSpan();
final int rowSpan = cellBox.getRowSpan();
DataCell dataCell = new DataCell
(rowSpan, colSpan, cellBox.getInstanceId());
infoStruct.addCell(dataCell);
cellBox.setColumnIndex(cellPosition);
cellPosition += 1;
for (int i = 1; i < colSpan; i++)
{
// if there's a previous cell at the current position - check it
// maybe we have a conflicting instruction here
if (cellPosition < prevInfoStruct.getCellCount())
{
final TableCell prevCell = prevInfoStruct.getCellAt(cellPosition);
if (prevCell.getRowSpan() > 1)
{
// thats a conflict. Oh, no!
final ConflictingCell conflictingCell =
new ConflictingCell(dataCell, rowSpan, colSpan - i);
if (prevCell instanceof ConflictingCell)
{
// Oh, there's already a conflict? Coooool...
// (damn, users, fix your table definitions!)
ConflictingCell prevConflictCell = (ConflictingCell) prevCell;
final int count = prevConflictCell.getConflictingCellCount();
for (int x = 0; x < count; x++)
{
PlaceHolderCell phc = prevConflictCell.getConflictingCell(x);
if (phc.getRowSpan() > 1)
{
final PlaceHolderCell placeHolderCell =
new PlaceHolderCell(phc.getSourceCell(),
phc.getRowSpan() - 1,
phc.getColSpan());
conflictingCell.addConflictingCell(placeHolderCell);
}
}
}
else if (prevCell instanceof PlaceHolderCell)
{
PlaceHolderCell prevPHCell = (PlaceHolderCell) prevCell;
// a new conflict ...
final PlaceHolderCell placeHolderCell =
new PlaceHolderCell(prevPHCell.getSourceCell(),
prevCell.getRowSpan() - 1,
prevCell.getColSpan());
conflictingCell.addConflictingCell(placeHolderCell);
}
else if (prevCell instanceof DataCell)
{
final PlaceHolderCell placeHolderCell =
new PlaceHolderCell((DataCell) prevCell,
prevCell.getRowSpan() - 1,
prevCell.getColSpan());
conflictingCell.addConflictingCell(placeHolderCell);
}
else
{
throw new IllegalStateException("Unexpected cell type.");
}
infoStruct.addCell(conflictingCell);
}
else
{
final PlaceHolderCell placeHolderCell =
new PlaceHolderCell(dataCell, rowSpan, colSpan - i);
// a safe position. No conflicts ..
infoStruct.addCell(placeHolderCell);
}
}
else
{
final PlaceHolderCell placeHolderCell =
new PlaceHolderCell(dataCell, rowSpan, colSpan - i);
// no cells means: no conflicts. Thats always the easiest thing
infoStruct.addCell(placeHolderCell);
}
cellPosition += 1;
}
}
cellNode = cellNode.getNext();
}
final TableRow row = new TableRow(rowBox.getBorder());
section.getRowModel().addRow(row);