Class ConditionalFormatter

java.lang.Object
com.vaadin.flow.component.spreadsheet.ConditionalFormatter
All Implemented Interfaces:
Serializable

public class ConditionalFormatter extends Object implements Serializable
ConditionalFormatter is an utility class of Spreadsheet, which handles all processing regarding Conditional Formatting rules.

Rules are parsed into CSS rules with individual class names. Class names for each cell can then be fetched from this class.

For now, only XSSF formatting rules are supported because of bugs in POI.

Author:
Thomas Mattsson / Vaadin Ltd.
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected ColorConverter
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a new ConditionalFormatter targeting the given Spreadsheet.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Creates the necessary CSS rules and runs evaluations on all affected cells.
    getCellFormattingIndex(org.apache.poi.ss.usermodel.Cell cell)
    Each cell can have multiple matching rules, hence a collection.
    protected org.apache.poi.ss.usermodel.FormulaEvaluator
    Get the common FormulaEvaluator instance from Spreadsheet
    protected boolean
    matches(org.apache.poi.ss.usermodel.Cell cell, org.apache.poi.ss.usermodel.ConditionalFormattingRule rule, int deltaColumn, int deltaRow)
    Checks if the given cell value matches the given conditional formatting rule.
    protected boolean
    matchesFormula(org.apache.poi.ss.usermodel.Cell cell, org.apache.poi.ss.usermodel.ConditionalFormattingRule rule, int deltaColumn, int deltaRow)
    Checks if the formula in the given rule evaluates to true.
    protected boolean
    matchesValue(org.apache.poi.ss.usermodel.Cell cell, org.apache.poi.ss.usermodel.ConditionalFormattingRule rule, int deltaColumn, int deltaRow)
    Checks if the given cell value matches a ConditionalFormattingRule of VALUE_IS type.
    protected void
    runCellMatcher(org.apache.poi.ss.usermodel.ConditionalFormatting cf, org.apache.poi.ss.usermodel.ConditionalFormattingRule rule, int classNameIndex)
    Goes through the cells specified in the given formatting, and checks if each rule matches.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • ConditionalFormatter

      public ConditionalFormatter(Spreadsheet spreadsheet)
      Constructs a new ConditionalFormatter targeting the given Spreadsheet.
      Parameters:
      spreadsheet - Target spreadsheet
  • Method Details

    • getCellFormattingIndex

      public Set<Integer> getCellFormattingIndex(org.apache.poi.ss.usermodel.Cell cell)
      Each cell can have multiple matching rules, hence a collection. Order doesn't matter here, CSS is applied in correct order on the client side.
      Parameters:
      cell - Target cell
      Returns:
      indexes of the rules that match this Cell (to be used in class names)
    • createConditionalFormatterRules

      public void createConditionalFormatterRules()
      Creates the necessary CSS rules and runs evaluations on all affected cells.
    • getFormulaEvaluator

      protected org.apache.poi.ss.usermodel.FormulaEvaluator getFormulaEvaluator()
      Get the common FormulaEvaluator instance from Spreadsheet
    • runCellMatcher

      protected void runCellMatcher(org.apache.poi.ss.usermodel.ConditionalFormatting cf, org.apache.poi.ss.usermodel.ConditionalFormattingRule rule, int classNameIndex)
      Goes through the cells specified in the given formatting, and checks if each rule matches. Style ids from resulting matches are put in cellToIndex.
      Parameters:
      cf - ConditionalFormatting that specifies the affected cells
      rule - The rule to be evaluated
      classNameIndex - The index of the class name that was generated for this rule, to be added to cellToIndex
    • matches

      protected boolean matches(org.apache.poi.ss.usermodel.Cell cell, org.apache.poi.ss.usermodel.ConditionalFormattingRule rule, int deltaColumn, int deltaRow)
      Checks if the given cell value matches the given conditional formatting rule.
      Parameters:
      cell - Target cell
      rule - Conditional formatting rule to check against
      Returns:
      Whether the given rule evaluates to true for the given cell.
    • matchesFormula

      protected boolean matchesFormula(org.apache.poi.ss.usermodel.Cell cell, org.apache.poi.ss.usermodel.ConditionalFormattingRule rule, int deltaColumn, int deltaRow)
      Checks if the formula in the given rule evaluates to true.

      NOTE: Does not support HSSF files currently.

      Parameters:
      cell - Cell with conditional formatting
      rule - Conditional formatting rule based on formula
      Returns:
      Formula value, if the formula is of boolean formula type Formula value != 0, if the formula is of numeric formula type and false otherwise
    • matchesValue

      protected boolean matchesValue(org.apache.poi.ss.usermodel.Cell cell, org.apache.poi.ss.usermodel.ConditionalFormattingRule rule, int deltaColumn, int deltaRow)
      Checks if the given cell value matches a ConditionalFormattingRule of VALUE_IS type. Covers all cell types and comparison operations.
      Parameters:
      cell - Target cell
      rule - Conditional formatting rule to match against.
      deltaColumn - delta (on column axis) between cell and the origin cell
      deltaRow - delta (on row axis) between cell and the origin cell
      Returns:
      True if the given cells value matches the given VALUE_IS rule, false otherwise