Search in sources :

Example 6 with NatTableBorderOverlayPainter

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

the class NatTableCSSHandler method applyCSSProperty.

@Override
public boolean applyCSSProperty(Object element, String property, CSSValue value, String pseudo, CSSEngine engine) throws Exception {
    Object control = null;
    if (element instanceof CSSStylableElement) {
        CSSStylableElement elt = (CSSStylableElement) element;
        control = elt.getNativeWidget();
    }
    NatTable natTable = null;
    String label = null;
    String displayMode = NatTableCSSHelper.getDisplayMode(pseudo);
    CSSElementContext context = null;
    CSSElementContext natTableContext = null;
    if (control instanceof NatTable) {
        natTable = (NatTable) control;
    } else if (control instanceof NatTableWrapper) {
        natTable = ((NatTableWrapper) control).getNatTable();
        label = ((NatTableWrapper) control).getLabel();
        natTableContext = engine.getCSSElementContext(natTable);
    }
    if (natTable != null) {
        context = engine.getCSSElementContext(control);
        Boolean resolvePainter = NatTableCSSHelper.resolvePainter(context, natTableContext, displayMode);
        // check property
        if (NatTableCSSConstants.PAINTER_RESOLUTION.equalsIgnoreCase(property)) {
            NatTableCSSHelper.storeContextValue(context, displayMode, NatTableCSSConstants.PAINTER_RESOLUTION, NatTableCSSHelper.getBoolean(value, true));
        } else if (NatTableCSSConstants.PAINTER.equalsIgnoreCase(property)) {
            NatTableCSSHelper.storeContextValue(context, displayMode, NatTableCSSConstants.PAINTER, NatTableCSSHelper.resolvePainterRepresentation(value));
        } else if (NatTableCSSConstants.BACKGROUND_COLOR.equalsIgnoreCase(property)) {
            CSSPropertyBackgroundSWTHandler.INSTANCE.applyCSSPropertyBackgroundColor(element, value, pseudo, engine);
        } else if (NatTableCSSConstants.BACKGROUND_IMAGE.equalsIgnoreCase(property)) {
            CSSPropertyBackgroundSWTHandler.INSTANCE.applyCSSPropertyBackgroundImage(element, value, pseudo, engine);
        } else if (NatTableCSSConstants.CELL_BACKGROUND_COLOR.equalsIgnoreCase(property)) {
            if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
                Color newColor = (Color) engine.convert(value, Color.class, natTable.getDisplay());
                NatTableCSSHelper.applyNatTableStyle(natTable, CellStyleAttributes.BACKGROUND_COLOR, newColor, displayMode, label);
                if (resolvePainter) {
                    NatTableCSSHelper.storeContextValue(context, displayMode, NatTableCSSConstants.CV_BACKGROUND_PAINTER, CellPainterFactory.BACKGROUND_PAINTER_KEY);
                }
            } else if (value.getCssValueType() == CSSValue.CSS_VALUE_LIST) {
                Gradient grad = (Gradient) CSSValueSWTGradientConverterImpl.INSTANCE.convert(value, engine, natTable.getDisplay());
                if (grad != null) {
                    List<?> values = grad.getValues();
                    if (values.size() == 2) {
                        Color background = (Color) engine.convert((CSSPrimitiveValue) values.get(0), Color.class, natTable.getDisplay());
                        NatTableCSSHelper.applyNatTableStyle(natTable, CellStyleAttributes.GRADIENT_BACKGROUND_COLOR, background, displayMode, label);
                        Color foreground = (Color) engine.convert((CSSPrimitiveValue) values.get(1), Color.class, natTable.getDisplay());
                        NatTableCSSHelper.applyNatTableStyle(natTable, CellStyleAttributes.GRADIENT_FOREGROUND_COLOR, foreground, displayMode, label);
                        NatTableCSSHelper.getPainterProperties(context, displayMode).put(NatTableCSSConstants.GRADIENT_BACKGROUND_VERTICAL, grad.getVerticalGradient());
                        if (resolvePainter) {
                            NatTableCSSHelper.storeContextValue(context, displayMode, NatTableCSSConstants.CV_BACKGROUND_PAINTER, CellPainterFactory.GRADIENT_BACKGROUND_PAINTER_KEY);
                        }
                    }
                }
            }
        } else if (NatTableCSSConstants.CELL_BACKGROUND_IMAGE.equalsIgnoreCase(property)) {
            Image image = (Image) engine.convert(value, Image.class, natTable.getDisplay());
            if (image != null) {
                NatTableCSSHelper.getPainterProperties(context, displayMode).put(NatTableCSSConstants.CELL_BACKGROUND_IMAGE, image);
                if (resolvePainter) {
                    NatTableCSSHelper.storeContextValue(context, displayMode, NatTableCSSConstants.CV_BACKGROUND_PAINTER, CellPainterFactory.BACKGROUND_IMAGE_PAINTER_KEY);
                }
            }
        } else if (NatTableCSSConstants.FOREGROUND_COLOR.equalsIgnoreCase(property) && (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE)) {
            Color newColor = (Color) engine.convert(value, Color.class, natTable.getDisplay());
            NatTableCSSHelper.applyNatTableStyle(natTable, CellStyleAttributes.FOREGROUND_COLOR, newColor, displayMode, label);
        } else if (NatTableCSSConstants.HORIZONTAL_ALIGNMENT.equalsIgnoreCase(property) && (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE)) {
            String stringValue = value.getCssText().toLowerCase();
            HorizontalAlignmentEnum align = HorizontalAlignmentEnum.CENTER;
            if ("left".equals(stringValue) || "lead".equals(stringValue)) {
                align = HorizontalAlignmentEnum.LEFT;
            } else if ("right".equals(stringValue) || "trail".equals(stringValue)) {
                align = HorizontalAlignmentEnum.RIGHT;
            } else if ("center".equals(stringValue)) {
                align = HorizontalAlignmentEnum.CENTER;
            }
            NatTableCSSHelper.applyNatTableStyle(natTable, CellStyleAttributes.HORIZONTAL_ALIGNMENT, align, displayMode, label);
        } else if (NatTableCSSConstants.VERTICAL_ALIGNMENT.equalsIgnoreCase(property) && (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE)) {
            String stringValue = value.getCssText().toLowerCase();
            VerticalAlignmentEnum align = VerticalAlignmentEnum.MIDDLE;
            if ("top".equals(stringValue) || "up".equals(stringValue)) {
                align = VerticalAlignmentEnum.TOP;
            } else if ("bottom".equals(stringValue) || "down".equals(stringValue)) {
                align = VerticalAlignmentEnum.BOTTOM;
            } else if ("middle".equals(stringValue)) {
                align = VerticalAlignmentEnum.MIDDLE;
            }
            NatTableCSSHelper.applyNatTableStyle(natTable, CellStyleAttributes.VERTICAL_ALIGNMENT, align, displayMode, label);
        } else if (NatTableCSSConstants.FONT.equalsIgnoreCase(property) && (value.getCssValueType() == CSSValue.CSS_VALUE_LIST)) {
            NatTableCSSHelper.setFontProperties((CSSValueList) value, NatTableCSSHelper.getFontProperties(context, CSS2FontPropertiesHelpers.CSS2FONT_KEY, natTable, displayMode, label));
        } else if (NatTableCSSConstants.FONT_FAMILY.equalsIgnoreCase(property) && (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE)) {
            CSS2FontProperties font = NatTableCSSHelper.getFontProperties(context, CSS2FontPropertiesHelpers.CSS2FONT_KEY, natTable, displayMode, label);
            font.setFamily((CSSPrimitiveValue) value);
        } else if (NatTableCSSConstants.FONT_SIZE.equalsIgnoreCase(property) && (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE)) {
            CSS2FontProperties font = NatTableCSSHelper.getFontProperties(context, CSS2FontPropertiesHelpers.CSS2FONT_KEY, natTable, displayMode, label);
            font.setSize((CSSPrimitiveValue) value);
        } else if (NatTableCSSConstants.FONT_STYLE.equalsIgnoreCase(property) && (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE)) {
            CSS2FontProperties font = NatTableCSSHelper.getFontProperties(context, CSS2FontPropertiesHelpers.CSS2FONT_KEY, natTable, displayMode, label);
            font.setStyle((CSSPrimitiveValue) value);
        } else if (NatTableCSSConstants.FONT_WEIGHT.equalsIgnoreCase(property) && (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE)) {
            CSS2FontProperties font = NatTableCSSHelper.getFontProperties(context, CSS2FontPropertiesHelpers.CSS2FONT_KEY, natTable, displayMode, label);
            font.setWeight((CSSPrimitiveValue) value);
        } else if (NatTableCSSConstants.IMAGE.equalsIgnoreCase(property)) {
            Image image = (Image) engine.convert(value, Image.class, natTable.getDisplay());
            NatTableCSSHelper.applyNatTableStyle(natTable, CellStyleAttributes.IMAGE, image, displayMode, label);
            if (resolvePainter) {
                NatTableCSSHelper.storeContextValue(context, displayMode, NatTableCSSConstants.CV_CONTENT_PAINTER, CellPainterFactory.IMAGE_PAINTER_KEY);
            }
        } else if (NatTableCSSConstants.BORDER.equalsIgnoreCase(property) && (value.getCssValueType() == CSSValue.CSS_VALUE_LIST)) {
            CSSValueList valueList = (CSSValueList) value;
            BorderStyle borderStyle = NatTableCSSHelper.getBorderStyle(context, displayMode);
            NatTableCSSHelper.storeBorderStyle(valueList, borderStyle, engine, natTable.getDisplay());
        } else if (NatTableCSSConstants.BORDER_COLOR.equalsIgnoreCase(property) && (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE)) {
            BorderStyle borderStyle = NatTableCSSHelper.getBorderStyle(context, displayMode);
            borderStyle.setColor((Color) engine.convert(value, Color.class, natTable.getDisplay()));
        } else if (NatTableCSSConstants.BORDER_STYLE.equalsIgnoreCase(property) && (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE)) {
            BorderStyle borderStyle = NatTableCSSHelper.getBorderStyle(context, displayMode);
            CSSPrimitiveValue primitiveValue = (CSSPrimitiveValue) value;
            borderStyle.setLineStyle(LineStyleEnum.valueOf(primitiveValue.getStringValue().toUpperCase()));
        } else if (NatTableCSSConstants.BORDER_WIDTH.equalsIgnoreCase(property) && (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE)) {
            BorderStyle borderStyle = NatTableCSSHelper.getBorderStyle(context, displayMode);
            borderStyle.setThickness((int) ((CSSPrimitiveValue) value).getFloatValue(CSSPrimitiveValue.CSS_PT));
        } else if (NatTableCSSConstants.BORDER_MODE.equalsIgnoreCase(property) && (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE)) {
            BorderStyle borderStyle = NatTableCSSHelper.getBorderStyle(context, displayMode);
            CSSPrimitiveValue primitiveValue = (CSSPrimitiveValue) value;
            borderStyle.setBorderMode(BorderModeEnum.valueOf(primitiveValue.getStringValue().toUpperCase()));
        } else if (NatTableCSSConstants.PASSWORD_ECHO_CHAR.equalsIgnoreCase(property) && (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE)) {
            String stringValue = value.getCssText();
            NatTableCSSHelper.applyNatTableStyle(natTable, CellStyleAttributes.PASSWORD_ECHO_CHAR, stringValue.charAt(0), displayMode, label);
        } else if (NatTableCSSConstants.TEXT_DECORATION.equalsIgnoreCase(property)) {
            if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
                String stringValue = value.getCssText();
                if ("none".equals(stringValue)) {
                    NatTableCSSHelper.applyNatTableStyle(natTable, CellStyleAttributes.TEXT_DECORATION, null, displayMode, label);
                } else if ("underline".equals(stringValue)) {
                    NatTableCSSHelper.applyNatTableStyle(natTable, CellStyleAttributes.TEXT_DECORATION, TextDecorationEnum.UNDERLINE, displayMode, label);
                } else if ("line-through".equals(stringValue)) {
                    NatTableCSSHelper.applyNatTableStyle(natTable, CellStyleAttributes.TEXT_DECORATION, TextDecorationEnum.STRIKETHROUGH, displayMode, label);
                }
            } else if (value.getCssValueType() == CSSValue.CSS_VALUE_LIST) {
                CSSValueList valueList = (CSSValueList) value;
                int length = valueList.getLength();
                boolean strikethrough = false;
                boolean underline = false;
                for (int i = 0; i < length; i++) {
                    CSSValue value2 = valueList.item(i);
                    if (value2.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
                        String stringValue = value2.getCssText();
                        if ("none".equals(stringValue)) {
                            strikethrough = false;
                            underline = false;
                            break;
                        } else if ("underline".equals(stringValue)) {
                            underline = true;
                        } else if ("line-through".equals(stringValue)) {
                            strikethrough = true;
                        }
                    }
                }
                if (!strikethrough && !underline) {
                    NatTableCSSHelper.applyNatTableStyle(natTable, CellStyleAttributes.TEXT_DECORATION, null, displayMode, label);
                } else if (!strikethrough && underline) {
                    NatTableCSSHelper.applyNatTableStyle(natTable, CellStyleAttributes.TEXT_DECORATION, TextDecorationEnum.UNDERLINE, displayMode, label);
                } else if (strikethrough && !underline) {
                    NatTableCSSHelper.applyNatTableStyle(natTable, CellStyleAttributes.TEXT_DECORATION, TextDecorationEnum.STRIKETHROUGH, displayMode, label);
                } else if (strikethrough && underline) {
                    NatTableCSSHelper.applyNatTableStyle(natTable, CellStyleAttributes.TEXT_DECORATION, TextDecorationEnum.UNDERLINE_STRIKETHROUGH, displayMode, label);
                }
            }
        } else if (NatTableCSSConstants.FREEZE_SEPARATOR_COLOR.equalsIgnoreCase(property) && (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE)) {
            natTable.getConfigRegistry().registerConfigAttribute(IFreezeConfigAttributes.SEPARATOR_COLOR, (Color) engine.convert(value, Color.class, natTable.getDisplay()), displayMode, label);
        } else if (NatTableCSSConstants.GRID_LINE_COLOR.equalsIgnoreCase(property) && (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE)) {
            natTable.getConfigRegistry().registerConfigAttribute(CellConfigAttributes.GRID_LINE_COLOR, (Color) engine.convert(value, Color.class, natTable.getDisplay()), displayMode, label);
        } else if (NatTableCSSConstants.GRID_LINE_WIDTH.equalsIgnoreCase(property) && (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE)) {
            natTable.getConfigRegistry().registerConfigAttribute(CellConfigAttributes.GRID_LINE_WIDTH, (int) ((CSSPrimitiveValue) value).getFloatValue(CSSPrimitiveValue.CSS_PT), displayMode, label);
        } else if (NatTableCSSConstants.RENDER_GRID_LINES.equalsIgnoreCase(property) && (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE)) {
            natTable.getConfigRegistry().registerConfigAttribute(CellConfigAttributes.RENDER_GRID_LINES, NatTableCSSHelper.getBoolean(value, true), displayMode, label);
        } else if (NatTableCSSConstants.CONVERSION_ERROR_FONT.equalsIgnoreCase(property) && (value.getCssValueType() == CSSValue.CSS_VALUE_LIST)) {
            NatTableCSSHelper.setFontProperties((CSSValueList) value, NatTableCSSHelper.getFontProperties(context, NatTableCSSConstants.CV_CONVERSION_ERROR_FONT_PROPERTIES, natTable, displayMode, label));
        } else if (NatTableCSSConstants.CONVERSION_ERROR_FONT_FAMILY.equalsIgnoreCase(property) && (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE)) {
            CSS2FontProperties font = NatTableCSSHelper.getFontProperties(context, NatTableCSSConstants.CV_CONVERSION_ERROR_FONT_PROPERTIES, natTable, displayMode, label);
            font.setFamily((CSSPrimitiveValue) value);
        } else if (NatTableCSSConstants.CONVERSION_ERROR_FONT_SIZE.equalsIgnoreCase(property) && (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE)) {
            CSS2FontProperties font = NatTableCSSHelper.getFontProperties(context, NatTableCSSConstants.CV_CONVERSION_ERROR_FONT_PROPERTIES, natTable, displayMode, label);
            font.setSize((CSSPrimitiveValue) value);
        } else if (NatTableCSSConstants.CONVERSION_ERROR_FONT_STYLE.equalsIgnoreCase(property) && (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE)) {
            CSS2FontProperties font = NatTableCSSHelper.getFontProperties(context, NatTableCSSConstants.CV_CONVERSION_ERROR_FONT_PROPERTIES, natTable, displayMode, label);
            font.setStyle((CSSPrimitiveValue) value);
        } else if (NatTableCSSConstants.CONVERSION_ERROR_FONT_WEIGHT.equalsIgnoreCase(property) && (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE)) {
            CSS2FontProperties font = NatTableCSSHelper.getFontProperties(context, NatTableCSSConstants.CV_CONVERSION_ERROR_FONT_PROPERTIES, natTable, displayMode, label);
            font.setWeight((CSSPrimitiveValue) value);
        } else if (NatTableCSSConstants.CONVERSION_ERROR_BACKGROUND_COLOR.equalsIgnoreCase(property) && (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE)) {
            Color newColor = (Color) engine.convert(value, Color.class, natTable.getDisplay());
            NatTableCSSHelper.applyNatTableStyle(natTable, EditConfigAttributes.CONVERSION_ERROR_STYLE, CellStyleAttributes.BACKGROUND_COLOR, newColor, displayMode, label);
        } else if (NatTableCSSConstants.CONVERSION_ERROR_FOREGROUND_COLOR.equalsIgnoreCase(property) && (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE)) {
            Color newColor = (Color) engine.convert(value, Color.class, natTable.getDisplay());
            NatTableCSSHelper.applyNatTableStyle(natTable, EditConfigAttributes.CONVERSION_ERROR_STYLE, CellStyleAttributes.FOREGROUND_COLOR, newColor, displayMode, label);
        } else if (NatTableCSSConstants.VALIDATION_ERROR_FONT.equalsIgnoreCase(property) && (value.getCssValueType() == CSSValue.CSS_VALUE_LIST)) {
            NatTableCSSHelper.setFontProperties((CSSValueList) value, NatTableCSSHelper.getFontProperties(context, NatTableCSSConstants.CV_VALIDATION_ERROR_FONT_PROPERTIES, natTable, displayMode, label));
        } else if (NatTableCSSConstants.VALIDATION_ERROR_FONT_FAMILY.equalsIgnoreCase(property) && (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE)) {
            CSS2FontProperties font = NatTableCSSHelper.getFontProperties(context, NatTableCSSConstants.CV_VALIDATION_ERROR_FONT_PROPERTIES, natTable, displayMode, label);
            font.setFamily((CSSPrimitiveValue) value);
        } else if (NatTableCSSConstants.VALIDATION_ERROR_FONT_SIZE.equalsIgnoreCase(property) && (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE)) {
            CSS2FontProperties font = NatTableCSSHelper.getFontProperties(context, NatTableCSSConstants.CV_VALIDATION_ERROR_FONT_PROPERTIES, natTable, displayMode, label);
            font.setSize((CSSPrimitiveValue) value);
        } else if (NatTableCSSConstants.VALIDATION_ERROR_FONT_STYLE.equalsIgnoreCase(property) && (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE)) {
            CSS2FontProperties font = NatTableCSSHelper.getFontProperties(context, NatTableCSSConstants.CV_VALIDATION_ERROR_FONT_PROPERTIES, natTable, displayMode, label);
            font.setStyle((CSSPrimitiveValue) value);
        } else if (NatTableCSSConstants.VALIDATION_ERROR_FONT_WEIGHT.equalsIgnoreCase(property) && (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE)) {
            CSS2FontProperties font = NatTableCSSHelper.getFontProperties(context, NatTableCSSConstants.CV_VALIDATION_ERROR_FONT_PROPERTIES, natTable, displayMode, label);
            font.setWeight((CSSPrimitiveValue) value);
        } else if (NatTableCSSConstants.VALIDATION_ERROR_BACKGROUND_COLOR.equalsIgnoreCase(property) && (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE)) {
            Color newColor = (Color) engine.convert(value, Color.class, natTable.getDisplay());
            NatTableCSSHelper.applyNatTableStyle(natTable, EditConfigAttributes.VALIDATION_ERROR_STYLE, CellStyleAttributes.BACKGROUND_COLOR, newColor, displayMode, label);
        } else if (NatTableCSSConstants.VALIDATION_ERROR_FOREGROUND_COLOR.equalsIgnoreCase(property) && (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE)) {
            Color newColor = (Color) engine.convert(value, Color.class, natTable.getDisplay());
            NatTableCSSHelper.applyNatTableStyle(natTable, EditConfigAttributes.VALIDATION_ERROR_STYLE, CellStyleAttributes.FOREGROUND_COLOR, newColor, displayMode, label);
        } else if (NatTableCSSConstants.WORD_WRAP.equalsIgnoreCase(property) && (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE)) {
            NatTableCSSHelper.getPainterProperties(context, displayMode).put(NatTableCSSConstants.WORD_WRAP, NatTableCSSHelper.getBoolean(value, false));
        } else if (NatTableCSSConstants.TEXT_WRAP.equalsIgnoreCase(property) && (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE)) {
            NatTableCSSHelper.getPainterProperties(context, displayMode).put(NatTableCSSConstants.TEXT_WRAP, NatTableCSSHelper.getBoolean(value, false));
        } else if (NatTableCSSConstants.TEXT_TRIM.equalsIgnoreCase(property) && (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE)) {
            NatTableCSSHelper.getPainterProperties(context, displayMode).put(NatTableCSSConstants.TEXT_TRIM, NatTableCSSHelper.getBoolean(value, true));
        } else if (NatTableCSSConstants.TEXT_DIRECTION.equalsIgnoreCase(property) && (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE)) {
            NatTableCSSHelper.getPainterProperties(context, displayMode).put(NatTableCSSConstants.TEXT_DIRECTION, value.getCssText());
        } else if (NatTableCSSConstants.LINE_SPACING.equalsIgnoreCase(property) && (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE)) {
            NatTableCSSHelper.getPainterProperties(context, displayMode).put(NatTableCSSConstants.LINE_SPACING, (int) ((CSSPrimitiveValue) value).getFloatValue(CSSPrimitiveValue.CSS_PT));
        } else if (NatTableCSSConstants.COLUMN_WIDTH.equalsIgnoreCase(property) && (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE)) {
            CSSPrimitiveValue primitiveValue = (CSSPrimitiveValue) value;
            short type = primitiveValue.getPrimitiveType();
            switch(type) {
                case CSSPrimitiveValue.CSS_IDENT:
                    if ("auto".equalsIgnoreCase(value.getCssText())) {
                        NatTableCSSHelper.getPainterProperties(context, displayMode).put(NatTableCSSConstants.CALCULATE_CELL_WIDTH, true);
                    } else if ("percentage".equalsIgnoreCase(value.getCssText())) {
                        // set column percentage sizing
                        natTable.doCommand(new ColumnSizeConfigurationCommand(label, null, true));
                    }
                    break;
                case CSSPrimitiveValue.CSS_PERCENTAGE:
                    // set column percentage sizing
                    int percentage = (int) ((CSSPrimitiveValue) value).getFloatValue(CSSPrimitiveValue.CSS_PERCENTAGE);
                    natTable.doCommand(new ColumnSizeConfigurationCommand(label, percentage, true));
                    break;
                case CSSPrimitiveValue.CSS_PT:
                case CSSPrimitiveValue.CSS_NUMBER:
                case CSSPrimitiveValue.CSS_PX:
                    // set column width by label
                    int width = (int) ((CSSPrimitiveValue) value).getFloatValue(CSSPrimitiveValue.CSS_PT);
                    natTable.doCommand(new ColumnSizeConfigurationCommand(label, width, false));
                    break;
            }
        } else if (NatTableCSSConstants.ROW_HEIGHT.equalsIgnoreCase(property) && (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE)) {
            CSSPrimitiveValue primitiveValue = (CSSPrimitiveValue) value;
            short type = primitiveValue.getPrimitiveType();
            switch(type) {
                case CSSPrimitiveValue.CSS_IDENT:
                    if ("auto".equalsIgnoreCase(value.getCssText())) {
                        NatTableCSSHelper.getPainterProperties(context, displayMode).put(NatTableCSSConstants.CALCULATE_CELL_HEIGHT, true);
                    } else if ("percentage".equalsIgnoreCase(value.getCssText())) {
                        // set column percentage sizing
                        natTable.doCommand(new RowSizeConfigurationCommand(label, null, true));
                    }
                    break;
                case CSSPrimitiveValue.CSS_PERCENTAGE:
                    // set column percentage sizing
                    int percentage = (int) ((CSSPrimitiveValue) value).getFloatValue(CSSPrimitiveValue.CSS_PERCENTAGE);
                    natTable.doCommand(new RowSizeConfigurationCommand(label, percentage, true));
                    break;
                case CSSPrimitiveValue.CSS_PT:
                case CSSPrimitiveValue.CSS_NUMBER:
                case CSSPrimitiveValue.CSS_PX:
                    // set column width by label
                    int width = (int) ((CSSPrimitiveValue) value).getFloatValue(CSSPrimitiveValue.CSS_PT);
                    natTable.doCommand(new RowSizeConfigurationCommand(label, width, false));
                    break;
            }
        } else if (NatTableCSSConstants.CONVERTER.equalsIgnoreCase(property)) {
            if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
                if (NatTableCSSHelper.isConverterString(value.getCssText())) {
                    natTable.getConfigRegistry().registerConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, NatTableCSSHelper.getDisplayConverter(value.getCssText(), true, null, null, null), displayMode, label);
                }
            } else if (value.getCssValueType() == CSSValue.CSS_VALUE_LIST) {
                String converterKey = null;
                boolean format = true;
                Integer minFractionDigits = null;
                Integer maxFractionDigits = null;
                String pattern = null;
                CSSValueList valueList = (CSSValueList) value;
                int length = valueList.getLength();
                for (int i = 0; i < length; i++) {
                    CSSValue value2 = valueList.item(i);
                    if (value2.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
                        CSSPrimitiveValue primitiveValue = (CSSPrimitiveValue) value2;
                        short type = primitiveValue.getPrimitiveType();
                        switch(type) {
                            case CSSPrimitiveValue.CSS_IDENT:
                                if (NatTableCSSHelper.isConverterString(primitiveValue.getCssText())) {
                                    converterKey = primitiveValue.getCssText();
                                } else if ("true".equals(primitiveValue.getCssText()) || "false".equals(primitiveValue.getCssText())) {
                                    format = NatTableCSSHelper.getBoolean(primitiveValue, true);
                                }
                                break;
                            case CSSPrimitiveValue.CSS_STRING:
                                pattern = primitiveValue.getCssText();
                                break;
                            case CSSPrimitiveValue.CSS_PT:
                            case CSSPrimitiveValue.CSS_NUMBER:
                            case CSSPrimitiveValue.CSS_PX:
                                if (minFractionDigits == null) {
                                    minFractionDigits = (int) primitiveValue.getFloatValue(CSSPrimitiveValue.CSS_PT);
                                } else {
                                    maxFractionDigits = (int) primitiveValue.getFloatValue(CSSPrimitiveValue.CSS_PT);
                                }
                                break;
                        }
                    }
                }
                if (converterKey != null) {
                    natTable.getConfigRegistry().registerConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, NatTableCSSHelper.getDisplayConverter(converterKey, format, minFractionDigits, maxFractionDigits, pattern), displayMode, label);
                }
            }
        } else if (NatTableCSSConstants.PADDING.equalsIgnoreCase(property)) {
            if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
                NatTableCSSHelper.storePadding(NatTableCSSConstants.PADDING_TOP, value, context, displayMode);
                NatTableCSSHelper.storePadding(NatTableCSSConstants.PADDING_RIGHT, value, context, displayMode);
                NatTableCSSHelper.storePadding(NatTableCSSConstants.PADDING_BOTTOM, value, context, displayMode);
                NatTableCSSHelper.storePadding(NatTableCSSConstants.PADDING_LEFT, value, context, displayMode);
            } else if (value.getCssValueType() == CSSValue.CSS_VALUE_LIST) {
                CSSValueList valueList = (CSSValueList) value;
                int length = valueList.getLength();
                if (length == 4) {
                    NatTableCSSHelper.storePadding(NatTableCSSConstants.PADDING_TOP, valueList.item(0), context, displayMode);
                    NatTableCSSHelper.storePadding(NatTableCSSConstants.PADDING_RIGHT, valueList.item(1), context, displayMode);
                    NatTableCSSHelper.storePadding(NatTableCSSConstants.PADDING_BOTTOM, valueList.item(2), context, displayMode);
                    NatTableCSSHelper.storePadding(NatTableCSSConstants.PADDING_LEFT, valueList.item(3), context, displayMode);
                } else if (length == 3) {
                    NatTableCSSHelper.storePadding(NatTableCSSConstants.PADDING_TOP, valueList.item(0), context, displayMode);
                    NatTableCSSHelper.storePadding(NatTableCSSConstants.PADDING_RIGHT, valueList.item(1), context, displayMode);
                    NatTableCSSHelper.storePadding(NatTableCSSConstants.PADDING_BOTTOM, valueList.item(2), context, displayMode);
                    NatTableCSSHelper.storePadding(NatTableCSSConstants.PADDING_LEFT, valueList.item(1), context, displayMode);
                } else if (length == 2) {
                    NatTableCSSHelper.storePadding(NatTableCSSConstants.PADDING_TOP, valueList.item(0), context, displayMode);
                    NatTableCSSHelper.storePadding(NatTableCSSConstants.PADDING_RIGHT, valueList.item(1), context, displayMode);
                    NatTableCSSHelper.storePadding(NatTableCSSConstants.PADDING_BOTTOM, valueList.item(0), context, displayMode);
                    NatTableCSSHelper.storePadding(NatTableCSSConstants.PADDING_LEFT, valueList.item(1), context, displayMode);
                }
            }
        } else if (NatTableCSSConstants.PADDING_TOP.equalsIgnoreCase(property)) {
            NatTableCSSHelper.storePadding(NatTableCSSConstants.PADDING_TOP, value, context, displayMode);
        } else if (NatTableCSSConstants.PADDING_RIGHT.equalsIgnoreCase(property)) {
            NatTableCSSHelper.storePadding(NatTableCSSConstants.PADDING_RIGHT, value, context, displayMode);
        } else if (NatTableCSSConstants.PADDING_BOTTOM.equalsIgnoreCase(property)) {
            NatTableCSSHelper.storePadding(NatTableCSSConstants.PADDING_BOTTOM, value, context, displayMode);
        } else if (NatTableCSSConstants.PADDING_LEFT.equalsIgnoreCase(property)) {
            NatTableCSSHelper.storePadding(NatTableCSSConstants.PADDING_LEFT, value, context, displayMode);
        } else if (NatTableCSSConstants.TABLE_BORDER_COLOR.equals(property) && value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
            // remove any prior configured NatTableBorderOverlayPainter
            for (Iterator<IOverlayPainter> it = natTable.getOverlayPainters().iterator(); it.hasNext(); ) {
                IOverlayPainter painter = it.next();
                if (painter instanceof NatTableBorderOverlayPainter) {
                    it.remove();
                }
            }
            // add the new NatTableBorderOverlayPainter
            if ("auto".equalsIgnoreCase(value.getCssText())) {
                natTable.addOverlayPainter(new NatTableBorderOverlayPainter(true, natTable.getConfigRegistry()));
            } else {
                Color newColor = (Color) engine.convert(value, Color.class, natTable.getDisplay());
                natTable.addOverlayPainter(new NatTableBorderOverlayPainter(newColor, true));
            }
        } else if (NatTableCSSConstants.FILL_HANDLE_BORDER.equalsIgnoreCase(property) && (value.getCssValueType() == CSSValue.CSS_VALUE_LIST)) {
            CSSValueList valueList = (CSSValueList) value;
            BorderStyle borderStyle = new BorderStyle();
            NatTableCSSHelper.storeBorderStyle(valueList, borderStyle, engine, natTable.getDisplay());
            natTable.getConfigRegistry().registerConfigAttribute(FillHandleConfigAttributes.FILL_HANDLE_BORDER_STYLE, borderStyle);
        } else if (NatTableCSSConstants.FILL_HANDLE_COLOR.equalsIgnoreCase(property) && (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE)) {
            natTable.getConfigRegistry().registerConfigAttribute(FillHandleConfigAttributes.FILL_HANDLE_COLOR, (Color) engine.convert(value, Color.class, natTable.getDisplay()));
        } else if (NatTableCSSConstants.FILL_REGION_BORDER.equalsIgnoreCase(property) && (value.getCssValueType() == CSSValue.CSS_VALUE_LIST)) {
            CSSValueList valueList = (CSSValueList) value;
            BorderStyle borderStyle = new BorderStyle();
            NatTableCSSHelper.storeBorderStyle(valueList, borderStyle, engine, natTable.getDisplay());
            natTable.getConfigRegistry().registerConfigAttribute(FillHandleConfigAttributes.FILL_HANDLE_REGION_BORDER_STYLE, borderStyle);
        } else if (NatTableCSSConstants.DECORATION.equalsIgnoreCase(property) && (value.getCssValueType() == CSSValue.CSS_VALUE_LIST)) {
            CSSValueList valueList = (CSSValueList) value;
            int length = valueList.getLength();
            for (int i = 0; i < length; i++) {
                CSSValue value2 = valueList.item(i);
                if (value2.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
                    CSSPrimitiveValue primitiveValue = (CSSPrimitiveValue) value2;
                    short type = primitiveValue.getPrimitiveType();
                    switch(type) {
                        case CSSPrimitiveValue.CSS_IDENT:
                            if ("true".equalsIgnoreCase(value2.getCssText()) || "false".equalsIgnoreCase(value2.getCssText())) {
                                NatTableCSSHelper.getPainterProperties(context, displayMode).put(NatTableCSSConstants.PAINT_DECORATION_DEPENDENT, NatTableCSSHelper.getBoolean(value2, true));
                            } else {
                                CellEdgeEnum edge = NatTableCSSHelper.getCellEdgeEnum(value2.getCssText());
                                NatTableCSSHelper.getPainterProperties(context, displayMode).put(NatTableCSSConstants.DECORATOR_EDGE, edge);
                            }
                            break;
                        case CSSPrimitiveValue.CSS_URI:
                            Image image = (Image) engine.convert(value2, Image.class, natTable.getDisplay());
                            if (image != null) {
                                NatTableCSSHelper.getPainterProperties(context, displayMode).put(NatTableCSSConstants.DECORATOR_IMAGE, image);
                            }
                            break;
                        case CSSPrimitiveValue.CSS_PT:
                        case CSSPrimitiveValue.CSS_NUMBER:
                        case CSSPrimitiveValue.CSS_PX:
                            int spacing = (int) ((CSSPrimitiveValue) value2).getFloatValue(CSSPrimitiveValue.CSS_PT);
                            NatTableCSSHelper.getPainterProperties(context, displayMode).put(NatTableCSSConstants.DECORATOR_SPACING, spacing);
                            break;
                    }
                }
            }
            List<String> decoratorKeys = NatTableCSSHelper.getDecoratorPainter(context, displayMode);
            if (!decoratorKeys.contains(CellPainterFactory.DECORATOR_KEY)) {
                decoratorKeys.add(CellPainterFactory.DECORATOR_KEY);
            }
        } else if (NatTableCSSConstants.INVERT_ICONS.equalsIgnoreCase(property) && (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE)) {
            NatTableCSSHelper.getPainterProperties(context, displayMode).put(NatTableCSSConstants.INVERT_ICONS, NatTableCSSHelper.getBoolean(value, false));
        } else if (NatTableCSSConstants.PERCENTAGE_DECORATOR_COLORS.equalsIgnoreCase(property)) {
            if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
                Color newColor = (Color) engine.convert(value, Color.class, natTable.getDisplay());
                NatTableCSSHelper.applyNatTableStyle(natTable, PercentageBarDecorator.PERCENTAGE_BAR_COMPLETE_REGION_START_COLOR, newColor, displayMode, label);
            } else if (value.getCssValueType() == CSSValue.CSS_VALUE_LIST) {
                CSSValueList valueList = (CSSValueList) value;
                int length = valueList.getLength();
                for (int i = 0; i < length; i++) {
                    CSSValue value2 = valueList.item(i);
                    if (value2.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
                        Color newColor = (Color) engine.convert(value2, Color.class, natTable.getDisplay());
                        ConfigAttribute<Color> percentageConfig = null;
                        switch(i) {
                            case 0:
                                percentageConfig = PercentageBarDecorator.PERCENTAGE_BAR_COMPLETE_REGION_START_COLOR;
                                break;
                            case 1:
                                percentageConfig = PercentageBarDecorator.PERCENTAGE_BAR_COMPLETE_REGION_END_COLOR;
                                break;
                            case 2:
                                percentageConfig = PercentageBarDecorator.PERCENTAGE_BAR_INCOMPLETE_REGION_COLOR;
                                break;
                        }
                        if (percentageConfig != null) {
                            NatTableCSSHelper.applyNatTableStyle(natTable, percentageConfig, newColor, displayMode, label);
                        }
                    }
                }
            }
        } else if (NatTableCSSConstants.TREE_STRUCTURE_PAINTER.equalsIgnoreCase(property)) {
            List<String> painterValues = NatTableCSSHelper.resolvePainterRepresentation(value);
            Map<String, Object> painterProperties = NatTableCSSHelper.getPainterPropertiesInherited(context, natTableContext, displayMode);
            // painter
            if (CellPainterFactory.getInstance().isContentPainterKey(painterValues.get(painterValues.size() - 1))) {
                painterValues.remove(painterValues.size() - 1);
            }
            // add none to the end to ensure that the content painter is
            // resolved dynamically by the TreeLayer
            painterValues.add(CellPainterFactory.NONE);
            ICellPainter painter = CellPainterFactory.getInstance().getCellPainter(painterValues, painterProperties);
            if (painter != null) {
                natTable.getConfigRegistry().registerConfigAttribute(TreeConfigAttributes.TREE_STRUCTURE_PAINTER, painter, displayMode);
            }
        }
        return true;
    }
    return false;
}
Also used : CSS2FontProperties(org.eclipse.e4.ui.css.core.dom.properties.css2.CSS2FontProperties) Image(org.eclipse.swt.graphics.Image) CSSStylableElement(org.eclipse.e4.ui.css.core.dom.CSSStylableElement) ICellPainter(org.eclipse.nebula.widgets.nattable.painter.cell.ICellPainter) CSSValue(org.w3c.dom.css.CSSValue) CSSElementContext(org.eclipse.e4.ui.css.core.engine.CSSElementContext) Iterator(java.util.Iterator) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) CSSValueList(org.w3c.dom.css.CSSValueList) List(java.util.List) NatTableBorderOverlayPainter(org.eclipse.nebula.widgets.nattable.painter.NatTableBorderOverlayPainter) Gradient(org.eclipse.e4.ui.css.core.dom.properties.Gradient) ColumnSizeConfigurationCommand(org.eclipse.nebula.widgets.nattable.resize.command.ColumnSizeConfigurationCommand) IOverlayPainter(org.eclipse.nebula.widgets.nattable.painter.IOverlayPainter) BorderStyle(org.eclipse.nebula.widgets.nattable.style.BorderStyle) Color(org.eclipse.swt.graphics.Color) CellEdgeEnum(org.eclipse.nebula.widgets.nattable.ui.util.CellEdgeEnum) CSSPrimitiveValue(org.w3c.dom.css.CSSPrimitiveValue) RowSizeConfigurationCommand(org.eclipse.nebula.widgets.nattable.resize.command.RowSizeConfigurationCommand) VerticalAlignmentEnum(org.eclipse.nebula.widgets.nattable.style.VerticalAlignmentEnum) HorizontalAlignmentEnum(org.eclipse.nebula.widgets.nattable.style.HorizontalAlignmentEnum) CSSValueList(org.w3c.dom.css.CSSValueList)

