Skip to content

Commit

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

fix problems on column suppresion, undo/redo, and saves
  • Loading branch information
ValentinMgt authored May 24, 2023
2 parents e3c2c60 + ed79b88 commit 7670c75
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import javafx.scene.control.ButtonType;
import javafx.stage.WindowEvent;
import javafx.scene.control.ButtonBar.ButtonData;
import utils.GlobalVariables;

import java.util.Optional;
import java.util.UUID;
Expand Down Expand Up @@ -37,9 +38,14 @@ public Void execute() {
String currentTitle = upmtApp.getPrimaryStage().getTitle();
UUID currentCommandId = HistoryManager.getCurrentCommandId();
UUID lastSavedCommandId = upmtApp.getLastSavedCommandId();
if(currentCommandId != null ){
if (GlobalVariables.getGlobalVariables().getComparisonState()) {
GlobalVariables.getGlobalVariables().setId(currentCommandId);
}
if(currentCommandId != null){
if(lastSavedCommandId == null){
workUnsaved = true;
if (!(currentCommandId.equals(GlobalVariables.getGlobalVariables().getId()))) {
workUnsaved = true;
}
}else {
if (HistoryManager.getCurrentCommandId().equals(lastSavedCommandId)) {
System.out.println("Projet sauvegardé");
Expand All @@ -62,6 +68,7 @@ public Void execute() {
alert.getButtonTypes().setAll(buttonTypeOne, buttonTypeTwo, buttonTypeCancel);

Optional<ButtonType> result = alert.showAndWait();

if (result.get() == buttonTypeOne){
// ... user chose "Save And Quit"
appCommandFactory.saveProject().execute();
Expand Down
9 changes: 8 additions & 1 deletion src/main/java/components/comparison/ComparisonView.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
package components.comparison;

import application.appCommands.ApplicationCommand;
import application.appCommands.ApplicationCommandFactory;
import application.configuration.Configuration;
import application.history.HistoryManager;
import components.comparison.controllers.ComparisonTableController;
import javafx.application.Application;
import javafx.collections.ObservableList;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
import utils.GlobalVariables;

import java.io.IOException;
import java.util.Objects;
import java.util.UUID;

public class ComparisonView extends Application {

private final ObservableList<String> selectionInterviews;
private final UUID startingId = HistoryManager.getCurrentCommandId(); //save the current command id

public ComparisonView(ObservableList<String> selectionInterviews){
this.selectionInterviews = selectionInterviews;
Expand All @@ -29,7 +35,8 @@ public void start(Stage stage) throws IOException {
Scene scene = new Scene(root);
root.getStylesheets().add(Objects.requireNonNull(getClass().getResource("/css/application.css")).toExternalForm());
stage.setScene(scene);

GlobalVariables.getGlobalVariables().setComparisonState(true);
GlobalVariables.getGlobalVariables().setId(startingId);
stage.show();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,27 @@ public DelColumnCommand(int columnIndex, TableView<List<StringProperty>> tv, Lis
}
@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 (tv.getColumns().get(idx).getText().equals(" ")) {
tv.getColumns().remove(idx);
List<Boolean> easy_balance = new ArrayList<>();
//check if the last column of other tables is empty
//if so,
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);
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);
}
}
}
}
Expand All @@ -52,7 +54,6 @@ public Void execute() {
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 @@ -28,7 +28,7 @@
import persistency.newSaveSystem.SMoment;

//import javax.swing.event.ChangeListener;
import java.beans.EventHandler;
import java.awt.event.KeyEvent;
import java.io.File;
import java.io.IOException;
import java.net.URL;
Expand All @@ -40,17 +40,14 @@
public class ComparisonTableController implements Initializable {

private @FXML VBox table;
public @FXML MenuItem undo;
public @FXML MenuItem redo;
private ComparisonTable comparisonTable;
private ObservableList<String> selectionInterviews;
private final ObservableList<String> selectionInterviews;

private ArrayList<Double> columnsWidth = new ArrayList<>();
private Stage comparisonStage;

public ComparisonTableController(ObservableList<String> selectionInterviews) {
this.table = new VBox();
this.selectionInterviews = selectionInterviews;
initialize(null, null);
}

public void undo() {
HistoryManager.goBack();
Expand All @@ -60,23 +57,39 @@ public void redo() {
HistoryManager.goForward();
}


public ComparisonTableController(ObservableList<String> selectionInterviews) {
this.table = new VBox();
this.selectionInterviews = selectionInterviews;
initialize(null, null);
}


@Override
public void initialize(URL url, ResourceBundle resourceBundle) {
final KeyCodeCombination keyCombUNDO = new KeyCodeCombination(KeyCode.Z, KeyCombination.SHORTCUT_DOWN);
final KeyCodeCombination keyCombREDO = new KeyCodeCombination(KeyCode.Y, KeyCombination.SHORTCUT_DOWN);
//set the undo method to the undo keyCombination
table.setOnKeyPressed(event -> {
if (keyCombUNDO.match(event)) {
undo();
}
if (keyCombREDO.match(event)) {
redo();
}
});

fillTable(this.selectionInterviews);
Platform.runLater(() -> {
//bindUndoRedoButtons(false);
bindScroll();
setColumnsSizesToBiggest();
//bindUndoRedoButtons(true);

//set the undo method to the undo keyCombination
this.undo.setAccelerator(keyCombUNDO);
redo.setAccelerator(keyCombREDO);
});

this.table.setOnKeyPressed(event -> {
if (keyCombUNDO.match(event)) {
undo();
event.consume(); // Prevent the event from being processed further
} else if (keyCombREDO.match(event)) {
redo();
event.consume(); // Prevent the event from being processed further
}
});

}
Expand Down Expand Up @@ -229,18 +242,13 @@ public void setContextMenu(TableView<List<StringProperty>> tv, int columnIndex,

contextMenu.show(tv, event.getScreenX(), event.getScreenY());
}
public void setListener(TableView<List<StringProperty>> tv) {// Create the pop-up menu
public void setListener(TableView<List<StringProperty>> tv) {// Create the pop-up menu on right click
// Set the pop-up menu to show on a right-click event on the table header
for (TableColumn<?, ?> column : tv.getColumns()) {
column.setGraphic(new Label(column.getText()));
column.setContextMenu(new ContextMenu());
column.getGraphic().setOnContextMenuRequested(event -> {
int columnIndex = tv.getColumns().indexOf(column);
setContextMenu(tv, columnIndex, event);
});
setColListener((TableColumn<List<StringProperty>, StringProperty>) column);
}
}
public void setListener(TableColumn<List<StringProperty>, StringProperty> tc){
public void setColListener(TableColumn<List<StringProperty>, StringProperty> tc){
tc.setGraphic(new Label(tc.getText()));
tc.setContextMenu(new ContextMenu());
tc.getGraphic().setOnContextMenuRequested(event -> {
Expand All @@ -253,10 +261,10 @@ public void addColumn(int idx, TableView<List<StringProperty>> tv){
// Handle "Add Column After" action here
AddColumnCommand addColumnCommand = new AddColumnCommand(idx, tv, getTables());
HistoryManager.addCommand(addColumnCommand, true);
setListener((TableColumn<List<StringProperty>, StringProperty>) tv.getColumns().get(idx));
setColListener((TableColumn<List<StringProperty>, StringProperty>) tv.getColumns().get(idx));
for (TableView<List<StringProperty>> tableView : getTables()){
if (tableView != tv){
setListener((TableColumn<List<StringProperty>, StringProperty>) tv.getColumns().get(tv.getColumns().size() - 1));
setColListener((TableColumn<List<StringProperty>, StringProperty>) tv.getColumns().get(tv.getColumns().size() - 1));
}
}
setColumnsSizesToBiggest();
Expand All @@ -278,7 +286,7 @@ public void completeTable(TableView<List<StringProperty>> tv, int length){
for (int i = 0; i < length - actualLength; i++){
TableColumn<List<StringProperty>, StringProperty> tc = new TableColumn<>(" ");
tv.getColumns().add(tc);
setListener(tc);
setColListener(tc);
}
}
}
Expand Down Expand Up @@ -425,5 +433,4 @@ public void exportToExcel(){
ExcelExporter.exportToExcel(containerData, saveFile.getAbsolutePath());
}
}

}
20 changes: 18 additions & 2 deletions src/main/java/utils/GlobalVariables.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package utils;

import application.UPMTApp;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.value.ObservableObjectValue;
import javafx.scene.Node;
import models.*;

import java.util.HashMap;
import java.util.HashSet;
import java.util.UUID;
import java.util.function.BiFunction;

public class GlobalVariables {
Expand All @@ -26,6 +26,8 @@ public class GlobalVariables {
public static NodeView nodeViews = new NodeView();
public static ModelisationNavigator modelisationNavigator;
public SimpleBooleanProperty isMomentSearchClicked;
public boolean isComparisonViewOn = false;
public UUID lastCommandIdWhenStartComparisonView = null;

private GlobalVariables() {
this.isMomentSearchClicked = new SimpleBooleanProperty(false);
Expand Down Expand Up @@ -55,6 +57,13 @@ public static RootMoment getRootMoment() {
return rootMoment;
}

public void setId(UUID id) {
this.lastCommandIdWhenStartComparisonView = id;
}
public UUID getId() {
return lastCommandIdWhenStartComparisonView;
}

public void setDescriptemeChanged(Descripteme descripteme) {
changedDescripteme.set(descripteme);
}
Expand All @@ -73,6 +82,13 @@ public void setProject(Project project) {
public String getCurrentProjectPath() {
return currentProjectPath;
}
public boolean getComparisonState(){
return isComparisonViewOn;
}

public void setComparisonState(boolean state){
isComparisonViewOn = state;
}

public static void setCurrentProjectPath(String currentProjectPath) {
globalVariables.currentProjectPath = currentProjectPath;
Expand Down
17 changes: 9 additions & 8 deletions src/main/resources/views/Comparison/ComparisonView.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,18 @@


<VBox fx:id="table" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" >
<MenuBar BorderPane.alignment="CENTER">
<Menu mnemonicParsing="false" text="%file">
<MenuItem fx:id="excelExportButton" mnemonicParsing="false" onAction="#exportToExcel" text="%export_to_excel"/>
</Menu>
<Menu mnemonicParsing="false" text="%edit">
<MenuItem fx:id="undo" mnemonicParsing="false" onAction="#undo" text="%undo"/>
<MenuItem fx:id="redo" mnemonicParsing="false" onAction="#redo" text="%redo"/>
</Menu>
</MenuBar>
<padding>
<Insets bottom="20.0" />
</padding>
<Button id="ExcelExport" fx:id="excelExportButton" mnemonicParsing="false" onAction="#exportToExcel" prefHeight="27.0" prefWidth="98.0" styleClass="button-gray" text="%export">
<font>
<Font size="18.0" />
</font>
<HBox.margin>
<Insets bottom="20.0" />
</HBox.margin>
</Button>
</VBox>


Expand Down

0 comments on commit 7670c75

Please sign in to comment.