List of usage examples for org.apache.poi.ss.util CellReference equals
@Override public boolean equals(Object o)
From source file:com.adanac.excel.reader.sax.ExcelXSSFSheetXMLHandler.java
License:Apache License
/** * Do a check for, and output, comments in otherwise empty cells. * //from ww w . ja v a 2s . com * @throws BingSaxReadStopException */ private void checkForEmptyCellComments(EmptyCellCommentsCheckType type) throws BingSaxReadStopException { if (commentCellRefs != null && !commentCellRefs.isEmpty()) { // If we've reached the end of the sheet data, output any // comments we haven't yet already handled if (type == EmptyCellCommentsCheckType.END_OF_SHEET_DATA) { while (!commentCellRefs.isEmpty()) { outputEmptyCellComment(commentCellRefs.remove()); } return; } // At the end of a row, handle any comments for "missing" rows // before us if (this.cellRef == null) { if (type == EmptyCellCommentsCheckType.END_OF_ROW) { while (!commentCellRefs.isEmpty()) { if (commentCellRefs.peek().getRow() == rowNum) { outputEmptyCellComment(commentCellRefs.remove()); } else { return; } } return; } else { throw new IllegalStateException( "Cell ref should be null only if there are only empty cells in the row; rowNum: " + rowNum); } } CellReference nextCommentCellRef; do { CellReference cellRef = new CellReference(this.cellRef); CellReference peekCellRef = commentCellRefs.peek(); if (type == EmptyCellCommentsCheckType.CELL && cellRef.equals(peekCellRef)) { // remove the comment cell ref from the list if we're about // to handle it alongside the cell content commentCellRefs.remove(); return; } else { // fill in any gaps if there are empty cells with comment // mixed in with non-empty cells int comparison = cellRefComparator.compare(peekCellRef, cellRef); if (comparison > 0 && type == EmptyCellCommentsCheckType.END_OF_ROW && peekCellRef.getRow() <= rowNum) { nextCommentCellRef = commentCellRefs.remove(); outputEmptyCellComment(nextCommentCellRef); } else if (comparison < 0 && type == EmptyCellCommentsCheckType.CELL && peekCellRef.getRow() <= rowNum) { nextCommentCellRef = commentCellRefs.remove(); outputEmptyCellComment(nextCommentCellRef); } else { nextCommentCellRef = null; } } } while (nextCommentCellRef != null && !commentCellRefs.isEmpty()); } }
From source file:com.vaadin.addon.spreadsheet.CellSelectionManager.java
License:Open Source License
boolean isCellInsideSelection(int row, int column) { CellReference cellReference = new CellReference(row - 1, column - 1); boolean inside = cellReference.equals(selectedCellReference) || individualSelectedCells.contains(cellReference); if (!inside) { for (CellRangeAddress cra : cellRangeAddresses) { if (cra.isInRange(row - 1, column - 1)) { inside = true;//from ww w .j a v a 2s . c om break; } } } return inside; }
From source file:com.vaadin.addon.spreadsheet.CellSelectionManager.java
License:Open Source License
/** * Sets/adds the cell at the given coordinates as/to the current selection. * /*from w w w .j ava 2 s.c o m*/ * @param row * Row index, 1-based * @param column * Column index, 1-based * @param discardOldRangeSelection * true to discard previous selections, false to add to the * current selection */ protected void onCellSelected(int row, int column, boolean discardOldRangeSelection) { CellReference cellReference = new CellReference(row - 1, column - 1); CellReference previousCellReference = selectedCellReference; if (!cellReference.equals(previousCellReference) || discardOldRangeSelection && (!cellRangeAddresses.isEmpty() || !individualSelectedCells.isEmpty())) { handleCellSelection(row, column); selectedCellReference = cellReference; spreadsheet.loadCustomEditorOnSelectedCell(); if (discardOldRangeSelection) { cellRangeAddresses.clear(); individualSelectedCells.clear(); paintedCellRange = spreadsheet.createCorrectCellRangeAddress(row, column, row, column); } ensureClientHasSelectionData(); fireNewSelectionChangeEvent(); } }
From source file:com.vaadin.addon.spreadsheet.CellSelectionManager.java
License:Open Source License
/** * Adds the cell at the given coordinates to the current selection. * //from w w w . j a va 2s . c om * @param row * Row index, 1-based * @param column * Column index, 1-based */ protected void onCellAddToSelectionAndSelected(int row, int column) { boolean oldSelectedCellInRange = false; for (CellRangeAddress range : cellRangeAddresses) { if (range.isInRange(selectedCellReference.getRow(), selectedCellReference.getCol())) { oldSelectedCellInRange = true; break; } } boolean oldSelectedCellInIndividual = false; for (CellReference cell : individualSelectedCells) { if (cell.equals(selectedCellReference)) { // it shouldn't be there yet(!) oldSelectedCellInIndividual = true; break; } } if (!oldSelectedCellInRange && !oldSelectedCellInIndividual) { individualSelectedCells.add(selectedCellReference); } handleCellSelection(row, column); selectedCellReference = new CellReference(row - 1, column - 1); spreadsheet.loadCustomEditorOnSelectedCell(); if (individualSelectedCells.contains(selectedCellReference)) { individualSelectedCells.remove(individualSelectedCells.indexOf(selectedCellReference)); } paintedCellRange = null; ensureClientHasSelectionData(); fireNewSelectionChangeEvent(); }