Skip to content

Commit

Permalink
Merge pull request #139 from yprie/sprint4/update-and-improve-compari…
Browse files Browse the repository at this point in the history
…son-table

fix undo/redo issues
  • Loading branch information
ValentinMgt authored May 17, 2023
2 parents e561363 + 8c1c9a8 commit e3c2c60
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ public class DelColumnCommand extends ModelUserActionCommand {
private final int idx;
private final TableView<List<StringProperty>> tv;
private final List<TableView<List<StringProperty>>> tables;
private final List<TableColumn<List<StringProperty>, ?>> previousState;

public DelColumnCommand(int columnIndex, TableView<List<StringProperty>> tv, List<TableView<List<StringProperty>>> tables) {
this.idx = columnIndex;
this.tv = tv;
this.tables = tables;
this.previousState = new ArrayList<>(tv.getColumns());
}
@Override
public Void execute() {
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@

public class MoveColumnCommand extends ModelUserActionCommand {
private final TableView<List<StringProperty>> tableView;
private final List<TableColumn<List<StringProperty>, ?>> previousState;
private final int fromIndex;
private final int toIndex;

public MoveColumnCommand(TableView<List<StringProperty>> tableView, int fromIndex, int toIndex) {
this.tableView = tableView;
this.fromIndex = fromIndex;
this.toIndex = toIndex;
this.previousState = List.copyOf(tableView.getColumns());
}

@Override
Expand All @@ -30,8 +32,7 @@ public Object execute() {
@Override
public Object undo() {
// Undo the column reordering operation
TableColumn<List<StringProperty>, ?> column = tableView.getColumns().remove(toIndex);
tableView.getColumns().add(fromIndex, column);
tableView.getColumns().setAll(previousState);

return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -426,5 +426,4 @@ public void exportToExcel(){
}
}


}

0 comments on commit e3c2c60

Please sign in to comment.