// 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!)
final ConflictingCell prevConflictCell = (ConflictingCell) prevCell;
final int count = prevConflictCell.getConflictingCellCount();
for (int x = 0; x < count; x++)
{
final 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)
{
final 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.");