com.vaadin.flow.component.spreadsheet.
Class ConditionalFormatter
- java.lang.Object
-
- com.vaadin.flow.component.spreadsheet.ConditionalFormatter
-
All Implemented Interfaces:
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
colorConverter
-
Constructor Summary
Constructors Constructor Description ConditionalFormatter(Spreadsheet spreadsheet)
Constructs a new ConditionalFormatter targeting the given Spreadsheet.
-
Method Summary
All Methods Modifier and Type Method Description void
createConditionalFormatterRules()
Creates the necessary CSS rules and runs evaluations on all affected cells.
Set<Integer>
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
getFormulaEvaluator()
Get the common
FormulaEvaluator
instance fromSpreadsheet
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
ofVALUE_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.
-
-
-
Field Detail
-
colorConverter
protected ColorConverter colorConverter
-
-
Constructor Detail
-
ConditionalFormatter
public ConditionalFormatter(Spreadsheet spreadsheet)
Constructs a new ConditionalFormatter targeting the given Spreadsheet.
Parameters:
spreadsheet
- Target spreadsheet
-
-
Method Detail
-
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 cellReturns:
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 fromSpreadsheet
-
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 cellsrule
- The rule to be evaluatedclassNameIndex
- The index of the class name that was generated for this rule, to be added tocellToIndex
-
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 cellrule
- Conditional formatting rule to check againstReturns:
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 formattingrule
- Conditional formatting rule based on formulaReturns:
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
ofVALUE_IS
type. Covers all cell types and comparison operations.Parameters:
cell
- Target cellrule
- Conditional formatting rule to match against.deltaColumn
- delta (on column axis) between cell and the origin celldeltaRow
- delta (on row axis) between cell and the origin cellReturns:
True if the given cells value matches the given
VALUE_IS
rule, false otherwise
-
-