private static int getPreferredRowHeight(ILayer layer, int rowPosition,
IConfigRegistry configRegistry, GC gc) {
int maxHeight = 0;
ICellPainter painter;
ILayerCell cell;
for (int columnPosition = 0; columnPosition < layer.getColumnCount(); columnPosition++) {
cell = layer.getCellByPosition(columnPosition, rowPosition);
if (cell != null) {
boolean atEndOfCellSpan = cell.getOriginRowPosition()
+ cell.getRowSpan() - 1 == rowPosition;
if (atEndOfCellSpan) {
painter = layer.getCellPainter(cell.getColumnPosition(),
cell.getRowPosition(), cell, configRegistry);
if (painter != null) {
int preferredHeight = painter.getPreferredHeight(cell,
gc, configRegistry);
// Adjust height
Rectangle bounds = cell.getBounds();
bounds.height = preferredHeight;
Rectangle adjustedCellBounds = cell
.getLayer()
.getLayerPainter()
.adjustCellBounds(columnPosition, rowPosition,
bounds);
preferredHeight += preferredHeight
- adjustedCellBounds.height;
if (cell.getColumnSpan() > 1) {
int rowStartY = layer
.getStartYOfRowPosition(rowPosition);
int cellStartY = layer.getStartYOfRowPosition(cell
.getOriginRowPosition());
preferredHeight = Math.max(0, preferredHeight
- (rowStartY - cellStartY));
}