com.vaadin.addon.spreadsheet
Class ConditionalFormatter

java.lang.Object
  extended by com.vaadin.addon.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:
Serialized Form

Field Summary
protected  ColorConverter colorConverter
           
protected  org.apache.poi.ss.usermodel.FormulaEvaluator formulaEvaluator
           
 
Constructor Summary
ConditionalFormatter(Spreadsheet spreadsheet)
          Constructs a new ConditionalFormatter targeting the given Spreasheet.
 
Method Summary
 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  boolean matches(org.apache.poi.ss.usermodel.Cell cell, org.apache.poi.ss.usermodel.ConditionalFormattingRule rule)
          Checks if the given cell value matches the given conditional formatting rule.
protected  boolean matchesFormula(org.apache.poi.ss.usermodel.ConditionalFormattingRule rule)
          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)
          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 Detail

formulaEvaluator

protected org.apache.poi.ss.usermodel.FormulaEvaluator formulaEvaluator

colorConverter

protected ColorConverter colorConverter
Constructor Detail

ConditionalFormatter

public ConditionalFormatter(Spreadsheet spreadsheet)
Constructs a new ConditionalFormatter targeting the given Spreasheet.

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 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.


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)
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.ConditionalFormattingRule rule)
Checks if the formula in the given rule evaluates to true.

NOTE: Does not support HSSF files currently.

Parameters:
rule - Conditional formatting rule to get the formula from
Returns:
True if the formula in the given rule is of boolean formula type and evaluates to true, false otherwise

matchesValue

protected boolean matchesValue(org.apache.poi.ss.usermodel.Cell cell,
                               org.apache.poi.ss.usermodel.ConditionalFormattingRule rule)
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.
Returns:
True if the given cells value matches the given VALUE_IS rule, false otherwise


Copyright © 2013-2015 Vaadin Ltd. All Rights Reserved.