Class NatTableCSSHelper
- java.lang.Object
-
- org.eclipse.nebula.widgets.nattable.extension.e4.css.NatTableCSSHelper
-
public final class NatTableCSSHelper extends Object
Helper class for converting and applying CSS styles.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> void
applyNatTableStyle(NatTable natTable, ConfigAttribute<IStyle> styleAttribute, ConfigAttribute<T> styleConfig, T value, DisplayMode displayMode, String configLabel)
Apply a style attribute value for theIStyle
registered for the given styleAttribute.static <T> void
applyNatTableStyle(NatTable natTable, ConfigAttribute<T> styleConfig, T value, DisplayMode displayMode, String configLabel)
Apply a style attribute value for theIStyle
registered forCellConfigAttributes.CELL_STYLE
.static boolean
getBoolean(CSSValue value, boolean defaultValue)
Return theboolean
value that represents the givenCSSValue
.static BorderStyle
getBorderStyle(org.eclipse.e4.ui.css.core.engine.CSSElementContext context, DisplayMode displayMode)
static CellEdgeEnum
getCellEdgeEnum(String value)
Returns the NatTableCellEdgeEnum
for the given string representation.static Object
getContextValue(org.eclipse.e4.ui.css.core.engine.CSSElementContext context, DisplayMode displayMode, Object key)
Search the value for the given key andDisplayMode
out of the givenCSSElementContext
.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 andDisplayMode
out of the givenCSSElementContext
.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.static IDisplayConverter
getDisplayConverter(String value, boolean format, Integer minFractionDigits, Integer maxFractionDigits, String datePattern)
Returns the NatTableIDisplayConverter
for the given string representation.static String
getDisplayConverterString(IDisplayConverter converter)
static DisplayMode
getDisplayMode(String pseudo)
Returns the NatTableDisplayMode
for the given pseudo class.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 theCSS2FontProperties
out of the givenCSSElementContext
for the given parameters.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.static Map<String,Object>
getPainterProperties(org.eclipse.e4.ui.css.core.engine.CSSElementContext context, DisplayMode displayMode)
Returns the painter properties out of the givenCSSElementContext
for the givenDisplayMode
.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 givenCSSElementContext
for the givenDisplayMode
enriched with the painter property values out of inheritance.static boolean
isConverterString(String value)
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.static List<String>
resolvePainterRepresentation(CSSValue value)
Resolves the painter representations out of the givenCSSValue
.static void
setFontProperties(CSSValueList valueList, org.eclipse.e4.ui.css.core.dom.properties.css2.CSS2FontProperties font)
Sets the values from the givenCSSValueList
to the givenCSS2FontProperties
CSS2FontProperties.static void
storeBorderStyle(CSSValueList valueList, BorderStyle borderStyle, org.eclipse.e4.ui.css.core.engine.CSSEngine engine, org.eclipse.swt.widgets.Display display)
Convert and store the values of the givenCSSValueList
to the givenBorderStyle
.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 andDisplayMode
to the givenCSSElementContext
.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.
-
-
-
Method Detail
-
getBoolean
public static boolean getBoolean(CSSValue value, boolean defaultValue)
Return theboolean
value that represents the givenCSSValue
.- 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 NatTableDisplayMode
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 NatTableCellEdgeEnum
for the given string representation.- Parameters:
value
- The string representation of theCellEdgeEnum
- Returns:
- The
CellEdgeEnum
for the string representation.
-
getDisplayConverter
public static IDisplayConverter getDisplayConverter(String value, boolean format, Integer minFractionDigits, Integer maxFractionDigits, String datePattern)
Returns the NatTableIDisplayConverter
for the given string representation.- Parameters:
value
- The string representation of theIDisplayConverter
format
- flag for number display converters to specify whetherNumberFormat
should be used to format or not.minFractionDigits
- number of minimum fraction digits to use in case aNumberFormat
is used for formatting a number valuemaxFractionDigits
- number of maximum fraction digits to use in case aNumberFormat
is used for formatting a number valuedatePattern
- The pattern to use for formatting a date value when a date display converter requested- Returns:
- The
IDisplayConverter
for the string representation.
-
getDisplayConverterString
public static String getDisplayConverterString(IDisplayConverter converter)
- Parameters:
converter
- TheIDisplayConverter
for which the String representation is requested.- Returns:
- The String representation for the given
IDisplayConverter
.
-
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 whoseConfigRegistry
should be checked for the style configuration.styleConfig
- The styleConfigAttribute
that is requested.displayMode
- TheDisplayMode
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 theIStyle
registered forCellConfigAttributes.CELL_STYLE
.- Type Parameters:
T
- The type of the configuration attribute.- Parameters:
natTable
- The NatTable to apply the style configuration to.styleConfig
- The styleConfigAttribute
that should be applied.value
- The value to apply.displayMode
- TheDisplayMode
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 theIStyle
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
- TheConfigAttribute
that points to theIStyle
that should be configured.styleConfig
- The styleConfigAttribute
that should be applied.value
- The value to apply.displayMode
- TheDisplayMode
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 theCSS2FontProperties
out of the givenCSSElementContext
for the given parameters. If noCSS2FontProperties
exist, a new instance will be created and pre-filled with font values based on inheritance.- Parameters:
context
- TheCSSElementContext
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 todisplayMode
- The targetDisplayMode
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 givenCSSValueList
to the givenCSS2FontProperties
CSS2FontProperties.- Parameters:
valueList
- The value list containing the css property valuesfont
- The font properties to set the values to
-
getBorderStyle
public static BorderStyle getBorderStyle(org.eclipse.e4.ui.css.core.engine.CSSElementContext context, DisplayMode displayMode)
- Parameters:
context
- TheCSSElementContext
to search for the context value.displayMode
- TheDisplayMode
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 givenCSSValueList
to the givenBorderStyle
.- Parameters:
valueList
- TheCSSValueList
with the values to convert.borderStyle
- TheBorderStyle
to store the converted values to.engine
- TheCSSEngine
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
- TheCSSValue
of the padding that should be converted and stored.context
- TheCSSElementContext
to search for the configuration value.displayMode
- The targetDisplayMode
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
- TheCSSElementContext
to search for the configuration value.natTableContext
- TheCSSElementContext
of the parent NatTable ornull
in case the context parameter is already from the NatTable itself.displayMode
- The targetDisplayMode
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 istrue
.- 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
- TheCSSElementContext
to search for the context value.displayMode
- TheDisplayMode
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 givenCSSElementContext
for the givenDisplayMode
.- Parameters:
context
- TheCSSElementContext
to search for the context value.displayMode
- TheDisplayMode
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 givenCSSElementContext
for the givenDisplayMode
enriched with the painter property values out of inheritance.- Parameters:
context
- TheCSSElementContext
to search for the context value.natTableContext
- TheCSSElementContext
of the parent NatTable ornull
in case the context parameter is already from the NatTable itself.targetDisplayMode
- The targetDisplayMode
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 givenCSSValue
.- Parameters:
value
- TheCSSValue
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 andDisplayMode
to the givenCSSElementContext
.- Parameters:
context
- TheCSSElementContext
to put the value to.displayMode
- TheDisplayMode
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 andDisplayMode
out of the givenCSSElementContext
.- Parameters:
context
- TheCSSElementContext
out of which the value should be retrieved.displayMode
- TheDisplayMode
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 givenCSSElementContext
. If no value is found for the givenDisplayMode
, the value out of the givenCSSElementContext
directly is returned. Can benull
. - 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 andDisplayMode
out of the givenCSSElementContext
. Will search for the value also via inheritance, that means first it will check theIDisplayModeOrdering
and if there is no value found, it searches in the parent NatTable context.- Parameters:
context
- TheCSSElementContext
to search for the context value.natTableContext
- TheCSSElementContext
of the parent NatTable ornull
in case the context parameter is already from the NatTable itself.targetDisplayMode
- The targetDisplayMode
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
-
-