Class CellValueManager
java.lang.Object
com.vaadin.flow.component.spreadsheet.CellValueManager
- All Implemented Interfaces:
Serializable
CellValueManager is an utility class of SpreadsheetClass, which handles
values and formatting for individual cells.
- Author:
- Vaadin Ltd.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final SpreadsheetThe Spreadsheet this class is tied to. -
Constructor Summary
ConstructorsConstructorDescriptionCellValueManager(Spreadsheet spreadsheet) Creates a new CellValueManager and ties it to the given Spreadsheet. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidcellDeleted(org.apache.poi.ss.usermodel.Cell cell) Marks the given cell as deleted and notifies the evaluatorprotected voidcellUpdated(org.apache.poi.ss.usermodel.Cell cell) Notifies evaluator and marks cell for update on next call toupdateMarkedCellValues()voidClears all cached data.voidclearCacheForColumn(int indexColumn) Clears data cache for the column at the given indexprotected voidclearCellCache(String cellKey) Clears the cell with the given key from the cacheprotected CellDatacreateCellDataForCell(org.apache.poi.ss.usermodel.Cell cell) protected intgetCellWidth(org.apache.poi.ss.usermodel.Cell cell) Calculate cell width, accounting for merged cells (see #655)protected org.apache.poi.ss.formula.ConditionalFormattingEvaluatorGets the current CellDeletionHandlerGets the current CellValueHandlerorg.apache.poi.ss.usermodel.DataFormatterprotected org.apache.poi.ss.usermodel.FormulaEvaluatorGet the commonFormulaEvaluatorinstance fromSpreadsheetgetOriginalCellValue(org.apache.poi.ss.usermodel.Cell cell) protected voidloadCellData(int firstRow, int firstColumn, int lastRow, int lastColumn) Sends cell data to the client.loadCellDataForRowAndColumnRange(int firstRow, int firstColumn, int lastRow, int lastColumn) Gets cell data for cells within the given bounds.protected voidmarkCellForRemove(org.apache.poi.ss.usermodel.Cell cell) Marks the given cell for removal.protected voidmarkCellForUpdate(org.apache.poi.ss.usermodel.Cell cell) Marks cell for update on next call toupdateMarkedCellValues()voidonCellStyleWidthRatioUpdate(HashMap<Integer, Float> cellStyleWidthRatioMap) Sets the cell style width ratio mapvoidonCellValueChange(int col, int row, String value) Updates the cell value and type, causes a recalculation of all the values in the cell.voidDeletes the currently selected cells' values.protected voidparseValueIntoNumericCell(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.protected voidremoveCell(int rowIndex, int colIndex, boolean clearRemovedCellStyle) Removes an individual cell from the Spreadsheet and the underlying POI model.protected voidremoveCells(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.protected voidremoveHyperlink(org.apache.poi.ss.usermodel.Cell cell, org.apache.poi.ss.usermodel.Sheet sheet) Removes hyperlink from the given cellvoidsetCustomCellDeletionHandler(Spreadsheet.CellDeletionHandler customCellDeletionHandler) Sets the current CellDeletionHandlervoidsetCustomCellValueHandler(Spreadsheet.CellValueHandler customCellValueHandler) Sets the current CellValueHandlervoidsetDataFormatter(org.apache.poi.ss.usermodel.DataFormatter dataFormatter) protected voidupdateDeletedRowsInClientCache(int startRow, int endRow) Makes sure the nextSpreadsheet.updateMarkedCells()call will clear all removed rows from client cache.protected voidupdateLocale(Locale locale) protected voidMethod for updating cells that are marked for update and formula cells.protected voidMethod for updating the spreadsheet client side visible cells and cached data correctly.
-
Field Details
-
spreadsheet
The Spreadsheet this class is tied to.
-
-
Constructor Details
-
CellValueManager
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
-
updateLocale
-
getFormulaEvaluator
protected org.apache.poi.ss.usermodel.FormulaEvaluator getFormulaEvaluator()Get the commonFormulaEvaluatorinstance fromSpreadsheet -
getConditionalFormattingEvaluator
protected org.apache.poi.ss.formula.ConditionalFormattingEvaluator getConditionalFormattingEvaluator()- Returns:
- the common
ConditionalFormattingEvaluatorinstance fromSpreadsheet
-
createCellDataForCell
-
getOriginalCellValue
-
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
Gets the current CellValueHandler- Returns:
- the customCellValueHandler
-
setCustomCellValueHandler
Sets the current CellValueHandler- Parameters:
customCellValueHandler- the customCellValueHandler to set
-
getCustomCellDeletionHandler
Gets the current CellDeletionHandler- Returns:
- the customCellDeletionHandler
-
setCustomCellDeletionHandler
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 toupdateMarkedCellValues()- 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 toupdateMarkedCellValues()- 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
Clears the cell with the given key from the cache- Parameters:
cellKey- Key of target cell
-
onCellValueChange
Updates the cell value and type, causes a recalculation of all the values in the cell. If there is aSpreadsheet.CellValueHandlerdefined, 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-basedrow- Row index of target cell, 1-basedvalue- 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
Attempts to parse a numeric value from the given String and set it to the given Cell.- Parameters:
cell- Target Cellvalue- 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-basedfirstColumn- Starting column index, 1-basedlastRow- Ending row index, 1-basedlastColumn- 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-basedfirstColumn- Starting column index, 1-basedlastRow- Ending row index, 1-basedlastColumn- 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 nextSpreadsheet.updateMarkedCells()call will clear all removed rows from client cache.- Parameters:
startRow- Index of the starting row, 1-basedendRow- 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-basedfirstColumn- Starting column index, 1-basedlastRow- Ending row index, 1-basedlastColumn- Ending column index, 1-basedclearRemovedCellStyle- 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-basedcolIndex- Column index of target cell, 1-basedclearRemovedCellStyle- 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 cellsheet- Sheet the target cell belongs to
-
onCellStyleWidthRatioUpdate
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
-