Example 7 with NatTableBorderOverlayPainter

use of org.eclipse.nebula.widgets.nattable.painter.NatTableBorderOverlayPainter 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 8 with NatTableBorderOverlayPainter

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

the class _6036_SingleFieldFilterExample method createExampleControl.

@Override
public Control createExampleControl(Composite parent) {
    Composite panel = new Composite(parent, SWT.NONE);
    panel.setLayout(new GridLayout());
    GridDataFactory.fillDefaults().grab(true, true).applyTo(panel);
    Text input = new Text(panel, SWT.SINGLE | SWT.SEARCH | SWT.ICON_CANCEL);
    input.setMessage("type filter text");
    GridDataFactory.fillDefaults().grab(true, false).applyTo(input);
    // property names of the Person class
    String[] propertyNames = { "firstName", "lastName", "gender", "married", "birthday", "address.street", "address.housenumber", "address.postalCode", "address.city" };
    // mapping from property to label, needed for column header labels
    Map<String, String> propertyToLabelMap = new HashMap<>();
    propertyToLabelMap.put("firstName", "Firstname");
    propertyToLabelMap.put("lastName", "Lastname");
    propertyToLabelMap.put("gender", "Gender");
    propertyToLabelMap.put("married", "Married");
    propertyToLabelMap.put("birthday", "Birthday");
    propertyToLabelMap.put("address.street", "Street");
    propertyToLabelMap.put("address.housenumber", "Housenumber");
    propertyToLabelMap.put("address.postalCode", "Postal Code");
    propertyToLabelMap.put("address.city", "City");
    IColumnPropertyAccessor<PersonWithAddress> columnPropertyAccessor = new ExtendedReflectiveColumnPropertyAccessor<>(propertyNames);
    BodyLayerStack<PersonWithAddress> bodyLayerStack = new BodyLayerStack<>(PersonService.getPersonsWithAddress(10000), columnPropertyAccessor);
    // build the column header layer
    IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(propertyNames, propertyToLabelMap);
    DataLayer columnHeaderDataLayer = new DefaultColumnHeaderDataLayer(columnHeaderDataProvider);
    ILayer columnHeaderLayer = new ColumnHeaderLayer(columnHeaderDataLayer, bodyLayerStack, (SelectionLayer) null);
    CompositeLayer composite = new CompositeLayer(1, 2);
    composite.setChildLayer(GridRegion.COLUMN_HEADER, columnHeaderLayer, 0, 0);
    composite.setChildLayer(GridRegion.BODY, bodyLayerStack, 0, 1);
    RegexMarkupValue regexMarkup = new RegexMarkupValue("", "<span style=\"background-color:rgb(255, 255, 0)\">", "</span>");
    NatTable natTable = new NatTable(panel, composite, false);
    natTable.addConfiguration(new DefaultNatTableStyleConfiguration() {

        {
            this.cellPainter = new BackgroundPainter(new PaddingDecorator(new RichTextCellPainter(), 2));
        }

        @Override
        public void configureRegistry(IConfigRegistry configRegistry) {
            super.configureRegistry(configRegistry);
            // markup for highlighting
            MarkupDisplayConverter markupConverter = new MarkupDisplayConverter();
            markupConverter.registerMarkup("highlight", regexMarkup);
            // register markup display converter for normal displaymode in
            // the body
            configRegistry.registerConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, markupConverter, DisplayMode.NORMAL, GridRegion.BODY);
        }
    });
    natTable.configure();
    natTable.addOverlayPainter(new NatTableBorderOverlayPainter());
    GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
    // define a TextMatcherEditor and set it to the FilterList
    TextMatcherEditor<PersonWithAddress> matcherEditor = new TextMatcherEditor<>(new TextFilterator<PersonWithAddress>() {

        @Override
        public void getFilterStrings(List<String> baseList, PersonWithAddress element) {
            // add all values that should be included in filtering
            // Note:
            // if special converters are involved in rendering,
            // consider using them for adding the String values
            baseList.add(element.getFirstName());
            baseList.add(element.getLastName());
            baseList.add("" + element.getGender());
            baseList.add("" + element.isMarried());
            baseList.add("" + element.getBirthday());
            baseList.add(element.getAddress().getStreet());
            baseList.add("" + element.getAddress().getHousenumber());
            baseList.add("" + element.getAddress().getPostalCode());
            baseList.add(element.getAddress().getCity());
        }
    });
    matcherEditor.setMode(TextMatcherEditor.CONTAINS);
    bodyLayerStack.getFilterList().setMatcherEditor(matcherEditor);
    // connect the input field with the matcher
    input.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            if (e.keyCode == SWT.CR || e.keyCode == SWT.KEYPAD_CR) {
                String text = input.getText();
                matcherEditor.setFilterText(new String[] { text });
                regexMarkup.setRegexValue(text.isEmpty() ? "" : "(" + text + ")");
                natTable.refresh(false);
            }
        }
    });
    return natTable;
}
Also used : HashMap(java.util.HashMap) ColumnHeaderLayer(org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer) KeyAdapter(org.eclipse.swt.events.KeyAdapter) IDataProvider(org.eclipse.nebula.widgets.nattable.data.IDataProvider) TextMatcherEditor(ca.odell.glazedlists.matchers.TextMatcherEditor) KeyEvent(org.eclipse.swt.events.KeyEvent) GridLayout(org.eclipse.swt.layout.GridLayout) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) DefaultColumnHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultColumnHeaderDataLayer) ExtendedReflectiveColumnPropertyAccessor(org.eclipse.nebula.widgets.nattable.data.ExtendedReflectiveColumnPropertyAccessor) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) NatTableBorderOverlayPainter(org.eclipse.nebula.widgets.nattable.painter.NatTableBorderOverlayPainter) PersonWithAddress(org.eclipse.nebula.widgets.nattable.dataset.person.PersonWithAddress) BackgroundPainter(org.eclipse.nebula.widgets.nattable.painter.cell.BackgroundPainter) Composite(org.eclipse.swt.widgets.Composite) ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer) PaddingDecorator(org.eclipse.nebula.widgets.nattable.painter.cell.decorator.PaddingDecorator) MarkupDisplayConverter(org.eclipse.nebula.widgets.nattable.extension.nebula.richtext.MarkupDisplayConverter) Text(org.eclipse.swt.widgets.Text) DefaultColumnHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultColumnHeaderDataLayer) RichTextCellPainter(org.eclipse.nebula.widgets.nattable.extension.nebula.richtext.RichTextCellPainter) CompositeLayer(org.eclipse.nebula.widgets.nattable.layer.CompositeLayer) RegexMarkupValue(org.eclipse.nebula.widgets.nattable.extension.nebula.richtext.RegexMarkupValue) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) DefaultColumnHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider)

Example 9 with NatTableBorderOverlayPainter

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

the class _5054_SelectionProviderExample method createExampleControl.

@Override
public Control createExampleControl(Composite parent) {
    Composite panel = new Composite(parent, SWT.NONE);
    panel.setLayout(new GridLayout(2, true));
    // property names of the Person class
    String[] propertyNames = { "lastName", "firstName" };
    // mapping from property to label, needed for column header labels
    Map<String, String> propertyToLabelMap = new HashMap<>();
    propertyToLabelMap.put("lastName", "Lastname");
    propertyToLabelMap.put("firstName", "Firstname");
    IColumnPropertyAccessor<Person> columnPropertyAccessor = new ReflectiveColumnPropertyAccessor<>(propertyNames);
    IRowIdAccessor<Person> rowIdAccessor = new IRowIdAccessor<Person>() {

        @Override
        public Serializable getRowId(Person rowObject) {
            return rowObject.getId();
        }
    };
    // create the first table
    // create the body layer stack
    final IRowDataProvider<Person> firstBodyDataProvider = new ListDataProvider<>(getSimpsonsList(), columnPropertyAccessor);
    final DataLayer firstBodyDataLayer = new DataLayer(firstBodyDataProvider);
    final SelectionLayer firstSelectionLayer = new SelectionLayer(firstBodyDataLayer);
    ViewportLayer firstViewportLayer = new ViewportLayer(firstSelectionLayer);
    // use a RowSelectionModel that will perform row selections and is able
    // to identify a row via unique ID
    firstSelectionLayer.setSelectionModel(new RowSelectionModel<>(firstSelectionLayer, firstBodyDataProvider, rowIdAccessor));
    // create the column header layer stack
    IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(propertyNames, propertyToLabelMap);
    DataLayer firstColumnHeaderDataLayer = new DataLayer(columnHeaderDataProvider);
    ColumnHeaderLayer firstColumnHeaderLayer = new ColumnHeaderLayer(firstColumnHeaderDataLayer, firstViewportLayer, firstSelectionLayer);
    // register custom label styling to indicate if the table is active
    firstColumnHeaderDataLayer.setConfigLabelAccumulator(new IConfigLabelAccumulator() {

        @Override
        public void accumulateConfigLabels(LabelStack configLabels, int columnPosition, int rowPosition) {
            if (_5054_SelectionProviderExample.this.isFirstSelectionProvider) {
                configLabels.addLabelOnTop(ACTIVE_LABEL);
            }
        }
    });
    // set the region labels to make default configurations work, e.g.
    // selection
    CompositeLayer firstCompositeLayer = new CompositeLayer(1, 2);
    firstCompositeLayer.setChildLayer(GridRegion.COLUMN_HEADER, firstColumnHeaderLayer, 0, 0);
    firstCompositeLayer.setChildLayer(GridRegion.BODY, firstViewportLayer, 0, 1);
    final NatTable firstNatTable = new NatTable(panel, firstCompositeLayer, false);
    firstNatTable.addConfiguration(new DefaultNatTableStyleConfiguration());
    firstNatTable.addConfiguration(new ActiveTableStyleConfiguration());
    firstNatTable.configure();
    // set the modern theme
    firstNatTable.setTheme(new ModernNatTableThemeConfiguration());
    // add overlay painter for full borders
    firstNatTable.addOverlayPainter(new NatTableBorderOverlayPainter());
    // create the second table
    // create the body layer stack
    final IRowDataProvider<Person> secondBodyDataProvider = new ListDataProvider<>(getFlandersList(), columnPropertyAccessor);
    final DataLayer secondBodyDataLayer = new DataLayer(secondBodyDataProvider);
    final SelectionLayer secondSelectionLayer = new SelectionLayer(secondBodyDataLayer);
    ViewportLayer secondViewportLayer = new ViewportLayer(secondSelectionLayer);
    // use a RowSelectionModel that will perform row selections and is able
    // to identify a row via unique ID
    secondSelectionLayer.setSelectionModel(new RowSelectionModel<>(secondSelectionLayer, secondBodyDataProvider, rowIdAccessor));
    // create the column header layer stack
    DataLayer secondColumnHeaderDataLayer = new DataLayer(columnHeaderDataProvider);
    ILayer secondColumnHeaderLayer = new ColumnHeaderLayer(secondColumnHeaderDataLayer, secondViewportLayer, secondSelectionLayer);
    // register custom label styling to indicate if the table is active
    secondColumnHeaderDataLayer.setConfigLabelAccumulator(new IConfigLabelAccumulator() {

        @Override
        public void accumulateConfigLabels(LabelStack configLabels, int columnPosition, int rowPosition) {
            if (!_5054_SelectionProviderExample.this.isFirstSelectionProvider) {
                configLabels.addLabelOnTop(ACTIVE_LABEL);
            }
        }
    });
    // set the region labels to make default configurations work, e.g.
    // selection
    CompositeLayer secondCompositeLayer = new CompositeLayer(1, 2);
    secondCompositeLayer.setChildLayer(GridRegion.COLUMN_HEADER, secondColumnHeaderLayer, 0, 0);
    secondCompositeLayer.setChildLayer(GridRegion.BODY, secondViewportLayer, 0, 1);
    final NatTable secondNatTable = new NatTable(panel, secondCompositeLayer, false);
    secondNatTable.addConfiguration(new DefaultNatTableStyleConfiguration());
    secondNatTable.addConfiguration(new ActiveTableStyleConfiguration());
    secondNatTable.configure();
    // set the modern theme
    secondNatTable.setTheme(new ModernNatTableThemeConfiguration());
    // add overlay painter for full borders
    secondNatTable.addOverlayPainter(new NatTableBorderOverlayPainter());
    // set ISelectionProvider
    final RowSelectionProvider<Person> selectionProvider = new RowSelectionProvider<>(firstSelectionLayer, firstBodyDataProvider);
    // add a listener to the selection provider, in an Eclipse application
    // you would do this e.g. getSite().getPage().addSelectionListener()
    selectionProvider.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            log("Selection changed:");
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            @SuppressWarnings("rawtypes") Iterator it = selection.iterator();
            while (it.hasNext()) {
                Person selected = (Person) it.next();
                log("  " + selected.getFirstName() + " " + selected.getLastName());
            }
        }
    });
    // layout widgets
    GridDataFactory.fillDefaults().grab(true, true).applyTo(firstNatTable);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(secondNatTable);
    // add a region for buttons
    Composite buttonArea = new Composite(panel, SWT.NONE);
    buttonArea.setLayout(new RowLayout());
    GridDataFactory.fillDefaults().grab(true, false).span(2, 1).applyTo(buttonArea);
    // create a button to enable selection provider change
    Button button = new Button(buttonArea, SWT.PUSH);
    button.setText("Change selection provider");
    button.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            _5054_SelectionProviderExample.this.isFirstSelectionProvider = !_5054_SelectionProviderExample.this.isFirstSelectionProvider;
            if (_5054_SelectionProviderExample.this.isFirstSelectionProvider) {
                selectionProvider.updateSelectionProvider(firstSelectionLayer, firstBodyDataProvider);
            } else {
                selectionProvider.updateSelectionProvider(secondSelectionLayer, secondBodyDataProvider);
            }
            // refresh both tables to update the active rendering in the
            // column header/ this is not necessary for updating the
            // selection provider
            firstNatTable.doCommand(new VisualRefreshCommand());
            secondNatTable.doCommand(new VisualRefreshCommand());
        }
    });
    // add a log area to the example to show the log entries
    Text output = setupTextArea(panel);
    GridDataFactory.fillDefaults().grab(true, true).span(2, 1).applyTo(output);
    return panel;
}
Also used : ListDataProvider(org.eclipse.nebula.widgets.nattable.data.ListDataProvider) LabelStack(org.eclipse.nebula.widgets.nattable.layer.LabelStack) HashMap(java.util.HashMap) ColumnHeaderLayer(org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer) IConfigLabelAccumulator(org.eclipse.nebula.widgets.nattable.layer.cell.IConfigLabelAccumulator) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ViewportLayer(org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer) IDataProvider(org.eclipse.nebula.widgets.nattable.data.IDataProvider) IRowIdAccessor(org.eclipse.nebula.widgets.nattable.data.IRowIdAccessor) GridLayout(org.eclipse.swt.layout.GridLayout) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) Button(org.eclipse.swt.widgets.Button) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) RowLayout(org.eclipse.swt.layout.RowLayout) Iterator(java.util.Iterator) SelectionEvent(org.eclipse.swt.events.SelectionEvent) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) NatTableBorderOverlayPainter(org.eclipse.nebula.widgets.nattable.painter.NatTableBorderOverlayPainter) VisualRefreshCommand(org.eclipse.nebula.widgets.nattable.command.VisualRefreshCommand) ModernNatTableThemeConfiguration(org.eclipse.nebula.widgets.nattable.style.theme.ModernNatTableThemeConfiguration) Composite(org.eclipse.swt.widgets.Composite) ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Text(org.eclipse.swt.widgets.Text) CompositeLayer(org.eclipse.nebula.widgets.nattable.layer.CompositeLayer) RowSelectionProvider(org.eclipse.nebula.widgets.nattable.selection.RowSelectionProvider) ReflectiveColumnPropertyAccessor(org.eclipse.nebula.widgets.nattable.data.ReflectiveColumnPropertyAccessor) SelectionLayer(org.eclipse.nebula.widgets.nattable.selection.SelectionLayer) DefaultColumnHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider) Person(org.eclipse.nebula.widgets.nattable.dataset.person.Person)

