Search in sources :

Example 1 with ImagePainter

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

the class Rendering_cells_as_a_link_and_button method addButtonToColumn.

private void addButtonToColumn(IConfigRegistry configRegistry) {
    this.buttonPainter = new ButtonCellPainter(new CellPainterDecorator(new TextPainter(), CellEdgeEnum.RIGHT, new ImagePainter(GUIHelper.getImage("preferences"))));
    configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, this.buttonPainter, DisplayMode.NORMAL, BUTTON_CELL_LABEL);
    // Add your listener to the button
    this.buttonPainter.addClickListener(new MyMouseAction());
    // Set the color of the cell. This is picked up by the button painter to
    // style the button
    Style style = new Style();
    style.setAttributeValue(CellStyleAttributes.BACKGROUND_COLOR, GUIHelper.COLOR_WHITE);
    configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, style, DisplayMode.NORMAL, BUTTON_CELL_LABEL);
    configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, style, DisplayMode.SELECT, BUTTON_CELL_LABEL);
}
Also used : Style(org.eclipse.nebula.widgets.nattable.style.Style) TextPainter(org.eclipse.nebula.widgets.nattable.painter.cell.TextPainter) ButtonCellPainter(org.eclipse.nebula.widgets.nattable.painter.cell.ButtonCellPainter) CellPainterDecorator(org.eclipse.nebula.widgets.nattable.painter.cell.decorator.CellPainterDecorator) ImagePainter(org.eclipse.nebula.widgets.nattable.painter.cell.ImagePainter)

Example 2 with ImagePainter

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

the class CellPainterFactory method getCellPainter.

/**
 * @param backgroundKey
 *            The key of the background painter to use
 * @param decoratorKeys
 *            The list of keys of decorator painter to use
 * @param contentKey
 *            The key of the content painter to use
 * @param painterProperties
 *            The properties to set to the painters
 * @return The {@link ICellPainter} construct that should be used for
 *         rendering
 */
public ICellPainter getCellPainter(String backgroundKey, List<String> decoratorKeys, String contentKey, Map<String, Object> painterProperties) {
    ICellPainter painter = null;
    // resolve content painter
    ICellPainter contentPainter = null;
    if (isContentPainterKey(contentKey)) {
        contentPainter = getContentPainter(contentKey, painterProperties);
    } else if (!NONE.equalsIgnoreCase(contentKey)) {
        // fallback for unknown content painter key
        contentPainter = getContentPainter(TEXT_PAINTER_KEY, painterProperties);
    }
    // intermediate result = content painter
    painter = contentPainter;
    // resolve decorators
    String decoratorKey = null;
    for (int i = decoratorKeys.size() - 1; i >= 0; i--) {
        decoratorKey = decoratorKeys.get(i);
        if (DECORATOR_KEY.equalsIgnoreCase(decoratorKey)) {
            CellPainterDecorator decorator = new CellPainterDecorator();
            decorator.setPaintBackground(false);
            decorator.setBaseCellPainter(painter);
            Image image = (Image) painterProperties.get(NatTableCSSConstants.DECORATOR_IMAGE);
            CellEdgeEnum edge = (CellEdgeEnum) painterProperties.get(NatTableCSSConstants.DECORATOR_EDGE);
            Integer spacing = (Integer) painterProperties.get(NatTableCSSConstants.DECORATOR_SPACING);
            Boolean paintDecorationDependent = (Boolean) painterProperties.get(NatTableCSSConstants.PAINT_DECORATION_DEPENDENT);
            decorator.setDecoratorCellPainter(new ImagePainter(image, false));
            decorator.setCellEdge(edge);
            decorator.setSpacing(spacing);
            decorator.setPaintDecorationDependent(paintDecorationDependent);
            painter = decorator;
        } else {
            CellPainterWrapper decorator = getDecoratorPainter(decoratorKey, painterProperties, painter);
            if (decorator != null) {
                painter = decorator;
            }
        }
    }
    // add background painter
    if (backgroundKey != null) {
        CellPainterWrapper bgPainter = getBackgroundPainter(backgroundKey, painterProperties, painter);
        if (bgPainter != null) {
            bgPainter.setWrappedPainter(painter);
            painter = bgPainter;
        }
    }
    return painter;
}
Also used : CellEdgeEnum(org.eclipse.nebula.widgets.nattable.ui.util.CellEdgeEnum) CellPainterWrapper(org.eclipse.nebula.widgets.nattable.painter.cell.CellPainterWrapper) CellPainterDecorator(org.eclipse.nebula.widgets.nattable.painter.cell.decorator.CellPainterDecorator) Image(org.eclipse.swt.graphics.Image) ICellPainter(org.eclipse.nebula.widgets.nattable.painter.cell.ICellPainter) ImagePainter(org.eclipse.nebula.widgets.nattable.painter.cell.ImagePainter) ColumnGroupExpandCollapseImagePainter(org.eclipse.nebula.widgets.nattable.group.painter.ColumnGroupExpandCollapseImagePainter) IndentedTreeImagePainter(org.eclipse.nebula.widgets.nattable.tree.painter.IndentedTreeImagePainter) TreeImagePainter(org.eclipse.nebula.widgets.nattable.tree.painter.TreeImagePainter) BackgroundImagePainter(org.eclipse.nebula.widgets.nattable.painter.cell.BackgroundImagePainter) RowGroupExpandCollapseImagePainter(org.eclipse.nebula.widgets.nattable.group.painter.RowGroupExpandCollapseImagePainter)

