From 8c1c9a8406b50b6b24f2f9231ed72e600ffc3797 Mon Sep 17 00:00:00 2001 From: Valentin Date: Wed, 17 May 2023 02:48:13 +0200 Subject: [PATCH] fix undo/redo issues --- .../components/comparison/appCommands/DelColumnCommand.java | 5 +++++ .../components/comparison/appCommands/MoveColumnCommand.java | 5 +++-- .../comparison/controllers/ComparisonTableController.java | 1 - 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main/java/components/comparison/appCommands/DelColumnCommand.java b/src/main/java/components/comparison/appCommands/DelColumnCommand.java index 5aeaf5ca..cce2c50f 100644 --- a/src/main/java/components/comparison/appCommands/DelColumnCommand.java +++ b/src/main/java/components/comparison/appCommands/DelColumnCommand.java @@ -13,11 +13,13 @@ public class DelColumnCommand extends ModelUserActionCommand { private final int idx; private final TableView> tv; private final List>> tables; + private final List, ?>> previousState; public DelColumnCommand(int columnIndex, TableView> tv, List>> tables) { this.idx = columnIndex; this.tv = tv; this.tables = tables; + this.previousState = new ArrayList<>(tv.getColumns()); } @Override public Void execute() { @@ -48,6 +50,9 @@ public Void execute() { @Override public Object undo() { + // Restaurer l'état précédent de la table en réinsérant les colonnes précédentes + tv.getColumns().setAll(previousState); + return null; } } diff --git a/src/main/java/components/comparison/appCommands/MoveColumnCommand.java b/src/main/java/components/comparison/appCommands/MoveColumnCommand.java index 59e52cda..c09c9258 100644 --- a/src/main/java/components/comparison/appCommands/MoveColumnCommand.java +++ b/src/main/java/components/comparison/appCommands/MoveColumnCommand.java @@ -9,6 +9,7 @@ public class MoveColumnCommand extends ModelUserActionCommand { private final TableView> tableView; + private final List, ?>> previousState; private final int fromIndex; private final int toIndex; @@ -16,6 +17,7 @@ public MoveColumnCommand(TableView> tableView, int fromInde this.tableView = tableView; this.fromIndex = fromIndex; this.toIndex = toIndex; + this.previousState = List.copyOf(tableView.getColumns()); } @Override @@ -30,8 +32,7 @@ public Object execute() { @Override public Object undo() { // Undo the column reordering operation - TableColumn, ?> column = tableView.getColumns().remove(toIndex); - tableView.getColumns().add(fromIndex, column); + tableView.getColumns().setAll(previousState); return null; } diff --git a/src/main/java/components/comparison/controllers/ComparisonTableController.java b/src/main/java/components/comparison/controllers/ComparisonTableController.java index 457fcbd6..61187cac 100644 --- a/src/main/java/components/comparison/controllers/ComparisonTableController.java +++ b/src/main/java/components/comparison/controllers/ComparisonTableController.java @@ -426,5 +426,4 @@ public void exportToExcel(){ } } - }