Class AttributedResult
Object
AttributedResult
Provides means for output elements' formatting.
The usage is simple, instead of returning the output value, create a new AttributedResult instance like this:
api.attributedResult(plain value), customize it by calling its various methods, and return it finally.
Example:
def cost = out.MarginPct
def myOptions = ["A" , "B" , "C" ]
return api.attributedResult(cost)
.withBackgroundColor(cost < 0.30 ? "red" : "#0101DF")
.withSuffix(cost < 0.30 ? "!!!" : null)
.withTextColor(cost < 0.30 ? "white" : null)
.withTextDecoration(cost < 0.30 ? "underline" : null)
.withManualOverrideValueOptions(myOptions)
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionAttributedResult(Object result) Creates a result with no formatting attributes set.AttributedResult(Object result, Map<String, Object> attrs) Creates a result with a starting set of formatting attributes. -
Method Summary
Modifier and TypeMethodDescription<T> TclearAttribute(String name) Removes one formatting attribute.booleancontainsAttribute(String name) Tells whether one formatting attribute is set on this instance.<T> TgetAttribute(String name) Returns the value of one formatting attribute.Returns all formatting attributes set on this instance.Returns the plain value this instance formats.In case the result element is overridable, this method clears a set (list) of values defined with above withManualOverrideValueOptions method IMPORTANT NOTE: This is implemented only for Pricelists, PriceGrids and CalculationGrids.<T> TsetAttribute(String name, Object value) Sets one formatting attribute.withBackgroundColor(String cssColor) Sets the background color.In case the result element is overridable, this method defines if the selection box shows also the "empty value" option.withManualOverrideValueOptions(List<Object> options) In case the result element is overridable, this method defines a set (list) of values that the user can pick from (vs. default free-style data entry) IMPORTANT NOTE: This is meant to list a few options only.withRawCSS(String css) Adds any valid CSS style to the cell.withSuffix(String suffix) Sets a suffix to be appended to the result.withTextColor(String cssColor) Sets the text (foreground) color.withTextDecoration(String textDecoration) Sets the decoration to be added to the resulting text.
-
Constructor Details
-
AttributedResult
Creates a result with no formatting attributes set.- Parameters:
result- The plain value the output element returns.
-
AttributedResult
Creates a result with a starting set of formatting attributes.The given attributes are copied, so later changes to the map do not affect this instance.
- Parameters:
result- The plain value the output element returns.attrs- The formatting attributes to start from, keyed by attribute name.
-
-
Method Details
-
getResult
Returns the plain value this instance formats.- Returns:
- The value the output element returns, without the formatting attributes.
-
getAttributes
Returns all formatting attributes set on this instance.- Returns:
- An unmodifiable map of the formatting attributes, keyed by attribute name.
-
getAttribute
Returns the value of one formatting attribute.- Type Parameters:
T- The expected type of the attribute value.- Parameters:
name- The attribute name.- Returns:
- The attribute value, cast to the expected type.
-
setAttribute
Sets one formatting attribute.Works like
Map.put. The value previously held under this name is returned.- Type Parameters:
T- The expected type of the previous attribute value.- Parameters:
name- The attribute name.value- The attribute value.- Returns:
- The previous value held under this name, cast to the expected type.
-
clearAttribute
Removes one formatting attribute.Works like
Map.remove. The value previously held under this name is returned.- Type Parameters:
T- The expected type of the removed attribute value.- Parameters:
name- The attribute name.- Returns:
- The removed value, cast to the expected type.
-
containsAttribute
Tells whether one formatting attribute is set on this instance.- Parameters:
name- The attribute name.- Returns:
truewhen an attribute with this name is set.
-
withRawCSS
Adds any valid CSS style to the cell. Note: There is no check if the CSS is actually valid, the values are just passed through as-is- Parameters:
css- The full CSS style parameter in the form of "property:value;"- Returns:
- the
AttributedResultinstance, for convenience - See Also:
-
withSuffix
Sets a suffix to be appended to the result.- Parameters:
suffix- The text to append to the result. Passnullto fall back to the suffix configured on the logic element.- Returns:
- the
AttributedResultinstance, for convenience
-
withTextColor
Sets the text (foreground) color.- Parameters:
cssColor- The CSS color, for example"white"or"#0101DF". Anullor empty value is ignored, so a color already set stays.- Returns:
- the
AttributedResultinstance, for convenience - See Also:
-
withTextDecoration
Sets the decoration to be added to the resulting text.Valid options are
underline,line-through, andoverline.- Parameters:
textDecoration- One ofunderline,line-through, oroverline. Any other value is ignored, so a decoration already set stays.- Returns:
- the
AttributedResultinstance, for convenience - See Also:
-
withBackgroundColor
Sets the background color.- Parameters:
cssColor- The CSS color, for example"red"or"#0101DF". Anullor empty value is ignored, so a color already set stays.- Returns:
- the
AttributedResultinstance, for convenience - See Also:
-
withManualOverrideValueOptions
In case the result element is overridable, this method defines a set (list) of values that the user can pick from (vs. default free-style data entry) IMPORTANT NOTE: This is meant to list a few options only. Not a large list of choices! There is not a hard limitation here, but if this is used widely in a particular configuration and the list of options is long the browser may not be able to render it anymore and/or the data transfer speeds may suffer.- Parameters:
options- The list of valid options in the UI- Returns:
- the
AttributedResultinstance, for convenience
-
removeManualOverrideValueOptions
In case the result element is overridable, this method clears a set (list) of values defined with above withManualOverrideValueOptions method IMPORTANT NOTE: This is implemented only for Pricelists, PriceGrids and CalculationGrids.- Returns:
- the
AttributedResultinstance, for convenience
-
withManualOverrideAllowEmpty
In case the result element is overridable, this method defines if the selection box shows also the "empty value" option. Default is true- Parameters:
allow- Whether the selection box shows the "empty value" option.nullis read asfalse.- Returns:
- the
AttributedResultinstance, for convenience
-