Search in sources :

Example 1 with CSSValue

use of org.w3c.dom.css.CSSValue 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 2 with CSSValue

use of org.w3c.dom.css.CSSValue in project webtools.sourceediting by eclipse.

the class CSSFontFamilyTest method testFontFamilies.

public void testFontFamilies() throws IOException {
    ICSSModel model = getModel();
    IStructuredDocument structuredDocument = model.getStructuredDocument();
    structuredDocument.set(FileUtil.createString("src/org/eclipse/wst/css/core/tests/testfiles", "CSSFontFamilyTest.css"));
    CSSStyleSheet sheet = (CSSStyleSheet) model.getDocument();
    CSSRuleList rules = sheet.getCssRules();
    assertEquals(4, rules.getLength());
    // Rule 1: No whitespace
    CSSRule rule;
    CSSStyleDeclaration declaration;
    CSSValue value;
    // Rule 1: No whitespace
    rule = rules.item(0);
    assertEquals(CSSRule.STYLE_RULE, rule.getType());
    assertTrue(rule instanceof CSSStyleRule);
    declaration = ((CSSStyleRule) rule).getStyle();
    value = declaration.getPropertyCSSValue(FONT_FAMILY);
    checkPrimitiveString(value, new PrimitiveString(CSSPrimitiveValue.CSS_IDENT, "Courier"));
    // Rule 2: Single whitespace
    rule = rules.item(1);
    assertEquals(CSSRule.STYLE_RULE, rule.getType());
    assertTrue(rule instanceof CSSStyleRule);
    declaration = ((CSSStyleRule) rule).getStyle();
    value = declaration.getPropertyCSSValue(FONT_FAMILY);
    checkPrimitiveString(value, new PrimitiveString(CSSPrimitiveValue.CSS_IDENT, "Courier New"));
    // Rule 3: In quotes
    rule = rules.item(2);
    assertEquals(CSSRule.STYLE_RULE, rule.getType());
    assertTrue(rule instanceof CSSStyleRule);
    declaration = ((CSSStyleRule) rule).getStyle();
    value = declaration.getPropertyCSSValue(FONT_FAMILY);
    checkPrimitiveString(value, new PrimitiveString(CSSPrimitiveValue.CSS_STRING, "Courier New"));
    // Rule 4: Tabs and spaces all over
    rule = rules.item(3);
    assertEquals(CSSRule.STYLE_RULE, rule.getType());
    assertTrue(rule instanceof CSSStyleRule);
    declaration = ((CSSStyleRule) rule).getStyle();
    value = declaration.getPropertyCSSValue(FONT_FAMILY);
    checkPrimitiveString(value, new PrimitiveString(CSSPrimitiveValue.CSS_IDENT, "Comic Sans"));
}
Also used : ICSSValue(org.eclipse.wst.css.core.internal.provisional.document.ICSSValue) CSSValue(org.w3c.dom.css.CSSValue) CSSRule(org.w3c.dom.css.CSSRule) ICSSModel(org.eclipse.wst.css.core.internal.provisional.document.ICSSModel) CSSStyleRule(org.w3c.dom.css.CSSStyleRule) CSSStyleSheet(org.w3c.dom.css.CSSStyleSheet) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) CSSStyleDeclaration(org.w3c.dom.css.CSSStyleDeclaration) CSSRuleList(org.w3c.dom.css.CSSRuleList)

Example 3 with CSSValue

use of org.w3c.dom.css.CSSValue in project webtools.sourceediting by eclipse.

the class CSSPageRuleTest method testInsertText4.

