Skip to content

Commit

Permalink
fix: use the same cell reference constructor in order to ensure consi…
Browse files Browse the repository at this point in the history
…stency
  • Loading branch information
ugur-vaadin committed Feb 2, 2023
1 parent 31d0441 commit 245d39b
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ public void loadFixture(final Spreadsheet spreadsheet) {
}
List<String> values = new ArrayList<>(VALUES);
CellReference ref = event.getSelectedCellReference();
CellReference newRef = new CellReference(ref.getRow(),
ref.getCol());
CellReference newRef = new CellReference(
spreadsheet.getActiveSheet().getSheetName(), ref.getRow(),
ref.getCol(), false, false);
DataValidationButton popupButton = new DataValidationButton(
spreadsheet, values);
popupButton.setUp();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ public SelectionChangeEvent getLatestSelectionEvent() {
}

boolean isCellInsideSelection(int row, int column) {
CellReference cellReference = new CellReference(row - 1, column - 1);
CellReference cellReference = new CellReference(
spreadsheet.getActiveSheet().getSheetName(), row - 1,
column - 1, false, false);
boolean inside = cellReference.equals(selectedCellReference)
|| individualSelectedCells.contains(cellReference);
if (!inside) {
Expand Down Expand Up @@ -173,7 +175,9 @@ protected void reloadCurrentSelection() {
*/
protected void onCellSelected(int row, int column,
boolean discardOldRangeSelection) {
CellReference cellReference = new CellReference(row - 1, column - 1);
CellReference cellReference = new CellReference(
spreadsheet.getActiveSheet().getSheetName(), row - 1,
column - 1, false, false);
CellReference previousCellReference = selectedCellReference;
if (!cellReference.equals(previousCellReference)
|| discardOldRangeSelection && (!cellRangeAddresses.isEmpty()
Expand Down Expand Up @@ -217,8 +221,9 @@ protected void onSheetAddressChanged(String value,
region.col1 - 1, region.col2 - 1);
}
handleCellRangeSelection(cra);
selectedCellReference = new CellReference(cra.getFirstRow(),
cra.getFirstColumn());
selectedCellReference = new CellReference(
spreadsheet.getActiveSheet().getSheetName(),
cra.getFirstRow(), cra.getFirstColumn(), false, false);
paintedCellRange = cra;
cellRangeAddresses.clear();
cellRangeAddresses.add(cra);
Expand All @@ -234,8 +239,10 @@ protected void onSheetAddressChanged(String value,
.createCorrectCellRangeAddress(region.row1,
region.col1, region.row2, region.col2);
handleCellRangeSelection(cra);
selectedCellReference = new CellReference(cra.getFirstRow(),
cra.getFirstColumn());
selectedCellReference = new CellReference(
spreadsheet.getActiveSheet().getSheetName(),
cra.getFirstRow(), cra.getFirstColumn(), false,
false);
paintedCellRange = cra;
cellRangeAddresses.clear();
cellRangeAddresses.add(cra);
Expand Down Expand Up @@ -382,8 +389,9 @@ protected void handleCellRangeSelection(CellRangeAddress cra) {

protected void handleCellRangeSelection(String name, CellRangeAddress cra) {

final CellReference firstCell = new CellReference(cra.getFirstRow(),
cra.getFirstColumn());
final CellReference firstCell = new CellReference(
spreadsheet.getActiveSheet().getSheetName(), cra.getFirstRow(),
cra.getFirstColumn(), false, false);

handleCellRangeSelection(name, firstCell, cra, true);
}
Expand Down Expand Up @@ -463,8 +471,9 @@ protected void onCellRangePainted(int selectedCellRow,
cellRangeAddresses.clear();
individualSelectedCells.clear();

selectedCellReference = new CellReference(selectedCellRow - 1,
selectedCellColumn - 1);
selectedCellReference = new CellReference(
spreadsheet.getActiveSheet().getSheetName(),
selectedCellRow - 1, selectedCellColumn - 1, false, false);

CellRangeAddress cra = spreadsheet.createCorrectCellRangeAddress(row1,
col1, row2, col2);
Expand Down Expand Up @@ -507,7 +516,9 @@ protected void onCellAddToSelectionAndSelected(int row, int column) {
individualSelectedCells.add(selectedCellReference);
}
handleCellSelection(row, column);
selectedCellReference = new CellReference(row - 1, column - 1);
selectedCellReference = new CellReference(
spreadsheet.getActiveSheet().getSheetName(), row - 1,
column - 1, false, false);
spreadsheet.loadCustomEditorOnSelectedCell();
if (individualSelectedCells.contains(selectedCellReference)) {
individualSelectedCells.remove(
Expand Down Expand Up @@ -558,8 +569,9 @@ protected void onCellsAddedToRangeSelection(int row1, int col1, int row2,
*/
protected void onRowSelected(int row, int firstColumnIndex) {
handleCellSelection(row, firstColumnIndex);
selectedCellReference = new CellReference(row - 1,
firstColumnIndex - 1);
selectedCellReference = new CellReference(
spreadsheet.getActiveSheet().getSheetName(), row - 1,
firstColumnIndex - 1, false, false);
spreadsheet.loadCustomEditorOnSelectedCell();
cellRangeAddresses.clear();
individualSelectedCells.clear();
Expand Down Expand Up @@ -592,8 +604,9 @@ protected void onRowAddedToRangeSelection(int row, int firstColumnIndex) {
individualSelectedCells.add(selectedCellReference);
}
handleCellSelection(row, firstColumnIndex);
selectedCellReference = new CellReference(row - 1,
firstColumnIndex - 1);
selectedCellReference = new CellReference(
spreadsheet.getActiveSheet().getSheetName(), row - 1,
firstColumnIndex - 1, false, false);
spreadsheet.loadCustomEditorOnSelectedCell();
cellRangeAddresses.add(spreadsheet.createCorrectCellRangeAddress(row, 1,
row, spreadsheet.getColumns()));
Expand All @@ -612,8 +625,9 @@ protected void onRowAddedToRangeSelection(int row, int firstColumnIndex) {
*/
protected void onColumnSelected(int firstRowIndex, int column) {
handleCellSelection(firstRowIndex, column);
selectedCellReference = new CellReference(firstRowIndex - 1,
column - 1);
selectedCellReference = new CellReference(
spreadsheet.getActiveSheet().getSheetName(), firstRowIndex - 1,
column - 1, false, false);
spreadsheet.loadCustomEditorOnSelectedCell();
cellRangeAddresses.clear();
individualSelectedCells.clear();
Expand Down Expand Up @@ -646,8 +660,9 @@ protected void onColumnAddedToSelection(int firstRowIndex, int column) {
individualSelectedCells.add(selectedCellReference);
}
handleCellSelection(firstRowIndex, column);
selectedCellReference = new CellReference(firstRowIndex - 1,
column - 1);
selectedCellReference = new CellReference(
spreadsheet.getActiveSheet().getSheetName(), firstRowIndex - 1,
column - 1, false, false);
spreadsheet.loadCustomEditorOnSelectedCell();
cellRangeAddresses.add(spreadsheet.createCorrectCellRangeAddress(1,
column, spreadsheet.getRows(), column));
Expand Down Expand Up @@ -676,8 +691,10 @@ protected void mergedRegionAdded(CellRangeAddress region) {
handleCellAddressChange(region.getFirstRow() + 1,
region.getFirstColumn() + 1, false);
}
selectedCellReference = new CellReference(region.getFirstRow(),
region.getFirstColumn());
selectedCellReference = new CellReference(
spreadsheet.getActiveSheet().getSheetName(),
region.getFirstRow(), region.getFirstColumn(), false,
false);
fire = true;
}
for (Iterator<CellRangeAddress> i = cellRangeAddresses.iterator(); i
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,9 @@ private void fireCellValueChangeEvent(CellRangeAddress region) {
for (int x = region.getFirstColumn(); x <= region
.getLastColumn(); x++) {
for (int y = region.getFirstRow(); y <= region.getLastRow(); y++) {
cells.add(new CellReference(y, x));
cells.add(new CellReference(
spreadsheet.getActiveSheet().getSheetName(), y, x,
false, false));
}
}
spreadsheet.fireEvent(new CellValueChangeEvent(spreadsheet, cells));
Expand Down Expand Up @@ -399,8 +401,10 @@ public void onSelectionDecreasePainted(int r, int c) {
if (!SpreadsheetUtil.isCellInRange(selectedCellReference,
newPaintedCellRange)) {
selectedCellReference = new CellReference(
spreadsheet.getActiveSheet().getSheetName(),
newPaintedCellRange.getFirstRow(),
newPaintedCellRange.getFirstColumn());
newPaintedCellRange.getFirstColumn(), false,
false);
}
getCellSelectionManager().handleCellRangeSelection(
selectedCellReference, newPaintedCellRange, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,9 @@ public void onCellValueChange(int col, int row, String value) {

// capture cell value to history
CellValueCommand command = new CellValueCommand(spreadsheet);
command.captureCellValues(new CellReference(row - 1, col - 1));
command.captureCellValues(
new CellReference(spreadsheet.getActiveSheet().getSheetName(),
row - 1, col - 1, false, false));
spreadsheet.getSpreadsheetHistoryManager().addCommand(command);
boolean updateHyperlinks = false;
boolean formulaChanged = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,8 @@ void setNamedRanges(List<String> namedRanges) {
void onPopupButtonClick(int row, int column) {
PopupButton popup = sheetPopupButtons
.get(SpreadsheetUtil.relativeToAbsolute(this,
new CellReference(row - 1, column - 1)));
new CellReference(getActiveSheet().getSheetName(),
row - 1, column - 1, false, false)));
if (popup != null) {
popup.openPopup();
}
Expand All @@ -652,7 +653,8 @@ void onPopupButtonClick(int row, int column) {
void onPopupClose(int row, int column) {
PopupButton popup = sheetPopupButtons
.get(SpreadsheetUtil.relativeToAbsolute(this,
new CellReference(row - 1, column - 1)));
new CellReference(getActiveSheet().getSheetName(),
row - 1, column - 1, false, false)));

if (popup != null) {
popup.closePopup();
Expand Down Expand Up @@ -2922,7 +2924,8 @@ private void rowsMoved(int first, int last, int n) {
} else if (numberOfRowsAboveWasChanged(row, last, first)) {
int newRow = cell.getRow() + n;
int col = cell.getCol();
CellReference newCell = new CellReference(newRow, col, true,
CellReference newCell = new CellReference(
getActiveSheet().getSheetName(), newRow, col, true,
true);
pbutton.setCellReference(newCell);
updated.put(newCell, pbutton);
Expand Down Expand Up @@ -4760,7 +4763,8 @@ public void setPopup(String cellAddress, PopupButton popupButton) {
* removes the pop-up button for the target cell.
*/
public void setPopup(int row, int col, PopupButton popupButton) {
setPopup(new CellReference(row, col), popupButton);
setPopup(new CellReference(getActiveSheet().getSheetName(), row, col,
false, false), popupButton);
}

/**
Expand Down Expand Up @@ -5184,7 +5188,9 @@ private static Set<CellReference> getAllSelectedCells(

for (int x = a.getFirstColumn(); x <= a.getLastColumn(); x++) {
for (int y = a.getFirstRow(); y <= a.getLastRow(); y++) {
cells.add(new CellReference(y, x));
cells.add(new CellReference(
selectedCellReference.getSheetName(), y, x,
false, false));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,9 @@ private void fireCellValueChangeEvent(CellRangeAddress region) {
for (int x = region.getFirstColumn(); x <= region
.getLastColumn(); x++) {
for (int y = region.getFirstRow(); y <= region.getLastRow(); y++) {
cells.add(new CellReference(y, x));
cells.add(new CellReference(
spreadsheet.getActiveSheet().getSheetName(), y, x,
false, false));
}
}
fireCellValueChangeEvent(cells);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@ public CellReference getSelectedCellReference() {
.isCellInRange(selectedCellReference, paintedCellRange)) {
return selectedCellReference;
} else {
return new CellReference(paintedCellRange.getFirstRow(),
paintedCellRange.getFirstColumn());
return new CellReference(
spreadsheet.getActiveSheet().getSheetName(),
paintedCellRange.getFirstRow(),
paintedCellRange.getFirstColumn(), false, false);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ public void captureCellRangeValues(CellRangeAddress... cellRanges) {

@Override
public CellReference getSelectedCellReference() {
return new CellReference(selectedCellRow, selectedcellCol);
return new CellReference(spreadsheet.getActiveSheet().getSheetName(),
selectedCellRow, selectedcellCol, false, false);
}

@Override
Expand Down Expand Up @@ -339,13 +340,15 @@ public Set<CellReference> getChangedCells() {
for (Object o : values) {
if (o instanceof CellValue) {
CellValue cellValue = (CellValue) o;
changedCells
.add(new CellReference(cellValue.row, cellValue.col));
changedCells.add(new CellReference(
spreadsheet.getActiveSheet().getSheetName(),
cellValue.row, cellValue.col, false, false));
} else {
CellRangeValue cellRangeValue = (CellRangeValue) o;
for (int r = cellRangeValue.row1; r <= cellRangeValue.row2; r++) {
for (int c = cellRangeValue.col1; c <= cellRangeValue.col2; c++) {
changedCells.add(new CellReference(r, c));
changedCells.add(new CellReference(
getSheet().getSheetName(), r, c, false, false));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ public void execute() {

@Override
public CellReference getSelectedCellReference() {
return new CellReference(row, 0);
return new CellReference(spreadsheet.getActiveSheet().getSheetName(),
row, 0, false, false);
}

@Override
Expand Down

0 comments on commit 245d39b

Please sign in to comment.