Example 3 with ImagePainter

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

the class TableDecorationConfiguration method configureRegistry.

@Override
public void configureRegistry(IConfigRegistry configRegistry) {
    configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, new CellPainterDecorator(new TextPainter(), CellEdgeEnum.TOP, new ImagePainter(GUIHelper.getImage("plus")), this.paintDecorationdepentend), DisplayMode.NORMAL, CellPainterDecorator_Example.COLUMN_ONE_LABEL);
    configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, new CellPainterDecorator(new TextPainter(), CellEdgeEnum.BOTTOM, new ImagePainter(GUIHelper.getImage("plus")), this.paintDecorationdepentend), DisplayMode.NORMAL, CellPainterDecorator_Example.COLUMN_TWO_LABEL);
    configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, new CellPainterDecorator(new TextPainter(), CellEdgeEnum.LEFT, new ImagePainter(GUIHelper.getImage("plus")), this.paintDecorationdepentend), DisplayMode.NORMAL, CellPainterDecorator_Example.COLUMN_THREE_LABEL);
    configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, new CellPainterDecorator(new TextPainter(), CellEdgeEnum.RIGHT, new ImagePainter(GUIHelper.getImage("plus")), this.paintDecorationdepentend), DisplayMode.NORMAL, CellPainterDecorator_Example.COLUMN_FOUR_LABEL);
    configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, new CellPainterDecorator(new TextPainter(), CellEdgeEnum.TOP_LEFT, new ImagePainter(GUIHelper.getImage("plus")), this.paintDecorationdepentend), DisplayMode.NORMAL, CellPainterDecorator_Example.COLUMN_FIVE_LABEL);
    configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, new CellPainterDecorator(new TextPainter(), CellEdgeEnum.TOP_RIGHT, new ImagePainter(GUIHelper.getImage("plus")), this.paintDecorationdepentend), DisplayMode.NORMAL, CellPainterDecorator_Example.COLUMN_SIX_LABEL);
    configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, new CellPainterDecorator(new TextPainter(), CellEdgeEnum.BOTTOM_LEFT, new ImagePainter(GUIHelper.getImage("plus")), this.paintDecorationdepentend), DisplayMode.NORMAL, CellPainterDecorator_Example.COLUMN_SEVEN_LABEL);
    configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, new CellPainterDecorator(new TextPainter(), CellEdgeEnum.BOTTOM_RIGHT, new ImagePainter(GUIHelper.getImage("plus")), this.paintDecorationdepentend), DisplayMode.NORMAL, CellPainterDecorator_Example.COLUMN_EIGHT_LABEL);
}
Also used : TextPainter(org.eclipse.nebula.widgets.nattable.painter.cell.TextPainter) CellPainterDecorator(org.eclipse.nebula.widgets.nattable.painter.cell.decorator.CellPainterDecorator) ImagePainter(org.eclipse.nebula.widgets.nattable.painter.cell.ImagePainter)

Aggregations

ImagePainter (org.eclipse.nebula.widgets.nattable.painter.cell.ImagePainter)3 CellPainterDecorator (org.eclipse.nebula.widgets.nattable.painter.cell.decorator.CellPainterDecorator)3 TextPainter (org.eclipse.nebula.widgets.nattable.painter.cell.TextPainter)2 ColumnGroupExpandCollapseImagePainter (org.eclipse.nebula.widgets.nattable.group.painter.ColumnGroupExpandCollapseImagePainter)1 RowGroupExpandCollapseImagePainter (org.eclipse.nebula.widgets.nattable.group.painter.RowGroupExpandCollapseImagePainter)1 BackgroundImagePainter (org.eclipse.nebula.widgets.nattable.painter.cell.BackgroundImagePainter)1 ButtonCellPainter (org.eclipse.nebula.widgets.nattable.painter.cell.ButtonCellPainter)1 CellPainterWrapper (org.eclipse.nebula.widgets.nattable.painter.cell.CellPainterWrapper)1 ICellPainter (org.eclipse.nebula.widgets.nattable.painter.cell.ICellPainter)1 Style (org.eclipse.nebula.widgets.nattable.style.Style)1 IndentedTreeImagePainter (org.eclipse.nebula.widgets.nattable.tree.painter.IndentedTreeImagePainter)1 TreeImagePainter (org.eclipse.nebula.widgets.nattable.tree.painter.TreeImagePainter)1 CellEdgeEnum (org.eclipse.nebula.widgets.nattable.ui.util.CellEdgeEnum)1 Image (org.eclipse.swt.graphics.Image)1