public void testInsertText4() throws IOException {
    ICSSModel model = getModel();
    IStructuredDocument structuredDocument = model.getStructuredDocument();
    structuredDocument.set(FileUtil.createString("src/org/eclipse/wst/css/core/tests/testfiles", "CSSPageRuleTest.css"));
    CSSStyleSheet sheet = (CSSStyleSheet) model.getDocument();
    CSSRuleList ruleList = sheet.getCssRules();
    assertEquals(6, ruleList.getLength());
    CSSRule rule;
    CSSStyleDeclaration declaration;
    CSSValue value;
    // rule 4
    rule = ruleList.item(3);
    assertEquals(CSSRule.PAGE_RULE, rule.getType());
    assertTrue(rule instanceof CSSPageRule);
    assertEquals(":right", ((CSSPageRule) rule).getSelectorText());
    declaration = ((CSSPageRule) rule).getStyle();
    assertEquals(2, declaration.getLength());
    value = declaration.getPropertyCSSValue("margin-left");
    checkPrimitiveNumber(value, new PrimitiveNumber(CSSPrimitiveValue.CSS_CM, 3));
    value = declaration.getPropertyCSSValue("margin-right");
    checkPrimitiveNumber(value, new PrimitiveNumber(CSSPrimitiveValue.CSS_CM, 4));
}
Also used : CSSPageRule(org.w3c.dom.css.CSSPageRule) CSSValue(org.w3c.dom.css.CSSValue) CSSRule(org.w3c.dom.css.CSSRule) ICSSModel(org.eclipse.wst.css.core.internal.provisional.document.ICSSModel) CSSStyleSheet(org.w3c.dom.css.CSSStyleSheet) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) CSSStyleDeclaration(org.w3c.dom.css.CSSStyleDeclaration) CSSRuleList(org.w3c.dom.css.CSSRuleList)

Example 4 with CSSValue

use of org.w3c.dom.css.CSSValue in project webtools.sourceediting by eclipse.

the class CSSPageRuleTest method testInsertText5.

public void testInsertText5() throws IOException {
    ICSSModel model = getModel();
    IStructuredDocument structuredDocument = model.getStructuredDocument();
    structuredDocument.set(FileUtil.createString("src/org/eclipse/wst/css/core/tests/testfiles", "CSSPageRuleTest.css"));
    CSSStyleSheet sheet = (CSSStyleSheet) model.getDocument();
    CSSRuleList ruleList = sheet.getCssRules();
    assertEquals(6, ruleList.getLength());
    CSSRule rule;
    CSSStyleDeclaration declaration;
    CSSValue value;
    CSSValueList valueList;
    // rule 5
    rule = ruleList.item(4);
    assertEquals(CSSRule.PAGE_RULE, rule.getType());
    assertTrue(rule instanceof CSSPageRule);
    assertEquals("narrow", ((CSSPageRule) rule).getSelectorText());
    declaration = ((CSSPageRule) rule).getStyle();
    assertEquals(1, declaration.getLength());
    value = declaration.getPropertyCSSValue("size");
    assertTrue(value instanceof CSSValueList);
    valueList = (CSSValueList) value;
    assertEquals(2, valueList.getLength());
    checkPrimitiveNumber(valueList.item(0), new PrimitiveNumber(CSSPrimitiveValue.CSS_CM, 9));
    checkPrimitiveNumber(valueList.item(1), new PrimitiveNumber(CSSPrimitiveValue.CSS_CM, 18));
}
Also used : CSSPageRule(org.w3c.dom.css.CSSPageRule) CSSValue(org.w3c.dom.css.CSSValue) CSSValueList(org.w3c.dom.css.CSSValueList) CSSRule(org.w3c.dom.css.CSSRule) ICSSModel(org.eclipse.wst.css.core.internal.provisional.document.ICSSModel) CSSStyleSheet(org.w3c.dom.css.CSSStyleSheet) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) CSSStyleDeclaration(org.w3c.dom.css.CSSStyleDeclaration) CSSRuleList(org.w3c.dom.css.CSSRuleList)

Example 5 with CSSValue

use of org.w3c.dom.css.CSSValue in project webtools.sourceediting by eclipse.

the class CSSFontFaceRuleTest method _testInsertText1.

