-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #138 from yprie/sprint4/update-and-improve-compari…
…son-table add the undo/redo option
- Loading branch information
Showing
4 changed files
with
196 additions
and
45 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
src/main/java/components/comparison/appCommands/AddColumnCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package components.comparison.appCommands; | ||
|
||
import application.history.ModelUserActionCommand; | ||
import components.comparison.controllers.ComparisonTableController; | ||
import javafx.beans.property.StringProperty; | ||
import javafx.scene.control.TableColumn; | ||
import javafx.scene.control.TableView; | ||
import utils.command.Executable; | ||
|
||
import java.util.List; | ||
|
||
public class AddColumnCommand extends ModelUserActionCommand { | ||
private final int idx; | ||
private final TableView<List<StringProperty>> tv; | ||
private final List<TableView<List<StringProperty>>> tables; | ||
public AddColumnCommand(int columnIndex, TableView<List<StringProperty>> tv, List<TableView<List<StringProperty>>> tables) { | ||
this.idx = columnIndex; | ||
this.tv = tv; | ||
this.tables = tables; | ||
} | ||
|
||
@Override | ||
public Void execute() { | ||
TableColumn<List<StringProperty>, StringProperty> tc = new TableColumn<>(" "); | ||
tv.getColumns().add(idx, tc); | ||
tv.getColumns().get(idx).setSortable(false); | ||
for (TableView<List<StringProperty>> tableView : tables){ | ||
if (tableView != tv){ | ||
TableColumn<List<StringProperty>, StringProperty> column = new TableColumn<>(" "); | ||
tableView.getColumns().add(column); | ||
tv.getColumns().get(tv.getColumns().size() - 1).setSortable(false); | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public Object undo() { | ||
tv.getColumns().remove(idx); | ||
for (TableView<List<StringProperty>> tableView : tables){ | ||
if (tableView != tv){ | ||
tableView.getColumns().remove(tableView.getColumns().size() - 1); | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
} |
53 changes: 53 additions & 0 deletions
53
src/main/java/components/comparison/appCommands/DelColumnCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package components.comparison.appCommands; | ||
|
||
import application.history.ModelUserActionCommand; | ||
import javafx.beans.property.StringProperty; | ||
import javafx.scene.control.TableColumn; | ||
import javafx.scene.control.TableView; | ||
import utils.command.Executable; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class DelColumnCommand extends ModelUserActionCommand { | ||
private final int idx; | ||
private final TableView<List<StringProperty>> tv; | ||
private final List<TableView<List<StringProperty>>> tables; | ||
|
||
public DelColumnCommand(int columnIndex, TableView<List<StringProperty>> tv, List<TableView<List<StringProperty>>> tables) { | ||
this.idx = columnIndex; | ||
this.tv = tv; | ||
this.tables = tables; | ||
} | ||
@Override | ||
public Void execute() { | ||
tv.getColumns().remove(idx); | ||
List<Boolean> easy_balance = new ArrayList<>(); | ||
//check if the last column of other tables is empty | ||
for (TableView<?> tableView : tables){ | ||
if (tableView != tv){ | ||
if (tableView.getColumns().get(tableView.getColumns().size() - 1).getText().equals(" ")){ | ||
easy_balance.add(false); | ||
} else { | ||
easy_balance.add(true); | ||
} | ||
} | ||
} | ||
if (easy_balance.contains(true)){ | ||
tv.getColumns().add(new TableColumn<>(" ")); | ||
} | ||
else { | ||
for (TableView<?> tableView : tables){ | ||
if (tableView != tv) { | ||
tableView.getColumns().remove(tableView.getColumns().size() - 1); | ||
} | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public Object undo() { | ||
return null; | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
src/main/java/components/comparison/appCommands/MoveColumnCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package components.comparison.appCommands; | ||
|
||
import application.history.ModelUserActionCommand; | ||
import javafx.beans.property.StringProperty; | ||
import javafx.scene.control.TableColumn; | ||
import javafx.scene.control.TableView; | ||
|
||
import java.util.List; | ||
|
||
public class MoveColumnCommand extends ModelUserActionCommand { | ||
private final TableView<List<StringProperty>> tableView; | ||
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; | ||
} | ||
|
||
@Override | ||
public Object execute() { | ||
// Perform the column reordering operation | ||
TableColumn<List<StringProperty>, ?> column = tableView.getColumns().remove(fromIndex); | ||
tableView.getColumns().add(toIndex, column); | ||
|
||
return null; | ||
} | ||
|
||
@Override | ||
public Object undo() { | ||
// Undo the column reordering operation | ||
TableColumn<List<StringProperty>, ?> column = tableView.getColumns().remove(toIndex); | ||
tableView.getColumns().add(fromIndex, column); | ||
|
||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters