Search in sources :

Example 1 with CellPainterWrapper

use of org.eclipse.nebula.widgets.nattable.painter.cell.CellPainterWrapper 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 2 with CellPainterWrapper

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

the class NatTableCSSHandler method retrieveCSSProperty.

@Override
public String retrieveCSSProperty(Object control, String property, String pseudo, CSSEngine engine) throws Exception {
    NatTable natTable = null;
    String label = null;
    String displayMode = NatTableCSSHelper.getDisplayMode(pseudo);
    if (control instanceof NatTable) {
        natTable = (NatTable) control;
    } else if (control instanceof NatTableWrapper) {
        natTable = ((NatTableWrapper) control).getNatTable();
        label = ((NatTableWrapper) control).getLabel();
    }
    if (natTable != null) {
        // check property
        if (NatTableCSSConstants.BACKGROUND_COLOR.equalsIgnoreCase(property)) {
            return CSSPropertyBackgroundSWTHandler.INSTANCE.retrieveCSSPropertyBackgroundColor(control, pseudo, engine);
        } else if (NatTableCSSConstants.BACKGROUND_IMAGE.equalsIgnoreCase(property)) {
            return CSSPropertyBackgroundSWTHandler.INSTANCE.retrieveCSSPropertyBackgroundImage(control, pseudo, engine);
        } else if (NatTableCSSConstants.CELL_BACKGROUND_COLOR.equalsIgnoreCase(property)) {
            ICSSValueConverter cssValueConverter = engine.getCSSValueConverter(String.class);
            return cssValueConverter.convert(NatTableCSSHelper.getNatTableStyle(natTable, CellStyleAttributes.BACKGROUND_COLOR, displayMode, label), engine, null);
        } else if (NatTableCSSConstants.CELL_BACKGROUND_IMAGE.equalsIgnoreCase(property)) {
            // TODO : manage path of Image.
            return "none";
        } else if (NatTableCSSConstants.FOREGROUND_COLOR.equalsIgnoreCase(property)) {
            ICSSValueConverter cssValueConverter = engine.getCSSValueConverter(String.class);
            return cssValueConverter.convert(NatTableCSSHelper.getNatTableStyle(natTable, CellStyleAttributes.FOREGROUND_COLOR, displayMode, label), engine, null);
        } else if (NatTableCSSConstants.HORIZONTAL_ALIGNMENT.equalsIgnoreCase(property)) {
            HorizontalAlignmentEnum align = NatTableCSSHelper.getNatTableStyle(natTable, CellStyleAttributes.HORIZONTAL_ALIGNMENT, displayMode, label);
            switch(align) {
                case CENTER:
                    return "center";
                case LEFT:
                    return "left";
                case RIGHT:
                    return "right";
            }
        } else if (NatTableCSSConstants.VERTICAL_ALIGNMENT.equalsIgnoreCase(property)) {
            VerticalAlignmentEnum align = NatTableCSSHelper.getNatTableStyle(natTable, CellStyleAttributes.VERTICAL_ALIGNMENT, displayMode, label);
            switch(align) {
                case TOP:
                    return "top";
                case MIDDLE:
                    return "middle";
                case BOTTOM:
                    return "bottom";
            }
        } else if (NatTableCSSConstants.FONT.equalsIgnoreCase(property)) {
            Font font = NatTableCSSHelper.getNatTableStyle(natTable, CellStyleAttributes.FONT, displayMode, label);
            return CSSSWTFontHelper.getFontComposite(font);
        } else if (NatTableCSSConstants.FONT_FAMILY.equalsIgnoreCase(property)) {
            Font font = NatTableCSSHelper.getNatTableStyle(natTable, CellStyleAttributes.FONT, displayMode, label);
            return CSSSWTFontHelper.getFontFamily(font);
        } else if (NatTableCSSConstants.FONT_SIZE.equalsIgnoreCase(property)) {
            Font font = NatTableCSSHelper.getNatTableStyle(natTable, CellStyleAttributes.FONT, displayMode, label);
            return CSSSWTFontHelper.getFontSize(font);
        } else if (NatTableCSSConstants.FONT_STYLE.equalsIgnoreCase(property)) {
            Font font = NatTableCSSHelper.getNatTableStyle(natTable, CellStyleAttributes.FONT, displayMode, label);
            return CSSSWTFontHelper.getFontStyle(font);
        } else if (NatTableCSSConstants.FONT_WEIGHT.equalsIgnoreCase(property)) {
            Font font = NatTableCSSHelper.getNatTableStyle(natTable, CellStyleAttributes.FONT, displayMode, label);
            return CSSSWTFontHelper.getFontWeight(font);
        } else if (NatTableCSSConstants.IMAGE.equalsIgnoreCase(property)) {
            // TODO : manage path of Image.
            return "none";
        } else if (NatTableCSSConstants.BORDER.equalsIgnoreCase(property)) {
            BorderStyle border = NatTableCSSHelper.getNatTableStyle(natTable, CellStyleAttributes.BORDER_STYLE, displayMode, label);
            ICSSValueConverter cssValueConverter = engine.getCSSValueConverter(String.class);
            return border.getThickness() + " " + border.getLineStyle().toString().toLowerCase() + " " + border.getBorderMode().toString().toLowerCase() + " " + cssValueConverter.convert(border.getColor(), engine, null);
        } else if (NatTableCSSConstants.BORDER_COLOR.equalsIgnoreCase(property)) {
            BorderStyle border = NatTableCSSHelper.getNatTableStyle(natTable, CellStyleAttributes.BORDER_STYLE, displayMode, label);
            ICSSValueConverter cssValueConverter = engine.getCSSValueConverter(String.class);
            return cssValueConverter.convert(border.getColor(), engine, null);
        } else if (NatTableCSSConstants.BORDER_STYLE.equalsIgnoreCase(property)) {
            BorderStyle border = NatTableCSSHelper.getNatTableStyle(natTable, CellStyleAttributes.BORDER_STYLE, displayMode, label);
            return border.getLineStyle().toString().toLowerCase();
        } else if (NatTableCSSConstants.BORDER_WIDTH.equalsIgnoreCase(property)) {
            BorderStyle border = NatTableCSSHelper.getNatTableStyle(natTable, CellStyleAttributes.BORDER_STYLE, displayMode, label);
            return "" + border.getThickness();
        } else if (NatTableCSSConstants.BORDER_MODE.equalsIgnoreCase(property)) {
            BorderStyle border = NatTableCSSHelper.getNatTableStyle(natTable, CellStyleAttributes.BORDER_STYLE, displayMode, label);
            return "" + border.getBorderMode();
        } else if (NatTableCSSConstants.PASSWORD_ECHO_CHAR.equalsIgnoreCase(property)) {
            return "" + NatTableCSSHelper.getNatTableStyle(natTable, CellStyleAttributes.PASSWORD_ECHO_CHAR, displayMode, label);
        } else if (NatTableCSSConstants.TEXT_DECORATION.equalsIgnoreCase(property)) {
            TextDecorationEnum decoration = NatTableCSSHelper.getNatTableStyle(natTable, CellStyleAttributes.TEXT_DECORATION, displayMode, label);
            switch(decoration) {
                case NONE:
                    return "none";
                case STRIKETHROUGH:
                    return "line-through";
                case UNDERLINE:
                    return "underline";
                case UNDERLINE_STRIKETHROUGH:
                    return "underline line-through";
            }
        } else if (NatTableCSSConstants.FREEZE_SEPARATOR_COLOR.equalsIgnoreCase(property)) {
            ICSSValueConverter cssValueConverter = engine.getCSSValueConverter(String.class);
            return cssValueConverter.convert(natTable.getConfigRegistry().getConfigAttribute(IFreezeConfigAttributes.SEPARATOR_COLOR, displayMode, label), engine, null);
        } else if (NatTableCSSConstants.GRID_LINE_COLOR.equalsIgnoreCase(property)) {
            ICSSValueConverter cssValueConverter = engine.getCSSValueConverter(String.class);
            return cssValueConverter.convert(natTable.getConfigRegistry().getConfigAttribute(CellConfigAttributes.GRID_LINE_COLOR, displayMode, label), engine, null);
        } else if (NatTableCSSConstants.GRID_LINE_WIDTH.equalsIgnoreCase(property)) {
            Integer width = natTable.getConfigRegistry().getConfigAttribute(CellConfigAttributes.GRID_LINE_WIDTH, displayMode, label);
            if (width == null) {
                return "0";
            } else {
                return width.toString();
            }
        } else if (NatTableCSSConstants.RENDER_GRID_LINES.equalsIgnoreCase(property)) {
            Boolean render = natTable.getConfigRegistry().getConfigAttribute(CellConfigAttributes.RENDER_GRID_LINES, displayMode, label);
            if (render == null) {
                return Boolean.TRUE.toString();
            } else {
                return render.toString();
            }
        } else if (NatTableCSSConstants.CONVERSION_ERROR_FONT.equalsIgnoreCase(property)) {
            IStyle style = natTable.getConfigRegistry().getConfigAttribute(EditConfigAttributes.CONVERSION_ERROR_STYLE, displayMode, label);
            Font font = style.getAttributeValue(CellStyleAttributes.FONT);
            return CSSSWTFontHelper.getFontComposite(font);
        } else if (NatTableCSSConstants.CONVERSION_ERROR_FONT_FAMILY.equalsIgnoreCase(property)) {
            IStyle style = natTable.getConfigRegistry().getConfigAttribute(EditConfigAttributes.CONVERSION_ERROR_STYLE, displayMode, label);
            Font font = style.getAttributeValue(CellStyleAttributes.FONT);
            return CSSSWTFontHelper.getFontFamily(font);
        } else if (NatTableCSSConstants.CONVERSION_ERROR_FONT_SIZE.equalsIgnoreCase(property)) {
            IStyle style = natTable.getConfigRegistry().getConfigAttribute(EditConfigAttributes.CONVERSION_ERROR_STYLE, displayMode, label);
            Font font = style.getAttributeValue(CellStyleAttributes.FONT);
            return CSSSWTFontHelper.getFontSize(font);
        } else if (NatTableCSSConstants.CONVERSION_ERROR_FONT_STYLE.equalsIgnoreCase(property)) {
            IStyle style = natTable.getConfigRegistry().getConfigAttribute(EditConfigAttributes.CONVERSION_ERROR_STYLE, displayMode, label);
            Font font = style.getAttributeValue(CellStyleAttributes.FONT);
            return CSSSWTFontHelper.getFontStyle(font);
        } else if (NatTableCSSConstants.CONVERSION_ERROR_FONT_WEIGHT.equalsIgnoreCase(property)) {
            IStyle style = natTable.getConfigRegistry().getConfigAttribute(EditConfigAttributes.CONVERSION_ERROR_STYLE, displayMode, label);
            Font font = style.getAttributeValue(CellStyleAttributes.FONT);
            return CSSSWTFontHelper.getFontWeight(font);
        } else if (NatTableCSSConstants.CONVERSION_ERROR_BACKGROUND_COLOR.equalsIgnoreCase(property)) {
            ICSSValueConverter cssValueConverter = engine.getCSSValueConverter(String.class);
            IStyle style = natTable.getConfigRegistry().getConfigAttribute(EditConfigAttributes.CONVERSION_ERROR_STYLE, displayMode, label);
            return cssValueConverter.convert(style.getAttributeValue(CellStyleAttributes.BACKGROUND_COLOR), engine, null);
        } else if (NatTableCSSConstants.CONVERSION_ERROR_FOREGROUND_COLOR.equalsIgnoreCase(property)) {
            ICSSValueConverter cssValueConverter = engine.getCSSValueConverter(String.class);
            IStyle style = natTable.getConfigRegistry().getConfigAttribute(EditConfigAttributes.CONVERSION_ERROR_STYLE, displayMode, label);
            return cssValueConverter.convert(style.getAttributeValue(CellStyleAttributes.FOREGROUND_COLOR), engine, null);
        } else if (NatTableCSSConstants.VALIDATION_ERROR_FONT.equalsIgnoreCase(property)) {
            IStyle style = natTable.getConfigRegistry().getConfigAttribute(EditConfigAttributes.VALIDATION_ERROR_STYLE, displayMode, label);
            Font font = style.getAttributeValue(CellStyleAttributes.FONT);
            return CSSSWTFontHelper.getFontComposite(font);
        } else if (NatTableCSSConstants.VALIDATION_ERROR_FONT_FAMILY.equalsIgnoreCase(property)) {
            IStyle style = natTable.getConfigRegistry().getConfigAttribute(EditConfigAttributes.VALIDATION_ERROR_STYLE, displayMode, label);
            Font font = style.getAttributeValue(CellStyleAttributes.FONT);
            return CSSSWTFontHelper.getFontFamily(font);
        } else if (NatTableCSSConstants.VALIDATION_ERROR_FONT_SIZE.equalsIgnoreCase(property)) {
            IStyle style = natTable.getConfigRegistry().getConfigAttribute(EditConfigAttributes.VALIDATION_ERROR_STYLE, displayMode, label);
            Font font = style.getAttributeValue(CellStyleAttributes.FONT);
            return CSSSWTFontHelper.getFontSize(font);
        } else if (NatTableCSSConstants.VALIDATION_ERROR_FONT_STYLE.equalsIgnoreCase(property)) {
            IStyle style = natTable.getConfigRegistry().getConfigAttribute(EditConfigAttributes.VALIDATION_ERROR_STYLE, displayMode, label);
            Font font = style.getAttributeValue(CellStyleAttributes.FONT);
            return CSSSWTFontHelper.getFontStyle(font);
        } else if (NatTableCSSConstants.VALIDATION_ERROR_FONT_WEIGHT.equalsIgnoreCase(property)) {
            IStyle style = natTable.getConfigRegistry().getConfigAttribute(EditConfigAttributes.VALIDATION_ERROR_STYLE, displayMode, label);
            Font font = style.getAttributeValue(CellStyleAttributes.FONT);
            return CSSSWTFontHelper.getFontWeight(font);
        } else if (NatTableCSSConstants.VALIDATION_ERROR_BACKGROUND_COLOR.equalsIgnoreCase(property)) {
            ICSSValueConverter cssValueConverter = engine.getCSSValueConverter(String.class);
            IStyle style = natTable.getConfigRegistry().getConfigAttribute(EditConfigAttributes.VALIDATION_ERROR_STYLE, displayMode, label);
            return cssValueConverter.convert(style.getAttributeValue(CellStyleAttributes.BACKGROUND_COLOR), engine, null);
        } else if (NatTableCSSConstants.VALIDATION_ERROR_FOREGROUND_COLOR.equalsIgnoreCase(property)) {
            ICSSValueConverter cssValueConverter = engine.getCSSValueConverter(String.class);
            IStyle style = natTable.getConfigRegistry().getConfigAttribute(EditConfigAttributes.VALIDATION_ERROR_STYLE, displayMode, label);
            return cssValueConverter.convert(style.getAttributeValue(CellStyleAttributes.FOREGROUND_COLOR), engine, null);
        } else if (NatTableCSSConstants.WORD_WRAP.equalsIgnoreCase(property)) {
            Boolean wrap = Boolean.FALSE;
            ICellPainter painter = natTable.getConfigRegistry().getConfigAttribute(CellConfigAttributes.CELL_PAINTER, displayMode, label);
            if (painter != null) {
                while (painter instanceof CellPainterWrapper) {
                    painter = ((CellPainterWrapper) painter).getWrappedPainter();
                }
            }
            if (painter instanceof AbstractTextPainter) {
                wrap = ((AbstractTextPainter) painter).isWordWrapping();
            }
            return wrap.toString();
        } else if (NatTableCSSConstants.TEXT_WRAP.equalsIgnoreCase(property)) {
            Boolean wrap = Boolean.FALSE;
            ICellPainter painter = natTable.getConfigRegistry().getConfigAttribute(CellConfigAttributes.CELL_PAINTER, displayMode, label);
            if (painter != null) {
                while (painter instanceof CellPainterWrapper) {
                    painter = ((CellPainterWrapper) painter).getWrappedPainter();
                }
            }
            if (painter instanceof AbstractTextPainter) {
                wrap = ((AbstractTextPainter) painter).isWrapText();
            }
            return wrap.toString();
        } else if (NatTableCSSConstants.TEXT_TRIM.equalsIgnoreCase(property)) {
            Boolean trim = Boolean.FALSE;
            ICellPainter painter = natTable.getConfigRegistry().getConfigAttribute(CellConfigAttributes.CELL_PAINTER, displayMode, label);
            if (painter != null) {
                while (painter instanceof CellPainterWrapper) {
                    painter = ((CellPainterWrapper) painter).getWrappedPainter();
                }
            }
            if (painter instanceof AbstractTextPainter) {
                trim = ((AbstractTextPainter) painter).isTrimText();
            }
            return trim.toString();
        } else if (NatTableCSSConstants.LINE_SPACING.equalsIgnoreCase(property)) {
            int spacing = 0;
            ICellPainter painter = natTable.getConfigRegistry().getConfigAttribute(CellConfigAttributes.CELL_PAINTER, displayMode, label);
            if (painter != null) {
                while (painter instanceof CellPainterWrapper) {
                    painter = ((CellPainterWrapper) painter).getWrappedPainter();
                }
            }
            if (painter instanceof AbstractTextPainter) {
                spacing = ((AbstractTextPainter) painter).getLineSpacing();
            }
            return "" + spacing;
        } else if (NatTableCSSConstants.TEXT_DIRECTION.equalsIgnoreCase(property)) {
            String direction = "horizontal";
            ICellPainter painter = natTable.getConfigRegistry().getConfigAttribute(CellConfigAttributes.CELL_PAINTER, displayMode, label);
            if (painter != null) {
                while (painter instanceof CellPainterWrapper) {
                    painter = ((CellPainterWrapper) painter).getWrappedPainter();
                }
            }
            if (painter instanceof VerticalTextPainter) {
                direction = "vertical";
            }
            return direction;
        } else if (NatTableCSSConstants.COLUMN_WIDTH.equalsIgnoreCase(property)) {
            // inherit is not supported here
            return "default";
        } else if (NatTableCSSConstants.ROW_HEIGHT.equalsIgnoreCase(property)) {
            // inherit is not supported here
            return "default";
        } else if (NatTableCSSConstants.PADDING.equalsIgnoreCase(property)) {
            ICellPainter painter = natTable.getConfigRegistry().getConfigAttribute(CellConfigAttributes.CELL_PAINTER, displayMode, label);
            if (painter != null) {
                while (painter instanceof CellPainterWrapper) {
                    painter = ((CellPainterWrapper) painter).getWrappedPainter();
                    if (painter instanceof PaddingDecorator) {
                        PaddingDecorator decorator = (PaddingDecorator) painter;
                        return new StringBuilder().append(decorator.getTopPadding()).append(" ").append(decorator.getRightPadding()).append(" ").append(decorator.getBottomPadding()).append(" ").append(decorator.getLeftPadding()).toString();
                    }
                }
            }
        } else if (NatTableCSSConstants.PADDING_TOP.equalsIgnoreCase(property)) {
            ICellPainter painter = natTable.getConfigRegistry().getConfigAttribute(CellConfigAttributes.CELL_PAINTER, displayMode, label);
            if (painter != null) {
                while (painter instanceof CellPainterWrapper) {
                    painter = ((CellPainterWrapper) painter).getWrappedPainter();
                    if (painter instanceof PaddingDecorator) {
                        return "" + ((PaddingDecorator) painter).getTopPadding();
                    }
                }
            }
            return "0";
        } else if (NatTableCSSConstants.PADDING_RIGHT.equalsIgnoreCase(property)) {
            ICellPainter painter = natTable.getConfigRegistry().getConfigAttribute(CellConfigAttributes.CELL_PAINTER, displayMode, label);
            if (painter != null) {
                while (painter instanceof CellPainterWrapper) {
                    painter = ((CellPainterWrapper) painter).getWrappedPainter();
                    if (painter instanceof PaddingDecorator) {
                        return "" + ((PaddingDecorator) painter).getRightPadding();
                    }
                }
            }
            return "0";
        } else if (NatTableCSSConstants.PADDING_BOTTOM.equalsIgnoreCase(property)) {
            ICellPainter painter = natTable.getConfigRegistry().getConfigAttribute(CellConfigAttributes.CELL_PAINTER, displayMode, label);
            if (painter != null) {
                while (painter instanceof CellPainterWrapper) {
                    painter = ((CellPainterWrapper) painter).getWrappedPainter();
                    if (painter instanceof PaddingDecorator) {
                        return "" + ((PaddingDecorator) painter).getBottomPadding();
                    }
                }
            }
            return "0";
        } else if (NatTableCSSConstants.PADDING_LEFT.equalsIgnoreCase(property)) {
            ICellPainter painter = natTable.getConfigRegistry().getConfigAttribute(CellConfigAttributes.CELL_PAINTER, displayMode, label);
            if (painter != null) {
                while (painter instanceof CellPainterWrapper) {
                    painter = ((CellPainterWrapper) painter).getWrappedPainter();
                    if (painter instanceof PaddingDecorator) {
                        return "" + ((PaddingDecorator) painter).getLeftPadding();
                    }
                }
            }
            return "0";
        } else if (NatTableCSSConstants.TABLE_BORDER_COLOR.equalsIgnoreCase(property)) {
            for (Iterator<IOverlayPainter> it = natTable.getOverlayPainters().iterator(); it.hasNext(); ) {
                IOverlayPainter painter = it.next();
                if (painter instanceof NatTableBorderOverlayPainter) {
                    return engine.getCSSValueConverter(String.class).convert(((NatTableBorderOverlayPainter) painter).getBorderColor(), engine, null);
                }
            }
        } else if (NatTableCSSConstants.FILL_HANDLE_BORDER.equalsIgnoreCase(property)) {
            BorderStyle border = NatTableCSSHelper.getNatTableStyle(natTable, FillHandleConfigAttributes.FILL_HANDLE_BORDER_STYLE, displayMode, label);
            ICSSValueConverter cssValueConverter = engine.getCSSValueConverter(String.class);
            return border.getThickness() + " " + border.getLineStyle().toString().toLowerCase() + " " + border.getBorderMode().toString().toLowerCase() + " " + cssValueConverter.convert(border.getColor(), engine, null);
        } else if (NatTableCSSConstants.FILL_HANDLE_COLOR.equalsIgnoreCase(property)) {
            ICSSValueConverter cssValueConverter = engine.getCSSValueConverter(String.class);
            return cssValueConverter.convert(natTable.getConfigRegistry().getConfigAttribute(FillHandleConfigAttributes.FILL_HANDLE_COLOR, displayMode, label), engine, null);
        } else if (NatTableCSSConstants.FILL_REGION_BORDER.equalsIgnoreCase(property)) {
            BorderStyle border = NatTableCSSHelper.getNatTableStyle(natTable, FillHandleConfigAttributes.FILL_HANDLE_REGION_BORDER_STYLE, displayMode, label);
            ICSSValueConverter cssValueConverter = engine.getCSSValueConverter(String.class);
            return border.getThickness() + " " + border.getLineStyle().toString().toLowerCase() + " " + border.getBorderMode().toString().toLowerCase() + " " + cssValueConverter.convert(border.getColor(), engine, null);
        } else if (NatTableCSSConstants.INVERT_ICONS.equalsIgnoreCase(property)) {
            // not able to determine it easily here
            return Boolean.FALSE.toString();
        } else if (NatTableCSSConstants.DECORATION.equalsIgnoreCase(property)) {
            // TODO : manage path of Image.
            return "none";
        } else if (NatTableCSSConstants.PERCENTAGE_DECORATOR_COLORS.equalsIgnoreCase(property)) {
            IStyle style = natTable.getConfigRegistry().getConfigAttribute(CellConfigAttributes.CELL_STYLE, displayMode, label);
            Color c1 = style.getAttributeValue(PercentageBarDecorator.PERCENTAGE_BAR_COMPLETE_REGION_START_COLOR);
            Color c2 = style.getAttributeValue(PercentageBarDecorator.PERCENTAGE_BAR_COMPLETE_REGION_END_COLOR);
            Color c3 = style.getAttributeValue(PercentageBarDecorator.PERCENTAGE_BAR_INCOMPLETE_REGION_COLOR);
            ICSSValueConverter cssValueConverter = engine.getCSSValueConverter(String.class);
            return cssValueConverter.convert(c1, engine, null) + " " + cssValueConverter.convert(c2, engine, null) + " " + cssValueConverter.convert(c3, engine, null);
        } else if (NatTableCSSConstants.CONVERTER.equalsIgnoreCase(property)) {
            IDisplayConverter converter = natTable.getConfigRegistry().getConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, displayMode, label);
            return NatTableCSSHelper.getDisplayConverterString(converter);
        }
    }
    return null;
}
Also used : IOverlayPainter(org.eclipse.nebula.widgets.nattable.painter.IOverlayPainter) BorderStyle(org.eclipse.nebula.widgets.nattable.style.BorderStyle) TextDecorationEnum(org.eclipse.nebula.widgets.nattable.style.TextDecorationEnum) ICSSValueConverter(org.eclipse.e4.ui.css.core.dom.properties.converters.ICSSValueConverter) Color(org.eclipse.swt.graphics.Color) CellPainterWrapper(org.eclipse.nebula.widgets.nattable.painter.cell.CellPainterWrapper) PaddingDecorator(org.eclipse.nebula.widgets.nattable.painter.cell.decorator.PaddingDecorator) VerticalAlignmentEnum(org.eclipse.nebula.widgets.nattable.style.VerticalAlignmentEnum) IDisplayConverter(org.eclipse.nebula.widgets.nattable.data.convert.IDisplayConverter) Font(org.eclipse.swt.graphics.Font) ICellPainter(org.eclipse.nebula.widgets.nattable.painter.cell.ICellPainter) HorizontalAlignmentEnum(org.eclipse.nebula.widgets.nattable.style.HorizontalAlignmentEnum) IStyle(org.eclipse.nebula.widgets.nattable.style.IStyle) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) NatTableBorderOverlayPainter(org.eclipse.nebula.widgets.nattable.painter.NatTableBorderOverlayPainter) AbstractTextPainter(org.eclipse.nebula.widgets.nattable.painter.cell.AbstractTextPainter) VerticalTextPainter(org.eclipse.nebula.widgets.nattable.painter.cell.VerticalTextPainter)

Example 3 with CellPainterWrapper

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

the class CellPainterFactory method getDecoratorPainter.

/**
 * Create the decorator painter for the given key and properties.
 *
 * @param key
 *            The decorator painter key.
 * @param painterProperties
 *            The painter properties for painter initialization.
 * @param underlying
 *            the {@link ICellPainter} that should be applied as wrapped
 *            painter to the created decorator.
 * @return The decorator painter to use
 */
public CellPainterWrapper getDecoratorPainter(String key, Map<String, Object> painterProperties, ICellPainter underlying) {
    CellPainterWrapper result = null;
    String lowerKey = key.toLowerCase();
    CellPainterWrapperCreator creator = this.decoratorPainter.get(lowerKey);
    if (creator != null) {
        result = creator.createCellPainterWrapper(painterProperties, underlying);
    }
    if (result == null) {
        // a background painter can also be a decorator
        result = getBackgroundPainter(key, painterProperties, underlying);
    }
    return result;
}
Also used : CellPainterWrapper(org.eclipse.nebula.widgets.nattable.painter.cell.CellPainterWrapper)

Example 4 with CellPainterWrapper

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

the class CellPainterFactory method getBackgroundPainter.

/**
 * Create the background painter for the given key and properties.
 *
 * @param key
 *            The background painter key.
 * @param painterProperties
 *            The painter properties for painter initialization.
 * @param underlying
 *            The {@link ICellPainter} that should be applied as wrapped
 *            painter to the created decorator.
 * @return The background painter to use
 */
public CellPainterWrapper getBackgroundPainter(String key, Map<String, Object> painterProperties, ICellPainter underlying) {
    CellPainterWrapper result = null;
    String lowerKey = key.toLowerCase();
    CellPainterWrapperCreator creator = this.backgroundPainter.get(lowerKey);
    if (creator != null) {
        result = creator.createCellPainterWrapper(painterProperties, underlying);
    }
    return result;
}
Also used : CellPainterWrapper(org.eclipse.nebula.widgets.nattable.painter.cell.CellPainterWrapper)

Aggregations

CellPainterWrapper (org.eclipse.nebula.widgets.nattable.painter.cell.CellPainterWrapper)4 ICellPainter (org.eclipse.nebula.widgets.nattable.painter.cell.ICellPainter)2 ICSSValueConverter (org.eclipse.e4.ui.css.core.dom.properties.converters.ICSSValueConverter)1 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)1 IDisplayConverter (org.eclipse.nebula.widgets.nattable.data.convert.IDisplayConverter)1 ColumnGroupExpandCollapseImagePainter (org.eclipse.nebula.widgets.nattable.group.painter.ColumnGroupExpandCollapseImagePainter)1 RowGroupExpandCollapseImagePainter (org.eclipse.nebula.widgets.nattable.group.painter.RowGroupExpandCollapseImagePainter)1 IOverlayPainter (org.eclipse.nebula.widgets.nattable.painter.IOverlayPainter)1 NatTableBorderOverlayPainter (org.eclipse.nebula.widgets.nattable.painter.NatTableBorderOverlayPainter)1 AbstractTextPainter (org.eclipse.nebula.widgets.nattable.painter.cell.AbstractTextPainter)1 BackgroundImagePainter (org.eclipse.nebula.widgets.nattable.painter.cell.BackgroundImagePainter)1 ImagePainter (org.eclipse.nebula.widgets.nattable.painter.cell.ImagePainter)1 VerticalTextPainter (org.eclipse.nebula.widgets.nattable.painter.cell.VerticalTextPainter)1 CellPainterDecorator (org.eclipse.nebula.widgets.nattable.painter.cell.decorator.CellPainterDecorator)1 PaddingDecorator (org.eclipse.nebula.widgets.nattable.painter.cell.decorator.PaddingDecorator)1 BorderStyle (org.eclipse.nebula.widgets.nattable.style.BorderStyle)1 HorizontalAlignmentEnum (org.eclipse.nebula.widgets.nattable.style.HorizontalAlignmentEnum)1 IStyle (org.eclipse.nebula.widgets.nattable.style.IStyle)1 TextDecorationEnum (org.eclipse.nebula.widgets.nattable.style.TextDecorationEnum)1 VerticalAlignmentEnum (org.eclipse.nebula.widgets.nattable.style.VerticalAlignmentEnum)1