Search in sources :

Example 1 with ICellPainter

use of org.eclipse.nebula.widgets.nattable.painter.cell.ICellPainter in project nebula.widgets.nattable by eclipse.

the class ComboBoxFilterRowConfiguration method configureRegistry.

@Override
public void configureRegistry(IConfigRegistry configRegistry) {
    configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR, this.cellEditor, DisplayMode.NORMAL, GridRegion.FILTER_ROW);
    configRegistry.registerConfigAttribute(FilterRowConfigAttributes.TEXT_MATCHING_MODE, TextMatchingMode.REGULAR_EXPRESSION);
    ICellPainter cellPainter = new CellPainterDecorator(new TextPainter() {

        {
            this.paintFg = false;
        }

        // override the preferred width and height to be 0, as otherwise
        // the String that is generated in the background for multiple
        // selection will be taken into account for auto resizing
        @Override
        public int getPreferredWidth(ILayerCell cell, GC gc, IConfigRegistry configRegistry) {
            return 0;
        }

        @Override
        public int getPreferredHeight(ILayerCell cell, GC gc, IConfigRegistry configRegistry) {
            return 0;
        }
    }, CellEdgeEnum.RIGHT, this.filterIconPainter);
    configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, cellPainter, DisplayMode.NORMAL, GridRegion.FILTER_ROW);
}
Also used : IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) TextPainter(org.eclipse.nebula.widgets.nattable.painter.cell.TextPainter) CellPainterDecorator(org.eclipse.nebula.widgets.nattable.painter.cell.decorator.CellPainterDecorator) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell) GC(org.eclipse.swt.graphics.GC) ICellPainter(org.eclipse.nebula.widgets.nattable.painter.cell.ICellPainter)

Example 2 with ICellPainter

use of org.eclipse.nebula.widgets.nattable.painter.cell.ICellPainter in project nebula.widgets.nattable by eclipse.

the class HierarchicalTreeLayer method getCellPainter.

@Override
public ICellPainter getCellPainter(int columnPosition, int rowPosition, ILayerCell cell, IConfigRegistry configRegistry) {
    ICellPainter cellPainter = super.getCellPainter(columnPosition, rowPosition, cell, configRegistry);
    if (cell.getConfigLabels().hasLabel(TreeLayer.TREE_COLUMN_CELL)) {
        ICellPainter treeCellPainter = configRegistry.getConfigAttribute(TreeConfigAttributes.TREE_STRUCTURE_PAINTER, cell.getDisplayMode(), cell.getConfigLabels().getLabels());
        if (treeCellPainter != null) {
            IndentedTreeImagePainter treePainter = findIndentedTreeImagePainter(treeCellPainter);
            if (treePainter != null) {
                treePainter.setBaseCellPainter(cellPainter);
                cellPainter = treeCellPainter;
            } else {
                // $NON-NLS-1$
                LOG.warn("There is no IndentedTreeImagePainter found for TREE_STRUCTURE_PAINTER");
            }
        } else {
            // $NON-NLS-1$
            LOG.warn("There is no IndentedTreeImagePainter found for TREE_STRUCTURE_PAINTER");
        }
    }
    return cellPainter;
}
Also used : IndentedTreeImagePainter(org.eclipse.nebula.widgets.nattable.tree.painter.IndentedTreeImagePainter) ICellPainter(org.eclipse.nebula.widgets.nattable.painter.cell.ICellPainter)

Example 3 with ICellPainter

use of org.eclipse.nebula.widgets.nattable.painter.cell.ICellPainter in project nebula.widgets.nattable by eclipse.

the class DefaultHierarchicalTreeLayerConfiguration method configureRegistry.

