Class CellValueManager

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

public class CellValueManager extends Object implements Serializable
CellValueManager is an utility class of SpreadsheetClass, which handles values and formatting for individual cells.
Author:
Vaadin Ltd.
See Also:
  • Field Details

    • spreadsheet

      protected final Spreadsheet spreadsheet
      The Spreadsheet this class is tied to.
  • Constructor Details

    • CellValueManager

      public CellValueManager(Spreadsheet spreadsheet)
      Creates a new CellValueManager and ties it to the given Spreadsheet.
      Parameters:
      spreadsheet - Target Spreadsheet
  • Method Details

    • clearCachedContent

      public void clearCachedContent()
      Clears all cached data.
    • getDataFormatter

      public org.apache.poi.ss.usermodel.DataFormatter getDataFormatter()
    • setDataFormatter

      public void setDataFormatter(org.apache.poi.ss.usermodel.DataFormatter dataFormatter)
    • getOriginalValueDecimalFormat

      public DecimalFormat getOriginalValueDecimalFormat()
    • updateLocale

      protected void updateLocale(Locale locale)
    • getFormulaEvaluator

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

      protected org.apache.poi.ss.formula.ConditionalFormattingEvaluator getConditionalFormattingEvaluator()
      Returns:
      the common ConditionalFormattingEvaluator instance from Spreadsheet
    • createCellDataForCell

      protected CellData createCellDataForCell(org.apache.poi.ss.usermodel.Cell cell)
    • getOriginalCellValue

      public String getOriginalCellValue(org.apache.poi.ss.usermodel.Cell cell)
    • getCellWidth

      protected int getCellWidth(org.apache.poi.ss.usermodel.Cell cell)
      Calculate cell width, accounting for merged cells (see #655)
      Parameters:
      cell -
      Returns:
      cell width, including widths of any merged columns
    • getCustomCellValueHandler

      public Spreadsheet.CellValueHandler getCustomCellValueHandler()
      Gets the current CellValueHandler
      Returns:
      the customCellValueHandler
    • setCustomCellValueHandler

      public void setCustomCellValueHandler(Spreadsheet.CellValueHandler customCellValueHandler)
      Sets the current CellValueHandler
      Parameters:
      customCellValueHandler - the customCellValueHandler to set
    • getCustomCellDeletionHandler

      public Spreadsheet.CellDeletionHandler getCustomCellDeletionHandler()
      Gets the current CellDeletionHandler
      Returns:
      the customCellDeletionHandler
    • setCustomCellDeletionHandler

      public void setCustomCellDeletionHandler(Spreadsheet.CellDeletionHandler customCellDeletionHandler)
      Sets the current CellDeletionHandler
      Parameters:
      customCellDeletionHandler - the customCellDeletionHandler to set
    • cellUpdated

      protected void cellUpdated(org.apache.poi.ss.usermodel.Cell cell)
      Notifies evaluator and marks cell for update on next call to updateMarkedCellValues()
      Parameters:
      cell - Cell to mark for updates
    • markCellForUpdate

      protected void markCellForUpdate(org.apache.poi.ss.usermodel.Cell cell)
      Marks cell for update on next call to updateMarkedCellValues()
      Parameters:
      cell - Cell to mark for updates
    • cellDeleted

      protected void cellDeleted(org.apache.poi.ss.usermodel.Cell cell)
      Marks the given cell as deleted and notifies the evaluator
      Parameters:
      cell - Deleted cell
    • markCellForRemove

      protected void markCellForRemove(org.apache.poi.ss.usermodel.Cell cell)
      Marks the given cell for removal.
      Parameters:
      cell - Cell to mark for removal
    • clearCellCache

      protected void clearCellCache(String cellKey)
      Clears the cell with the given key from the cache
      Parameters:
      cellKey - Key of target cell
    • onCellValueChange

      public void onCellValueChange(int col, int row, String value)
      Updates the cell value and type, causes a recalculation of all the values in the cell. If there is a Spreadsheet.CellValueHandler defined, then it is used. Cells starting with "=" or "+" will be created/changed into FORMULA type. Cells that are existing and are NUMERIC type will be parsed according to their existing format, or if that fails, as Double. Cells not containing any letters and containing at least one number will be created/changed into NUMERIC type (formatting is not changed). Existing Boolean cells will be parsed as Boolean. For everything else and if any of the above fail, the cell will get the STRING type and the value will just be a string, except empty values will cause the cell type to be BLANK.
      Parameters:
      col - Column index of target cell, 1-based
      row - Row index of target cell, 1-based
      value - The new value to set to the target cell, formulas will start with an extra "=" or "+"
    • onDeleteSelectedCells

      public void onDeleteSelectedCells()
      Deletes the currently selected cells' values. Does not affect styles.
    • parseValueIntoNumericCell

      protected void parseValueIntoNumericCell(org.apache.poi.ss.usermodel.Cell cell, String value)
      Attempts to parse a numeric value from the given String and set it to the given Cell.
      Parameters:
      cell - Target Cell
      value - Source for parsing the value
    • loadCellData

      protected void loadCellData(int firstRow, int firstColumn, int lastRow, int lastColumn)
      Sends cell data to the client. Only the data within the given bounds will be sent.
      Parameters:
      firstRow - Starting row index, 1-based
      firstColumn - Starting column index, 1-based
      lastRow - Ending row index, 1-based
      lastColumn - Ending column index, 1-based
    • loadCellDataForRowAndColumnRange

      protected ArrayList<CellData> loadCellDataForRowAndColumnRange(int firstRow, int firstColumn, int lastRow, int lastColumn)
      Gets cell data for cells within the given bounds.
      Parameters:
      firstRow - Starting row index, 1-based
      firstColumn - Starting column index, 1-based
      lastRow - Ending row index, 1-based
      lastColumn - Ending column index, 1-based
      Returns:
      A list of CellData for the cells in the given area.
    • updateVisibleCellValues

      protected void updateVisibleCellValues()
      Method for updating the spreadsheet client side visible cells and cached data correctly.
    • updateMarkedCellValues

      protected void updateMarkedCellValues()
      Method for updating cells that are marked for update and formula cells. Iterates over the whole sheet (existing rows and columns) and updates client side cache for all sent formula cells, and cells that have been marked for updating.
    • updateDeletedRowsInClientCache

      protected void updateDeletedRowsInClientCache(int startRow, int endRow)
      Makes sure the next Spreadsheet.updateMarkedCells() call will clear all removed rows from client cache.
      Parameters:
      startRow - Index of the starting row, 1-based
      endRow - Index of the ending row, 1-based
    • removeCells

      protected void removeCells(int firstRow, int firstColumn, int lastRow, int lastColumn, boolean clearRemovedCellStyle)
      Removes all the cells within the given bounds from the Spreadsheet and the underlying POI model.
      Parameters:
      firstRow - Starting row index, 1-based
      firstColumn - Starting column index, 1-based
      lastRow - Ending row index, 1-based
      lastColumn - Ending column index, 1-based
      clearRemovedCellStyle - true to also clear styles from the removed cells
    • removeCell

      protected void removeCell(int rowIndex, int colIndex, boolean clearRemovedCellStyle)
      Removes an individual cell from the Spreadsheet and the underlying POI model.
      Parameters:
      rowIndex - Row index of target cell, 1-based
      colIndex - Column index of target cell, 1-based
      clearRemovedCellStyle - true to also clear styles from the removed cell
    • removeHyperlink

      protected void removeHyperlink(org.apache.poi.ss.usermodel.Cell cell, org.apache.poi.ss.usermodel.Sheet sheet)
      Removes hyperlink from the given cell
      Parameters:
      cell - Target cell
      sheet - Sheet the target cell belongs to
    • onCellStyleWidthRatioUpdate

      public void onCellStyleWidthRatioUpdate(HashMap<Integer,Float> cellStyleWidthRatioMap)
      Sets the cell style width ratio map
      Parameters:
      cellStyleWidthRatioMap - New map
    • clearCacheForColumn

      public void clearCacheForColumn(int indexColumn)
      Clears data cache for the column at the given index
      Parameters:
      indexColumn - Index of target column, 1-based