Class NatTableCSSHelper


  • public final class NatTableCSSHelper
    extends Object
    Helper class for converting and applying CSS styles.
    • Method Detail

      • getBoolean

        public static boolean getBoolean​(CSSValue value,
                                         boolean defaultValue)
        Return the boolean value that represents the given CSSValue.
        Parameters:
        value - The value for which the boolean value should be returned.
        defaultValue - The default value to return if the given value can not be converted to a boolean.
        Returns:
        The boolean representation of the given value or the default value if it can not be converted.
      • getDisplayMode

        public static DisplayMode getDisplayMode​(String pseudo)
        Returns the NatTable DisplayMode for the given pseudo class.
        Parameters:
        pseudo - The pseudo class.
        Returns:
        The DisplayMode value for the given pseudo class.
        Since:
        2.0
      • getCellEdgeEnum

        public static CellEdgeEnum getCellEdgeEnum​(String value)
        Returns the NatTable CellEdgeEnum for the given string representation.
        Parameters:
        value - The string representation of the CellEdgeEnum
        Returns:
        The CellEdgeEnum for the string representation.
      • getDisplayConverter

        public static IDisplayConverter getDisplayConverter​(String value,
                                                            boolean format,
                                                            Integer minFractionDigits,
                                                            Integer maxFractionDigits,
                                                            String datePattern)
        Returns the NatTable IDisplayConverter for the given string representation.
        Parameters:
        value - The string representation of the IDisplayConverter
        format - flag for number display converters to specify whether NumberFormat should be used to format or not.
        minFractionDigits - number of minimum fraction digits to use in case a NumberFormat is used for formatting a number value
        maxFractionDigits - number of maximum fraction digits to use in case a NumberFormat is used for formatting a number value
        datePattern - The pattern to use for formatting a date value when a date display converter requested
        Returns:
        The IDisplayConverter for the string representation.
      • isConverterString

        public static boolean isConverterString​(String value)
        Parameters:
        value - The value to check.
        Returns:
        true if the given value represents a valid converter key, false if not.
      • getNatTableStyle

        public static <T> T getNatTableStyle​(NatTable natTable,
                                             ConfigAttribute<T> styleConfig,
                                             DisplayMode displayMode,
                                             String... configLabels)
        Retrieves the style attribute for the given display mode and config labels out of the NatTable configuration. Uses the NatTable internal inheritance model to always retrieve a style configuration attribute if there is one configured at any level.
        Type Parameters:
        T - The type of the configuration attribute.
        Parameters:
        natTable - The NatTable whose ConfigRegistry should be checked for the style configuration.
        styleConfig - The style ConfigAttribute that is requested.
        displayMode - The DisplayMode for which the configuration is requested.
        configLabels - The config labels for which the configuration is requested.
        Returns:
        The style attribute for the given display mode and config labels out of the NatTable configuration.
        Since:
        2.0
      • applyNatTableStyle

        public static <T> void applyNatTableStyle​(NatTable natTable,
                                                  ConfigAttribute<T> styleConfig,
                                                  T value,
                                                  DisplayMode displayMode,
                                                  String configLabel)
        Apply a style attribute value for the IStyle registered for CellConfigAttributes.CELL_STYLE.
        Type Parameters:
        T - The type of the configuration attribute.
        Parameters:
        natTable - The NatTable to apply the style configuration to.
        styleConfig - The style ConfigAttribute that should be applied.
        value - The value to apply.
        displayMode - The DisplayMode for which the configuration should be applied.
        configLabel - The label for which the configuration should be applied.
        Since:
        2.0
      • applyNatTableStyle

        public static <T> void applyNatTableStyle​(NatTable natTable,
                                                  ConfigAttribute<IStyle> styleAttribute,
                                                  ConfigAttribute<T> styleConfig,
                                                  T value,
                                                  DisplayMode displayMode,
                                                  String configLabel)
        Apply a style attribute value for the IStyle registered for the given styleAttribute.
        Type Parameters:
        T - The type of the configuration attribute.
        Parameters:
        natTable - The NatTable to apply the style configuration to.
        styleAttribute - The ConfigAttribute that points to the IStyle that should be configured.
        styleConfig - The style ConfigAttribute that should be applied.
        value - The value to apply.
        displayMode - The DisplayMode for which the configuration should be applied.
        configLabel - The label for which the configuration should be applied.
        Since:
        2.0
      • getFontProperties

        public static org.eclipse.e4.ui.css.core.dom.properties.css2.CSS2FontProperties getFontProperties​(org.eclipse.e4.ui.css.core.engine.CSSElementContext context,
                                                                                                          String contextKey,
                                                                                                          NatTable natTable,
                                                                                                          DisplayMode displayMode,
                                                                                                          String label)
        Returns the CSS2FontProperties out of the given CSSElementContext for the given parameters. If no CSS2FontProperties exist, a new instance will be created and pre-filled with font values based on inheritance.
        Parameters:
        context - The CSSElementContext to search for the context value.
        contextKey - The context key under which the font properties are stored.
        natTable - The NatTable instance to apply the styles to
        displayMode - The target DisplayMode to check for the value.
        label - The label for which the font properties are requested.
        Returns:
        The CSS2FontProperties for the given attributes.
        Since:
        2.0
      • setFontProperties

        public static void setFontProperties​(CSSValueList valueList,
                                             org.eclipse.e4.ui.css.core.dom.properties.css2.CSS2FontProperties font)
        Sets the values from the given CSSValueList to the given CSS2FontPropertiesCSS2FontProperties.
        Parameters:
        valueList - The value list containing the css property values
        font - The font properties to set the values to
      • getBorderStyle

        public static BorderStyle getBorderStyle​(org.eclipse.e4.ui.css.core.engine.CSSElementContext context,
                                                 DisplayMode displayMode)
        Returns the BorderStyle out of the given CSSElementContext for the given DisplayMode.
        Parameters:
        context - The CSSElementContext to search for the context value.
        displayMode - The DisplayMode for which the value should be stored.
        Returns:
        The BorderStyle
        Since:
        2.0
      • storeBorderStyle

        public static void storeBorderStyle​(CSSValueList valueList,
                                            BorderStyle borderStyle,
                                            org.eclipse.e4.ui.css.core.engine.CSSEngine engine,
                                            org.eclipse.swt.widgets.Display display)
                                     throws Exception
        Convert and store the values of the given CSSValueList to the given BorderStyle.
        Parameters:
        valueList - The CSSValueList with the values to convert.
        borderStyle - The BorderStyle to store the converted values to.
        engine - The CSSEngine needed for conversion.
        display - The display needed for color conversion.
        Throws:
        Exception - if the value conversion fails
      • storePadding

        public static void storePadding​(String paddingKey,
                                        CSSValue value,
                                        org.eclipse.e4.ui.css.core.engine.CSSElementContext context,
                                        DisplayMode displayMode)
        Convert and store the padding value for the given key in the painter properties map.
        Parameters:
        paddingKey - The key of the padding property.
        value - The CSSValue of the padding that should be converted and stored.
        context - The CSSElementContext to search for the configuration value.
        displayMode - The target DisplayMode to check for the value.
        Since:
        2.0
      • resolvePainter

        public static boolean resolvePainter​(org.eclipse.e4.ui.css.core.engine.CSSElementContext context,
                                             org.eclipse.e4.ui.css.core.engine.CSSElementContext natTableContext,
                                             DisplayMode displayMode)
        Check if the automatic painter resolution is enabled or disabled via CSS property.
        Parameters:
        context - The CSSElementContext to search for the configuration value.
        natTableContext - The CSSElementContext of the parent NatTable or null in case the context parameter is already from the NatTable itself.
        displayMode - The target DisplayMode to check for the value.
        Returns:
        true if the painter to use should be automatically resolved, false if the painter is configured elsewhere and therefore no automatic resolution should be performed. Default is true.
        Since:
        2.0
      • getDecoratorPainter

        public static List<String> getDecoratorPainter​(org.eclipse.e4.ui.css.core.engine.CSSElementContext context,
                                                       DisplayMode displayMode)
        Returns the string representation list of cell painter decorators that should be used to build up the cell painter for rendering.
        Parameters:
        context - The CSSElementContext to search for the context value.
        displayMode - The DisplayMode for which the value should be stored.
        Returns:
        The string representation of decorator painter that should be used for rendering.
        Since:
        2.0
      • getPainterProperties

        public static Map<String,​Object> getPainterProperties​(org.eclipse.e4.ui.css.core.engine.CSSElementContext context,
                                                                    DisplayMode displayMode)
        Returns the painter properties out of the given CSSElementContext for the given DisplayMode.
        Parameters:
        context - The CSSElementContext to search for the context value.
        displayMode - The DisplayMode for which the value should be stored.
        Returns:
        The properties that should be used to create content painter.
        Since:
        2.0
      • getPainterPropertiesInherited

        public static Map<String,​Object> getPainterPropertiesInherited​(org.eclipse.e4.ui.css.core.engine.CSSElementContext context,
                                                                             org.eclipse.e4.ui.css.core.engine.CSSElementContext natTableContext,
                                                                             DisplayMode targetDisplayMode)
        Returns the painter properties out of the given CSSElementContext for the given DisplayMode enriched with the painter property values out of inheritance.
        Parameters:
        context - The CSSElementContext to search for the context value.
        natTableContext - The CSSElementContext of the parent NatTable or null in case the context parameter is already from the NatTable itself.
        targetDisplayMode - The target DisplayMode to check for the value.
        Returns:
        The painter properties with values out of inheritance
        Since:
        2.0
      • resolvePainterRepresentation

        public static List<String> resolvePainterRepresentation​(CSSValue value)
        Resolves the painter representations out of the given CSSValue.
        Parameters:
        value - The CSSValue to resolve.
        Returns:
        The list of string representations for painters.
      • storeContextValue

        public static void storeContextValue​(org.eclipse.e4.ui.css.core.engine.CSSElementContext context,
                                             DisplayMode displayMode,
                                             Object key,
                                             Object value)
        Put a value for the given key and DisplayMode to the given CSSElementContext.
        Parameters:
        context - The CSSElementContext to put the value to.
        displayMode - The DisplayMode for which the value should be stored.
        key - The key for which the value should be stored.
        value - The value to store.
        Since:
        2.0
      • getContextValue

        public static Object getContextValue​(org.eclipse.e4.ui.css.core.engine.CSSElementContext context,
                                             DisplayMode displayMode,
                                             Object key)
        Search the value for the given key and DisplayMode out of the given CSSElementContext.
        Parameters:
        context - The CSSElementContext out of which the value should be retrieved.
        displayMode - The DisplayMode for which the value is requested.
        key - The key for which the value is requested.
        Returns:
        The value for the given DisplayMode and key out of the given CSSElementContext. If no value is found for the given DisplayMode, the value out of the given CSSElementContext directly is returned. Can be null.
        Since:
        2.0
      • getContextValueInherited

        public static Object getContextValueInherited​(org.eclipse.e4.ui.css.core.engine.CSSElementContext context,
                                                      org.eclipse.e4.ui.css.core.engine.CSSElementContext natTableContext,
                                                      DisplayMode targetDisplayMode,
                                                      Object key)
        Search the value for the given key and DisplayMode out of the given CSSElementContext. Will search for the value also via inheritance, that means first it will check the IDisplayModeOrdering and if there is no value found, it searches in the parent NatTable context.
        Parameters:
        context - The CSSElementContext to search for the context value.
        natTableContext - The CSSElementContext of the parent NatTable or null in case the context parameter is already from the NatTable itself.
        targetDisplayMode - The target DisplayMode to check for the value.
        key - The key of the context value to search for.
        Returns:
        The context value for the given key.
        Since:
        2.0