Example 10 with NatTableBorderOverlayPainter

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

the class _810_SortableGroupByFilterColumnGroupAndFreezeExample method createExampleControl.

@Override
public Control createExampleControl(Composite parent) {
    Composite container = new Composite(parent, SWT.NONE);
    container.setLayout(new GridLayout());
    // create a new ConfigRegistry which will be needed for GlazedLists
    // handling
    final ConfigRegistry configRegistry = new ConfigRegistry();
    // property names of the ExtendedPersonWithAddress class
    String[] propertyNames = { "firstName", "lastName", "age", "money", "married", "gender", "birthday" };
    // mapping from property to label, needed for column header labels
    Map<String, String> propertyToLabelMap = new HashMap<>();
    propertyToLabelMap.put("firstName", "Firstname");
    propertyToLabelMap.put("lastName", "Lastname");
    propertyToLabelMap.put("age", "Age");
    propertyToLabelMap.put("money", "Money");
    propertyToLabelMap.put("married", "Married");
    propertyToLabelMap.put("gender", "Gender");
    propertyToLabelMap.put("birthday", "Birthday");
    final IColumnPropertyAccessor<ExtendedPersonWithAddress> columnPropertyAccessor = new ExtendedReflectiveColumnPropertyAccessor<>(propertyNames);
    // to enable the group by summary feature, the GroupByDataLayer needs to
    // know the ConfigRegistry
    final BodyLayerStack<ExtendedPersonWithAddress> bodyLayerStack = new BodyLayerStack<>(PersonService.getExtendedPersonsWithAddress(10), columnPropertyAccessor, configRegistry);
    bodyLayerStack.getBodyDataLayer().setConfigLabelAccumulator(new ColumnLabelAccumulator());
    // build the column header layer
    IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(propertyNames, propertyToLabelMap);
    DataLayer columnHeaderDataLayer = new DefaultColumnHeaderDataLayer(columnHeaderDataProvider);
    ColumnHeaderLayer columnHeaderLayer = new ColumnHeaderLayer(columnHeaderDataLayer, bodyLayerStack, bodyLayerStack.getSelectionLayer());
    // add sorting
    SortHeaderLayer<ExtendedPersonWithAddress> sortHeaderLayer = new SortHeaderLayer<>(columnHeaderLayer, new GlazedListsSortModel<>(bodyLayerStack.getSortedList(), columnPropertyAccessor, configRegistry, columnHeaderDataLayer), false);
    // connect sortModel to GroupByDataLayer to support sorting by group by
    // summary values
    bodyLayerStack.getBodyDataLayer().initializeTreeComparator(sortHeaderLayer.getSortModel(), bodyLayerStack.getTreeLayer(), true);
    ColumnGroupHeaderLayer columnGroupHeaderLayer = new ColumnGroupHeaderLayer(sortHeaderLayer, bodyLayerStack.getSelectionLayer(), this.columnGroupModel);
    columnGroupHeaderLayer.setCalculateHeight(true);
    // add the filter row functionality
    final FilterRowHeaderComposite<ExtendedPersonWithAddress> filterRowHeaderLayer = new FilterRowHeaderComposite<>(new DefaultGlazedListsFilterStrategy<>(bodyLayerStack.getFilterList(), columnPropertyAccessor, configRegistry), columnGroupHeaderLayer, columnHeaderDataLayer.getDataProvider(), configRegistry);
    // Row header
    // Adding the specialized DefaultSummaryRowHeaderDataProvider to
    // indicate the summary row in the row header
    IDataProvider rowHeaderDataProvider = new DefaultSummaryRowHeaderDataProvider(bodyLayerStack.getBodyDataLayer().getDataProvider(), "\u2211");
    final DataLayer rowHeaderDataLayer = new DefaultRowHeaderDataLayer(rowHeaderDataProvider);
    // add a label to the row header summary row cell aswell, so it can be
    // styled differently too
    // in this case it will simply use the same styling as the summary row
    // in the body
    rowHeaderDataLayer.setConfigLabelAccumulator(new AbstractOverrider() {

        @Override
        public void accumulateConfigLabels(LabelStack configLabels, int columnPosition, int rowPosition) {
            if ((rowPosition + 1) == rowHeaderDataLayer.getRowCount()) {
                configLabels.addLabel(ROW_HEADER_SUMMARY_ROW);
                configLabels.addLabel(SummaryRowLayer.DEFAULT_SUMMARY_ROW_CONFIG_LABEL);
            }
        }
    });
    ILayer rowHeaderLayer = new RowHeaderLayer(rowHeaderDataLayer, bodyLayerStack, bodyLayerStack.getSelectionLayer());
    // build the corner layer
    IDataProvider cornerDataProvider = new DefaultCornerDataProvider(columnHeaderDataProvider, rowHeaderDataProvider);
    DataLayer cornerDataLayer = new DataLayer(cornerDataProvider);
    ILayer cornerLayer = new CornerLayer(cornerDataLayer, rowHeaderLayer, filterRowHeaderLayer);
    // build the grid layer
    GridLayer gridLayer = new GridLayer(bodyLayerStack, filterRowHeaderLayer, rowHeaderLayer, cornerLayer);
    // set the group by header on top of the grid
    CompositeLayer compositeGridLayer = new CompositeLayer(1, 2);
    final GroupByHeaderLayer groupByHeaderLayer = new GroupByHeaderLayer(bodyLayerStack.getGroupByModel(), gridLayer, columnHeaderDataProvider, columnHeaderLayer);
    compositeGridLayer.setChildLayer(GroupByHeaderLayer.GROUP_BY_REGION, groupByHeaderLayer, 0, 0);
    compositeGridLayer.setChildLayer("Grid", gridLayer, 0, 1);
    // turn the auto configuration off as we want to add our header menu
    // configuration
    final NatTable natTable = new NatTable(container, compositeGridLayer, false);
    // as the autoconfiguration of the NatTable is turned off, we have to
    // add the DefaultNatTableStyleConfiguration and the ConfigRegistry
    // manually
    natTable.setConfigRegistry(configRegistry);
    natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
    // add some additional styling
    natTable.addConfiguration(new AbstractRegistryConfiguration() {

        @Override
        public void configureRegistry(IConfigRegistry configRegistry) {
            configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, new CheckBoxPainter(), DisplayMode.NORMAL, ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 4);
            configRegistry.registerConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, new DefaultDoubleDisplayConverter(), DisplayMode.NORMAL, ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 3);
        }
    });
    // add sorting configuration
    natTable.addConfiguration(new SingleClickSortConfiguration());
    this.sumMoneySummaryProvider = new SummationGroupBySummaryProvider<>(columnPropertyAccessor);
    this.avgMoneySummaryProvider = new AverageMoneyGroupBySummaryProvider();
    // add group by summary configuration
    natTable.addConfiguration(new AbstractRegistryConfiguration() {

        @Override
        public void configureRegistry(IConfigRegistry configRegistry) {
            configRegistry.registerConfigAttribute(GroupByConfigAttributes.GROUP_BY_SUMMARY_PROVIDER, _810_SortableGroupByFilterColumnGroupAndFreezeExample.this.sumMoneySummaryProvider, DisplayMode.NORMAL, GroupByDataLayer.GROUP_BY_COLUMN_PREFIX + 3);
            configRegistry.registerConfigAttribute(GroupByConfigAttributes.GROUP_BY_SUMMARY_PROVIDER, new AverageAgeGroupBySummaryProvider(), DisplayMode.NORMAL, GroupByDataLayer.GROUP_BY_COLUMN_PREFIX + 2);
            configRegistry.registerConfigAttribute(GroupByConfigAttributes.GROUP_BY_CHILD_COUNT_PATTERN, "[{0}] - ({1})");
            configRegistry.registerConfigAttribute(GroupByConfigAttributes.GROUP_BY_HINT, "Drag columns here");
            Style hintStyle = new Style();
            hintStyle.setAttributeValue(CellStyleAttributes.FONT, GUIHelper.getFont(new FontData("Arial", 10, SWT.ITALIC)));
            configRegistry.registerConfigAttribute(GroupByConfigAttributes.GROUP_BY_HINT_STYLE, hintStyle);
            configRegistry.registerConfigAttribute(SummaryRowConfigAttributes.SUMMARY_PROVIDER, new SummationSummaryProvider(bodyLayerStack.bodyDataProvider, false), DisplayMode.NORMAL, SummaryRowLayer.DEFAULT_SUMMARY_COLUMN_CONFIG_LABEL_PREFIX + 3);
            configRegistry.registerConfigAttribute(SummaryRowConfigAttributes.SUMMARY_PROVIDER, new AverageAgeSummaryProvider(bodyLayerStack.bodyDataProvider), DisplayMode.NORMAL, SummaryRowLayer.DEFAULT_SUMMARY_COLUMN_CONFIG_LABEL_PREFIX + 2);
            configRegistry.registerConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, new SummaryDisplayConverter(new DefaultDoubleDisplayConverter()), DisplayMode.NORMAL, SummaryRowLayer.DEFAULT_SUMMARY_COLUMN_CONFIG_LABEL_PREFIX + 3);
            // the main styling of the summary row cell in the row header is
            // done via summary row default style, but we need to override
            // the alignment
            IStyle style = new Style();
            style.setAttributeValue(CellStyleAttributes.HORIZONTAL_ALIGNMENT, HorizontalAlignmentEnum.CENTER);
            configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, style, DisplayMode.NORMAL, ROW_HEADER_SUMMARY_ROW);
            configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, style, DisplayMode.SELECT, ROW_HEADER_SUMMARY_ROW);
        }
    });
    // add group by header configuration
    natTable.addConfiguration(new GroupByHeaderMenuConfiguration(natTable, groupByHeaderLayer));
    natTable.addConfiguration(new AbstractHeaderMenuConfiguration(natTable) {

        @Override
        protected PopupMenuBuilder createColumnHeaderMenu(NatTable natTable) {
            return super.createColumnHeaderMenu(natTable).withHideColumnMenuItem().withShowAllColumnsMenuItem().withColumnChooserMenuItem().withCreateColumnGroupsMenuItem().withUngroupColumnsMenuItem().withAutoResizeSelectedColumnsMenuItem().withColumnRenameDialog().withClearAllFilters().withStateManagerMenuItemProvider();
        }

        @Override
        protected PopupMenuBuilder createCornerMenu(NatTable natTable) {
            return super.createCornerMenu(natTable).withShowAllColumnsMenuItem().withStateManagerMenuItemProvider();
        }
    });
    natTable.configure();
    natTable.registerCommandHandler(new DisplayPersistenceDialogCommandHandler(natTable));
    DisplayColumnChooserCommandHandler columnChooserCommandHandler = new DisplayColumnChooserCommandHandler(bodyLayerStack.getSelectionLayer(), bodyLayerStack.getColumnHideShowLayer(), columnHeaderLayer, columnHeaderDataLayer, null, null);
    natTable.registerCommandHandler(columnChooserCommandHandler);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
    Composite buttonPanel = new Composite(container, SWT.NONE);
    buttonPanel.setLayout(new RowLayout());
    GridDataFactory.fillDefaults().grab(true, false).applyTo(buttonPanel);
    Button toggleHeaderButton = new Button(buttonPanel, SWT.PUSH);
    toggleHeaderButton.setText("Toggle Group By Header");
    toggleHeaderButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            groupByHeaderLayer.setVisible(!groupByHeaderLayer.isVisible());
        }
    });
    Button toggleFilterButton = new Button(buttonPanel, SWT.PUSH);
    toggleFilterButton.setText("Toggle Filter Row");
    toggleFilterButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            filterRowHeaderLayer.setFilterRowVisible(!filterRowHeaderLayer.isFilterRowVisible());
        }
    });
    Button collapseAllButton = new Button(buttonPanel, SWT.PUSH);
    collapseAllButton.setText("Collapse All");
    collapseAllButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            natTable.doCommand(new TreeCollapseAllCommand());
        }
    });
    Button expandAllButton = new Button(buttonPanel, SWT.PUSH);
    expandAllButton.setText("Expand All");
    expandAllButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            natTable.doCommand(new TreeExpandAllCommand());
        }
    });
    Button toggleMoneySummaryButton = new Button(buttonPanel, SWT.PUSH);
    toggleMoneySummaryButton.setText("Toggle Money Group Summary (SUM/AVG)");
    toggleMoneySummaryButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            // clear the group by summary cache so the new summary
            // calculation gets triggered
            bodyLayerStack.getBodyDataLayer().clearCache();
            _810_SortableGroupByFilterColumnGroupAndFreezeExample.this.useMoneySum = !_810_SortableGroupByFilterColumnGroupAndFreezeExample.this.useMoneySum;
            if (_810_SortableGroupByFilterColumnGroupAndFreezeExample.this.useMoneySum) {
                configRegistry.registerConfigAttribute(GroupByConfigAttributes.GROUP_BY_SUMMARY_PROVIDER, _810_SortableGroupByFilterColumnGroupAndFreezeExample.this.sumMoneySummaryProvider, DisplayMode.NORMAL, GroupByDataLayer.GROUP_BY_COLUMN_PREFIX + 3);
            } else {
                configRegistry.registerConfigAttribute(GroupByConfigAttributes.GROUP_BY_SUMMARY_PROVIDER, _810_SortableGroupByFilterColumnGroupAndFreezeExample.this.avgMoneySummaryProvider, DisplayMode.NORMAL, GroupByDataLayer.GROUP_BY_COLUMN_PREFIX + 3);
            }
            natTable.doCommand(new VisualRefreshCommand());
        }
    });
    // this button adds data to the grid
    // try to group by last name, sort by last name desc and then add
    // dynamic data for verification
    Button addDynamicDataButton = new Button(buttonPanel, SWT.PUSH);
    addDynamicDataButton.setText("Add Data");
    addDynamicDataButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            Address address = new Address();
            address.setStreet("Some Street");
            address.setHousenumber(42);
            address.setPostalCode(12345);
            address.setCity("In the clouds");
            Person person = new Person(42, "Ralph", "Wiggum", Gender.MALE, false, new Date());
            ExtendedPersonWithAddress entry = new ExtendedPersonWithAddress(person, address, "0000", "The little Ralphy", PersonService.createRandomMoneyAmount(), new ArrayList<String>(), new ArrayList<String>());
            bodyLayerStack.getEventList().add(entry);
            person = new Person(42, "Clancy", "Wiggum", Gender.MALE, true, new Date());
            entry = new ExtendedPersonWithAddress(person, address, "XXXL", "It is Chief Wiggum", PersonService.createRandomMoneyAmount(), new ArrayList<String>(), new ArrayList<String>());
            bodyLayerStack.getEventList().add(entry);
            person = new Person(42, "Sarah", "Wiggum", Gender.FEMALE, true, new Date());
            entry = new ExtendedPersonWithAddress(person, address, "mommy", "Little Ralphy's mother", PersonService.createRandomMoneyAmount(), new ArrayList<String>(), new ArrayList<String>());
            bodyLayerStack.getEventList().add(entry);
        }
    });
    // add modern styling
    ThemeConfiguration theme = new ModernNatTableThemeConfiguration();
    theme.addThemeExtension(new ModernGroupByThemeExtension());
    natTable.setTheme(theme);
    // add a border on every side of the table
    natTable.addOverlayPainter(new NatTableBorderOverlayPainter());
    this.natTable = natTable;
    return container;
}
Also used : SummaryDisplayConverter(org.eclipse.nebula.widgets.nattable.summaryrow.SummaryDisplayConverter) ExtendedPersonWithAddress(org.eclipse.nebula.widgets.nattable.dataset.person.ExtendedPersonWithAddress) ExtendedPersonWithAddress(org.eclipse.nebula.widgets.nattable.dataset.person.ExtendedPersonWithAddress) Address(org.eclipse.nebula.widgets.nattable.dataset.person.Address) HashMap(java.util.HashMap) AbstractRegistryConfiguration(org.eclipse.nebula.widgets.nattable.config.AbstractRegistryConfiguration) ArrayList(java.util.ArrayList) DefaultCornerDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider) ConfigRegistry(org.eclipse.nebula.widgets.nattable.config.ConfigRegistry) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) DefaultColumnHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultColumnHeaderDataLayer) GroupByDataLayer(org.eclipse.nebula.widgets.nattable.extension.glazedlists.groupBy.GroupByDataLayer) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) DefaultRowHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer) TreeCollapseAllCommand(org.eclipse.nebula.widgets.nattable.tree.command.TreeCollapseAllCommand) Button(org.eclipse.swt.widgets.Button) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) SelectionEvent(org.eclipse.swt.events.SelectionEvent) NatTableBorderOverlayPainter(org.eclipse.nebula.widgets.nattable.painter.NatTableBorderOverlayPainter) GroupByHeaderLayer(org.eclipse.nebula.widgets.nattable.extension.glazedlists.groupBy.GroupByHeaderLayer) AbstractOverrider(org.eclipse.nebula.widgets.nattable.layer.cell.AbstractOverrider) FontData(org.eclipse.swt.graphics.FontData) SortHeaderLayer(org.eclipse.nebula.widgets.nattable.sort.SortHeaderLayer) SummationSummaryProvider(org.eclipse.nebula.widgets.nattable.summaryrow.SummationSummaryProvider) DefaultColumnHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultColumnHeaderDataLayer) CompositeLayer(org.eclipse.nebula.widgets.nattable.layer.CompositeLayer) ColumnGroupHeaderLayer(org.eclipse.nebula.widgets.nattable.group.ColumnGroupHeaderLayer) IStyle(org.eclipse.nebula.widgets.nattable.style.IStyle) GridLayer(org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer) ColumnLabelAccumulator(org.eclipse.nebula.widgets.nattable.layer.cell.ColumnLabelAccumulator) Person(org.eclipse.nebula.widgets.nattable.dataset.person.Person) DefaultSummaryRowHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultSummaryRowHeaderDataProvider) LabelStack(org.eclipse.nebula.widgets.nattable.layer.LabelStack) ColumnHeaderLayer(org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer) IDataProvider(org.eclipse.nebula.widgets.nattable.data.IDataProvider) GroupByHeaderMenuConfiguration(org.eclipse.nebula.widgets.nattable.extension.glazedlists.groupBy.GroupByHeaderMenuConfiguration) DefaultDoubleDisplayConverter(org.eclipse.nebula.widgets.nattable.data.convert.DefaultDoubleDisplayConverter) GridLayout(org.eclipse.swt.layout.GridLayout) DisplayPersistenceDialogCommandHandler(org.eclipse.nebula.widgets.nattable.persistence.command.DisplayPersistenceDialogCommandHandler) ExtendedReflectiveColumnPropertyAccessor(org.eclipse.nebula.widgets.nattable.data.ExtendedReflectiveColumnPropertyAccessor) CheckBoxPainter(org.eclipse.nebula.widgets.nattable.painter.cell.CheckBoxPainter) RowLayout(org.eclipse.swt.layout.RowLayout) DefaultRowHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer) IStyle(org.eclipse.nebula.widgets.nattable.style.IStyle) Style(org.eclipse.nebula.widgets.nattable.style.Style) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) VisualRefreshCommand(org.eclipse.nebula.widgets.nattable.command.VisualRefreshCommand) ModernNatTableThemeConfiguration(org.eclipse.nebula.widgets.nattable.style.theme.ModernNatTableThemeConfiguration) ThemeConfiguration(org.eclipse.nebula.widgets.nattable.style.theme.ThemeConfiguration) ModernNatTableThemeConfiguration(org.eclipse.nebula.widgets.nattable.style.theme.ModernNatTableThemeConfiguration) FilterRowHeaderComposite(org.eclipse.nebula.widgets.nattable.filterrow.FilterRowHeaderComposite) Composite(org.eclipse.swt.widgets.Composite) FilterRowHeaderComposite(org.eclipse.nebula.widgets.nattable.filterrow.FilterRowHeaderComposite) DisplayColumnChooserCommandHandler(org.eclipse.nebula.widgets.nattable.columnChooser.command.DisplayColumnChooserCommandHandler) ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Date(java.util.Date) RowHeaderLayer(org.eclipse.nebula.widgets.nattable.grid.layer.RowHeaderLayer) TreeExpandAllCommand(org.eclipse.nebula.widgets.nattable.tree.command.TreeExpandAllCommand) CornerLayer(org.eclipse.nebula.widgets.nattable.grid.layer.CornerLayer) SingleClickSortConfiguration(org.eclipse.nebula.widgets.nattable.sort.config.SingleClickSortConfiguration) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) AbstractHeaderMenuConfiguration(org.eclipse.nebula.widgets.nattable.ui.menu.AbstractHeaderMenuConfiguration) DefaultColumnHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider) PopupMenuBuilder(org.eclipse.nebula.widgets.nattable.ui.menu.PopupMenuBuilder) ModernGroupByThemeExtension(org.eclipse.nebula.widgets.nattable.extension.glazedlists.groupBy.ModernGroupByThemeExtension)