@Override
public void configureRegistry(IConfigRegistry configRegistry) {
    // configure the tree structure painter
    ICellPainter treeImagePainter = new PaddingDecorator(new TreeImagePainter(), 5, 2, 5, 2);
    IndentedTreeImagePainter treePainter = new IndentedTreeImagePainter(0, CellEdgeEnum.TOP_LEFT, treeImagePainter);
    treePainter.getInternalPainter().setPaintDecorationDependent(false);
    ICellPainter treeStructurePainter = new BackgroundPainter(treePainter);
    configRegistry.registerConfigAttribute(TreeConfigAttributes.TREE_STRUCTURE_PAINTER, treeStructurePainter, DisplayMode.NORMAL);
    // configure the style and the cell painter for the tree/node columns
    // necessary because the IndentedTreeImagePainter is inspecting and
    // using the underlying painter
    ICellPainter basePainter = new PaddingDecorator(new TextPainter(), 2, 2, 2, 15);
    configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, basePainter, DisplayMode.NORMAL, TreeLayer.TREE_COLUMN_CELL);
    Style treeStyle = new Style();
    treeStyle.setAttributeValue(CellStyleAttributes.VERTICAL_ALIGNMENT, VerticalAlignmentEnum.TOP);
    treeStyle.setAttributeValue(CellStyleAttributes.HORIZONTAL_ALIGNMENT, HorizontalAlignmentEnum.LEFT);
    configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, treeStyle, DisplayMode.NORMAL, TreeLayer.TREE_COLUMN_CELL);
    // configure styling for tree level header
    Style levelHeaderStyle = new Style();
    levelHeaderStyle.setAttributeValue(CellStyleAttributes.BACKGROUND_COLOR, this.levelHeaderColor);
    configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, levelHeaderStyle, DisplayMode.NORMAL, HierarchicalTreeLayer.LEVEL_HEADER_CELL);
    Style levelHeaderSelectedStyle = new Style();
    levelHeaderSelectedStyle.setAttributeValue(CellStyleAttributes.BACKGROUND_COLOR, this.levelHeaderSelectedColor);
    configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, levelHeaderSelectedStyle, DisplayMode.SELECT, HierarchicalTreeLayer.LEVEL_HEADER_CELL);
    // register special empty painter to not render content in collapsed
    // childs
    // this also allows for example some different styling of collapsed
    // childs
    configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, new BackgroundPainter(), DisplayMode.NORMAL, HierarchicalTreeLayer.COLLAPSED_CHILD);
    // configure alternate row style
    Style evenRowCellStyle = new Style();
    evenRowCellStyle.setAttributeValue(CellStyleAttributes.BACKGROUND_COLOR, this.evenRowBgColor);
    configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, evenRowCellStyle, DisplayMode.NORMAL, AlternatingRowConfigLabelAccumulator.EVEN_ROW_CONFIG_TYPE);
    Style oddRowCellStyle = new Style();
    oddRowCellStyle.setAttributeValue(CellStyleAttributes.BACKGROUND_COLOR, this.oddRowBgColor);
    configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, oddRowCellStyle, DisplayMode.NORMAL, AlternatingRowConfigLabelAccumulator.ODD_ROW_CONFIG_TYPE);
    configureEditableRules(configRegistry);
}
Also used : BackgroundPainter(org.eclipse.nebula.widgets.nattable.painter.cell.BackgroundPainter) PaddingDecorator(org.eclipse.nebula.widgets.nattable.painter.cell.decorator.PaddingDecorator) Style(org.eclipse.nebula.widgets.nattable.style.Style) TextPainter(org.eclipse.nebula.widgets.nattable.painter.cell.TextPainter) IndentedTreeImagePainter(org.eclipse.nebula.widgets.nattable.tree.painter.IndentedTreeImagePainter) IndentedTreeImagePainter(org.eclipse.nebula.widgets.nattable.tree.painter.IndentedTreeImagePainter) TreeImagePainter(org.eclipse.nebula.widgets.nattable.tree.painter.TreeImagePainter) ICellPainter(org.eclipse.nebula.widgets.nattable.painter.cell.ICellPainter)

Example 4 with ICellPainter

use of org.eclipse.nebula.widgets.nattable.painter.cell.ICellPainter in project nebula.widgets.nattable by eclipse.

the class MaxCellBoundsHelper method getPreferredRowHeight.

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));
                    }
                    maxHeight = (preferredHeight > maxHeight) ? preferredHeight : maxHeight;
                }
            }
        }
    }
    return maxHeight;
}
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 5 with ICellPainter

use of org.eclipse.nebula.widgets.nattable.painter.cell.ICellPainter in project nebula.widgets.nattable by eclipse.

the class ThemeConfiguration method configureDefaultStyle.

/**
 * Register default style configurations. Typically these configurations are
 * used be the body region and will be overridden by more specific
 * configurations of the header regions or custom styling based on labels.
 *
 * @param configRegistry
 *            The IConfigRegistry that is used by the NatTable instance to
 *            which the style configuration should be applied to.
 */
protected void configureDefaultStyle(IConfigRegistry configRegistry) {
    IStyle defaultStyle = getDefaultCellStyle();
    if (!isStyleEmpty(defaultStyle)) {
        // register body cell style for every display mode
        configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, defaultStyle);
    }
    ICellPainter defaultPainter = getDefaultCellPainter();
    if (defaultPainter != null) {
        // register body cell painter for every display mode
        configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, defaultPainter);
    }
}
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