public void _testInsertText1() throws IOException {
    ICSSModel model = getModel();
    IStructuredDocument structuredDocument = model.getStructuredDocument();
    structuredDocument.set(FileUtil.createString("src/org/eclipse/wst/css/core/tests/testfiles", "CSSFontFaceRuleTest.css"));
    CSSStyleSheet sheet = (CSSStyleSheet) model.getDocument();
    CSSRuleList ruleList = sheet.getCssRules();
    assertEquals(3, ruleList.getLength());
    CSSRule rule;
    CSSStyleDeclaration declaration;
    CSSValue value;
    CSSValueList valueList;
    // rule 1
    rule = ruleList.item(0);
    assertEquals(CSSRule.FONT_FACE_RULE, rule.getType());
    assertTrue(rule instanceof CSSFontFaceRule);
    declaration = ((CSSFontFaceRule) rule).getStyle();
    assertEquals(4, declaration.getLength());
    value = declaration.getPropertyCSSValue("font-family");
    checkPrimitiveString(value, new PrimitiveString(CSSPrimitiveValue.CSS_STRING, "Swiss 721"));
    value = declaration.getPropertyCSSValue("src");
    checkPrimitiveString(value, new PrimitiveString(CSSPrimitiveValue.CSS_URI, "swiss721blk.pfr"));
    value = declaration.getPropertyCSSValue("font-style");
    assertTrue(value instanceof CSSValueList);
    valueList = (CSSValueList) value;
    assertEquals(3, valueList.getLength());
    checkPrimitiveString(valueList.item(0), new PrimitiveString(CSSPrimitiveValue.CSS_IDENT, "normal"));
    checkPrimitiveString(valueList.item(1), new PrimitiveString(ICSSPrimitiveValue.CSS_COMMA, ","));
    checkPrimitiveString(valueList.item(2), new PrimitiveString(CSSPrimitiveValue.CSS_IDENT, "italic"));
    value = declaration.getPropertyCSSValue("font-weight");
    assertTrue(value instanceof CSSValueList);
    valueList = (CSSValueList) value;
    assertEquals(3, valueList.getLength());
    checkPrimitiveNumber(valueList.item(0), new PrimitiveNumber(ICSSPrimitiveValue.CSS_INTEGER, 800));
    checkPrimitiveString(valueList.item(1), new PrimitiveString(ICSSPrimitiveValue.CSS_COMMA, ","));
    checkPrimitiveNumber(valueList.item(2), new PrimitiveNumber(ICSSPrimitiveValue.CSS_INTEGER, 900));
}
Also used : CSSValue(org.w3c.dom.css.CSSValue) CSSValueList(org.w3c.dom.css.CSSValueList) CSSRule(org.w3c.dom.css.CSSRule) ICSSModel(org.eclipse.wst.css.core.internal.provisional.document.ICSSModel) CSSStyleSheet(org.w3c.dom.css.CSSStyleSheet) CSSFontFaceRule(org.w3c.dom.css.CSSFontFaceRule) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) CSSStyleDeclaration(org.w3c.dom.css.CSSStyleDeclaration) CSSRuleList(org.w3c.dom.css.CSSRuleList)

Aggregations

CSSValue (org.w3c.dom.css.CSSValue)19 CSSRule (org.w3c.dom.css.CSSRule)15 CSSRuleList (org.w3c.dom.css.CSSRuleList)15 CSSStyleDeclaration (org.w3c.dom.css.CSSStyleDeclaration)15 CSSStyleSheet (org.w3c.dom.css.CSSStyleSheet)15 ICSSModel (org.eclipse.wst.css.core.internal.provisional.document.ICSSModel)14 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)14 CSSValueList (org.w3c.dom.css.CSSValueList)7 CSSPageRule (org.w3c.dom.css.CSSPageRule)6 CSSStyleRule (org.w3c.dom.css.CSSStyleRule)5 CSSFontFaceRule (org.w3c.dom.css.CSSFontFaceRule)4 ICSSValue (org.eclipse.wst.css.core.internal.provisional.document.ICSSValue)3 CSSPrimitiveValue (org.w3c.dom.css.CSSPrimitiveValue)3 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 List (java.util.List)1 CSSStylableElement (org.eclipse.e4.ui.css.core.dom.CSSStylableElement)1 Gradient (org.eclipse.e4.ui.css.core.dom.properties.Gradient)1 CSS2FontProperties (org.eclipse.e4.ui.css.core.dom.properties.css2.CSS2FontProperties)1 CSSElementContext (org.eclipse.e4.ui.css.core.engine.CSSElementContext)1