Class ConditionalFormatter
java.lang.Object
com.vaadin.flow.component.spreadsheet.ConditionalFormatter
- All Implemented Interfaces:
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 -
Constructor Summary
ConstructorsConstructorDescriptionConditionalFormatter(Spreadsheet spreadsheet) Constructs a new ConditionalFormatter targeting the given Spreadsheet. -
Method Summary
Modifier and TypeMethodDescriptionvoidCreates 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.FormulaEvaluatorGet the commonFormulaEvaluatorinstance fromSpreadsheetprotected booleanmatches(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 booleanmatchesFormula(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 totrue.protected booleanmatchesValue(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 aConditionalFormattingRuleofVALUE_IStype.protected voidrunCellMatcher(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 Details
-
colorConverter
-
-
Constructor Details
-
ConditionalFormatter
Constructs a new ConditionalFormatter targeting the given Spreadsheet.- Parameters:
spreadsheet- Target spreadsheet
-
-
Method Details
-
getCellFormattingIndex
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 commonFormulaEvaluatorinstance 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 incellToIndex.- Parameters:
cf-ConditionalFormattingthat 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 against- Returns:
- Whether the given rule evaluates to
truefor 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 totrue.NOTE: Does not support HSSF files currently.
- Parameters:
cell- Cell with conditional formattingrule- 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 aConditionalFormattingRuleofVALUE_IStype. 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 cell- Returns:
- True if the given cells value matches the given
VALUE_ISrule, false otherwise
-