Aggregations

NatTable (org.eclipse.nebula.widgets.nattable.NatTable)13 NatTableBorderOverlayPainter (org.eclipse.nebula.widgets.nattable.painter.NatTableBorderOverlayPainter)13 HashMap (java.util.HashMap)11 DataLayer (org.eclipse.nebula.widgets.nattable.layer.DataLayer)11 IDataProvider (org.eclipse.nebula.widgets.nattable.data.IDataProvider)10 ColumnHeaderLayer (org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer)9 DefaultNatTableStyleConfiguration (org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration)8 DefaultColumnHeaderDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider)8 DefaultColumnHeaderDataLayer (org.eclipse.nebula.widgets.nattable.grid.layer.DefaultColumnHeaderDataLayer)8 ILayer (org.eclipse.nebula.widgets.nattable.layer.ILayer)8 GridLayout (org.eclipse.swt.layout.GridLayout)8 Composite (org.eclipse.swt.widgets.Composite)8 DefaultRowHeaderDataLayer (org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer)7 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)7 SelectionEvent (org.eclipse.swt.events.SelectionEvent)7 Button (org.eclipse.swt.widgets.Button)7 IConfigRegistry (org.eclipse.nebula.widgets.nattable.config.IConfigRegistry)6 ExtendedReflectiveColumnPropertyAccessor (org.eclipse.nebula.widgets.nattable.data.ExtendedReflectiveColumnPropertyAccessor)6 ListDataProvider (org.eclipse.nebula.widgets.nattable.data.ListDataProvider)6 DefaultCornerDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider)6