use of org.eclipse.nebula.widgets.nattable.painter.cell.ICellPainter in project nebula.widgets.nattable by eclipse.
the class CellLayerPainter method paintCell.
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());
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);
}
}
use of org.eclipse.nebula.widgets.nattable.painter.cell.ICellPainter in project nebula.widgets.nattable by eclipse.
the class MaxCellBoundsHelper method getPreferredColumnWidth.
/**
* Calculates the minimum width (in pixels) required to display the complete
* contents of the cells in a column. Takes into account the font settings
* and display type conversion.
*/
private static int getPreferredColumnWidth(ILayer layer, int columnPosition, IConfigRegistry configRegistry, GC gc) {
ICellPainter painter;
int maxWidth = 0;
ILayerCell cell;
for (int rowPosition = 0; rowPosition < layer.getRowCount(); rowPosition++) {
cell = layer.getCellByPosition(columnPosition, rowPosition);
if (cell != null) {
boolean atEndOfCellSpan = cell.getOriginColumnPosition() + cell.getColumnSpan() - 1 == columnPosition;
if (atEndOfCellSpan) {
painter = layer.getCellPainter(cell.getColumnPosition(), cell.getRowPosition(), cell, configRegistry);
if (painter != null) {
int preferredWidth = painter.getPreferredWidth(cell, gc, configRegistry);
// Adjust width
Rectangle bounds = cell.getBounds();
bounds.width = preferredWidth;
Rectangle adjustedCellBounds = cell.getLayer().getLayerPainter().adjustCellBounds(columnPosition, rowPosition, bounds);
preferredWidth += preferredWidth - adjustedCellBounds.width;
if (cell.getColumnSpan() > 1) {
int columnStartX = layer.getStartXOfColumnPosition(columnPosition);
int cellStartX = layer.getStartXOfColumnPosition(cell.getOriginColumnPosition());
preferredWidth = Math.max(0, preferredWidth - (columnStartX - cellStartX));
}
maxWidth = (preferredWidth > maxWidth) ? preferredWidth : maxWidth;
}
}
}
}
return maxWidth;
}
use of org.eclipse.nebula.widgets.nattable.painter.cell.ICellPainter in project nebula.widgets.nattable by eclipse.
the class NatTableContentTooltip method getText.
/**
* {@inheritDoc}
*
* <p>
* Evaluates the cell for which the tooltip should be rendered and checks
* the display value. If the display value is empty <code>null</code> will
* be returned which will result in not showing a tooltip.
*/
@Override
protected String getText(Event event) {
int col = this.natTable.getColumnPositionByX(event.x);
int row = this.natTable.getRowPositionByY(event.y);
ILayerCell cell = this.natTable.getCellByPosition(col, row);
if (cell != null) {
// if the registered cell painter is the PasswordCellPainter, there
// will be no tooltip
ICellPainter painter = this.natTable.getConfigRegistry().getConfigAttribute(CellConfigAttributes.CELL_PAINTER, DisplayMode.NORMAL, cell.getConfigLabels().getLabels());
if (isVisibleContentPainter(painter)) {
String tooltipValue = CellDisplayConversionUtils.convertDataType(cell, this.natTable.getConfigRegistry());
if (tooltipValue.length() > 0) {
return tooltipValue;
}
}
}
return null;
}
use of org.eclipse.nebula.widgets.nattable.painter.cell.ICellPainter in project nebula.widgets.nattable by eclipse.
the class ThemeConfiguration method configureRowHeaderSelectionStyle.
/**
* Register the style configurations for rendering the selection in a row
* header in a NatTable.
* <p>
* By default this means to register the style configurations against
* {@link DisplayMode#SELECT} and config/region label
* {@link GridRegion#ROW_HEADER}. The styling for rendering full row
* selection is configured against the label
* {@link SelectionStyleLabels#ROW_FULLY_SELECTED_STYLE}.
* </p>
*
* @param configRegistry
* The IConfigRegistry that is used by the NatTable instance to
* which the style configuration should be applied to.
*/
protected void configureRowHeaderSelectionStyle(IConfigRegistry configRegistry) {
IStyle rowHeaderStyle = getRowHeaderSelectionStyle();
if (!isStyleEmpty(rowHeaderStyle)) {
// register column header cell style in select mode
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, rowHeaderStyle, DisplayMode.SELECT, GridRegion.ROW_HEADER);
}
ICellPainter rowHeaderCellPainter = getRowHeaderSelectionCellPainter();
if (rowHeaderCellPainter != null) {
// register column header cell painter in select mode
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, rowHeaderCellPainter, DisplayMode.SELECT, GridRegion.ROW_HEADER);
}
IStyle fullSelectionRowHeaderStyle = getRowHeaderFullSelectionStyle();
if (!isStyleEmpty(fullSelectionRowHeaderStyle)) {
// register row header cell style in select mode when all cells in
// the row are selected
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, fullSelectionRowHeaderStyle, DisplayMode.SELECT, SelectionStyleLabels.ROW_FULLY_SELECTED_STYLE);
}
ICellPainter fullSelectionRowHeaderCellPainter = getRowHeaderFullSelectionCellPainter();
if (fullSelectionRowHeaderCellPainter != null) {
// register row header cell painter in select mode when all cells in
// the row are selected
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, fullSelectionRowHeaderCellPainter, DisplayMode.SELECT, SelectionStyleLabels.ROW_FULLY_SELECTED_STYLE);
}
}
use of org.eclipse.nebula.widgets.nattable.painter.cell.ICellPainter in project nebula.widgets.nattable by eclipse.
the class ThemeConfiguration method configureColumnGroupHeaderStyle.
/**
* This method is used to register style configurations for the column group
* header in a NatTable.
* <p>
* When adding the ColumnGroupHeaderLayer to a layer stack, there will be a
* new region with region label {@link GridRegion#COLUMN_GROUP_HEADER}.
* Typically it will share the same styling as the column header and have an
* internally configured {@link ICellPainter} to render dependent on the
* state of the ColumnGroupModel.
* </p>
*
* @param configRegistry
* The IConfigRegistry that is used by the NatTable instance to
* which the style configuration should be applied to.
*/
protected void configureColumnGroupHeaderStyle(IConfigRegistry configRegistry) {
IStyle columnGroupHeaderStyle = getColumnGroupHeaderStyle();
if (!isStyleEmpty(columnGroupHeaderStyle)) {
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, columnGroupHeaderStyle, DisplayMode.NORMAL, GridRegion.COLUMN_GROUP_HEADER);
}
ICellPainter columnGroupHeaderCellPainter = getColumnGroupHeaderCellPainter();
if (columnGroupHeaderCellPainter != null) {
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, columnGroupHeaderCellPainter, DisplayMode.NORMAL, GridRegion.COLUMN_GROUP_HEADER);
}
}
Aggregations