Class AttributedResult

Object
AttributedResult

public class AttributedResult extends Object
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 Details

    • AttributedResult

      public AttributedResult(Object result)
      Creates a result with no formatting attributes set.
      Parameters:
      result - The plain value the output element returns.
    • AttributedResult

      public AttributedResult(Object result, Map<String,Object> attrs)
      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

      public Object getResult()
      Returns the plain value this instance formats.
      Returns:
      The value the output element returns, without the formatting attributes.
    • getAttributes

      public Map<String,Object> getAttributes()
      Returns all formatting attributes set on this instance.
      Returns:
      An unmodifiable map of the formatting attributes, keyed by attribute name.
    • getAttribute

      public <T> T getAttribute(String name)
      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

      public <T> T setAttribute(String name, Object value)
      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

      public <T> T clearAttribute(String name)
      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

      public boolean containsAttribute(String name)
      Tells whether one formatting attribute is set on this instance.
      Parameters:
      name - The attribute name.
      Returns:
      true when an attribute with this name is set.
    • withRawCSS

      public AttributedResult withRawCSS(String css)
      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 AttributedResult instance, for convenience
      See Also:
    • withSuffix

      public AttributedResult withSuffix(String suffix)
      Sets a suffix to be appended to the result.
      Parameters:
      suffix - The text to append to the result. Pass null to fall back to the suffix configured on the logic element.
      Returns:
      the AttributedResult instance, for convenience
    • withTextColor

      public AttributedResult withTextColor(String cssColor)
      Sets the text (foreground) color.
      Parameters:
      cssColor - The CSS color, for example "white" or "#0101DF". A null or empty value is ignored, so a color already set stays.
      Returns:
      the AttributedResult instance, for convenience
      See Also:
    • withTextDecoration

      public AttributedResult withTextDecoration(String textDecoration)
      Sets the decoration to be added to the resulting text.

      Valid options are underline, line-through, and overline.

      Parameters:
      textDecoration - One of underline, line-through, or overline. Any other value is ignored, so a decoration already set stays.
      Returns:
      the AttributedResult instance, for convenience
      See Also:
    • withBackgroundColor

      public AttributedResult withBackgroundColor(String cssColor)
      Sets the background color.
      Parameters:
      cssColor - The CSS color, for example "red" or "#0101DF". A null or empty value is ignored, so a color already set stays.
      Returns:
      the AttributedResult instance, for convenience
      See Also:
    • withManualOverrideValueOptions

      public AttributedResult 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. 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 AttributedResult instance, for convenience
    • removeManualOverrideValueOptions

      public AttributedResult 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 AttributedResult instance, for convenience
    • withManualOverrideAllowEmpty

      public AttributedResult withManualOverrideAllowEmpty(Boolean allow)
      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. null is read as false.
      Returns:
      the AttributedResult instance, for convenience