Search in sources :

Example 36 with ICellPainter

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);
    }
}
Also used : ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer) Rectangle(org.eclipse.swt.graphics.Rectangle) ICellPainter(org.eclipse.nebula.widgets.nattable.painter.cell.ICellPainter)

Example 37 with ICellPainter

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;
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell) ICellPainter(org.eclipse.nebula.widgets.nattable.painter.cell.ICellPainter)

Example 38 with ICellPainter

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;
}
Also used : ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell) Point(org.eclipse.swt.graphics.Point) ICellPainter(org.eclipse.nebula.widgets.nattable.painter.cell.ICellPainter)

Example 39 with ICellPainter

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);
    }
}
Also used : IStyle(org.eclipse.nebula.widgets.nattable.style.IStyle) ICellPainter(org.eclipse.nebula.widgets.nattable.painter.cell.ICellPainter)

Example 40 with ICellPainter

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);
    }
}
Also used : IStyle(org.eclipse.nebula.widgets.nattable.style.IStyle) ICellPainter(org.eclipse.nebula.widgets.nattable.painter.cell.ICellPainter)

Aggregations

ICellPainter (org.eclipse.nebula.widgets.nattable.painter.cell.ICellPainter)50 IStyle (org.eclipse.nebula.widgets.nattable.style.IStyle)24 TextPainter (org.eclipse.nebula.widgets.nattable.painter.cell.TextPainter)11 Image (org.eclipse.swt.graphics.Image)10 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)9 IConfigRegistry (org.eclipse.nebula.widgets.nattable.config.IConfigRegistry)9 ILayerCell (org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell)9 BackgroundImagePainter (org.eclipse.nebula.widgets.nattable.painter.cell.BackgroundImagePainter)8 DefaultNatTableStyleConfiguration (org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration)6 IDataProvider (org.eclipse.nebula.widgets.nattable.data.IDataProvider)6 DataLayer (org.eclipse.nebula.widgets.nattable.layer.DataLayer)6 Rectangle (org.eclipse.swt.graphics.Rectangle)6 AbstractRegistryConfiguration (org.eclipse.nebula.widgets.nattable.config.AbstractRegistryConfiguration)5 DefaultColumnHeaderDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider)5 ColumnHeaderLayer (org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer)5 DefaultColumnHeaderDataLayer (org.eclipse.nebula.widgets.nattable.grid.layer.DefaultColumnHeaderDataLayer)5 SortableHeaderTextPainter (org.eclipse.nebula.widgets.nattable.sort.painter.SortableHeaderTextPainter)5 HashMap (java.util.HashMap)4 DefaultCornerDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider)4 DefaultRowHeaderDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider)4