// build the row header layer
IDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(
bodyLayer.getBodyDataProvider());
DataLayer rowHeaderDataLayer = new DefaultRowHeaderDataLayer(
rowHeaderDataProvider);
final ILayer rowHeaderLayer = new RowHeaderLayer(rowHeaderDataLayer,
bodyLayer, bodyLayer.getSelectionLayer());
// build the column header layer
IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(
propertyNames, propertyToLabelMap);
final DataLayer columnHeaderDataLayer = new DefaultColumnHeaderDataLayer(
columnHeaderDataProvider);
final AbstractLayer columnHeaderLayer = new ColumnHeaderLayer(
columnHeaderDataLayer, bodyLayer, bodyLayer.getSelectionLayer());
// Use this special layer painter that supports rendering of split
// viewports although
// the ColumnHeaderLayer is not split. Here is some custom calculation
// included that
// might not work correctly in case there are column groups or other
// spanning involved.
columnHeaderLayer.setLayerPainter(new CellLayerPainter() {
@Override
protected boolean isClipLeft(int position) {
// check position-1 because of the row header column count
// as the body is a composite layer, the default transformation
// for the grid is not working correctly
int index = LayerUtil.convertColumnPosition(columnHeaderLayer,
position - 1, columnHeaderDataLayer);
return (index > SPLIT_COLUMN_INDEX);
}
@Override
protected void paintCell(ILayerCell cell, GC gc,
IConfigRegistry configRegistry) {
ILayer layer = cell.getLayer();
int columnPosition = cell.getColumnPosition();
int rowPosition = cell.getRowPosition();
ICellPainter cellPainter = layer.getCellPainter(columnPosition,
rowPosition, cell, configRegistry);
Rectangle adjustedCellBounds = layer.getLayerPainter()
.adjustCellBounds(columnPosition, rowPosition,
cell.getBounds());
if (cellPainter != null) {
Rectangle originalClipping = gc.getClipping();
int startX = getStartXOfColumnPosition(columnPosition);
int startY = getStartYOfRowPosition(rowPosition);
int endX = getStartXOfColumnPosition(cell
.getOriginColumnPosition() + cell.getColumnSpan());
int endY = getStartYOfRowPosition(cell
.getOriginRowPosition() + cell.getRowSpan());
// correct position of first column in right region
// find the last visible column in left region
int viewportBorderX = bodyLayer.getViewportLayerLeft()
.getClientAreaWidth() + rowHeaderLayer.getWidth();
if (isClipLeft(columnPosition) && startX < viewportBorderX) {
startX = viewportBorderX;
}
if (!isClipLeft(columnPosition - 1)
&& startX > viewportBorderX) {
startX = viewportBorderX;
}
if (isClipLeft(cell.getOriginColumnPosition()
+ cell.getColumnSpan())
&& endX < viewportBorderX) {
endX = viewportBorderX;
}
Rectangle cellClipBounds = originalClipping
.intersection(new Rectangle(startX, startY, endX
- startX, endY - startY));
gc.setClipping(cellClipBounds
.intersection(adjustedCellBounds));
cellPainter.paintCell(cell, gc, adjustedCellBounds,
configRegistry);
gc.setClipping(originalClipping);
}
}
});
// build the corner layer
IDataProvider cornerDataProvider = new DefaultCornerDataProvider(
columnHeaderDataProvider, rowHeaderDataProvider);
DataLayer cornerDataLayer = new DataLayer(cornerDataProvider);
final ILayer cornerLayer = new CornerLayer(cornerDataLayer,
rowHeaderLayer, columnHeaderLayer);
// build the grid layer
GridLayer gridLayer = new GridLayer(bodyLayer, columnHeaderLayer,
rowHeaderLayer, cornerLayer);