Skip to content
This repository has been archived by the owner on Oct 13, 2021. It is now read-only.

Commit

Permalink
Merge branch 'master' into cse_pin_window
Browse files Browse the repository at this point in the history
  • Loading branch information
miovd authored Nov 5, 2018
2 parents d39dee5 + 450a6fb commit 6937de6
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 71 deletions.
28 changes: 2 additions & 26 deletions gse-app/src/main/java/com/powsybl/gse/app/ProjectPane.java
Original file line number Diff line number Diff line change
Expand Up @@ -297,15 +297,6 @@ private void dragOverEvent(DragEvent event, Object item, TreeItem<Object> treeIt
}
}

private Alert nameAlreadyExistsAlert() {
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle(RESOURCE_BUNDLE.getString("DragError"));
alert.setHeaderText(RESOURCE_BUNDLE.getString("Error"));
alert.setContentText(RESOURCE_BUNDLE.getString("DragFileExists"));
alert.showAndWait();
return alert;
}

private int getCounter() {
return counter;
}
Expand Down Expand Up @@ -357,7 +348,7 @@ private void treeItemChildrenSize(TreeItem<Object> treeItem, int compte) {
private void accepTransferDrag(ProjectFolder projectFolder, boolean s) {
success = s;
if (getCounter() >= 1) {
nameAlreadyExistsAlert();
GseAlerts.showDraggingError();
} else if (getCounter() < 1) {
ProjectNode monfichier = (ProjectNode) dragAndDropMove.getSource();
monfichier.moveTo(projectFolder);
Expand Down Expand Up @@ -555,22 +546,7 @@ private static List<ProjectFileExecutionTaskExtension> findExecutionTaskExtensio
private MenuItem createDeleteProjectNodeItem(List<? extends TreeItem<Object>> selectedTreeItems) {
MenuItem menuItem = new MenuItem(RESOURCE_BUNDLE.getString("Delete"), Glyph.createAwesomeFont('\uf1f8').size("1.1em"));
menuItem.setOnAction(event -> {
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
alert.setTitle(RESOURCE_BUNDLE.getString("ConfirmationDialog"));
String headerText;
if (selectedTreeItems.size() == 1) {
ProjectNode node = (ProjectNode) selectedTreeItems.get(0).getValue();
headerText = String.format(RESOURCE_BUNDLE.getString("FileWillBeDeleted"), node.getName());
} else if (selectedTreeItems.size() > 1) {
String names = selectedTreeItems.stream()
.map(selectedTreeItem -> selectedTreeItem.getValue().toString())
.collect(Collectors.joining(", "));
headerText = String.format(RESOURCE_BUNDLE.getString("FilesWillBeDeleted"), names);
} else {
throw new AssertionError();
}
alert.setHeaderText(headerText);
alert.setContentText(RESOURCE_BUNDLE.getString("DoYouConfirm"));
Alert alert = GseAlerts.deleteNodesAlert(selectedTreeItems);
Optional<ButtonType> result = alert.showAndWait();
if (result.get() == ButtonType.OK) {
List<TreeItem<Object>> parentTreeItems = new ArrayList<>();
Expand Down
72 changes: 72 additions & 0 deletions gse-util/src/main/java/com/powsybl/gse/util/GseAlerts.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/**
* Copyright (c) 2017, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package com.powsybl.gse.util;

import com.powsybl.afs.AbstractNodeBase;
import com.powsybl.afs.ProjectNode;
import com.powsybl.afs.Node;
import javafx.scene.control.Alert;
import javafx.scene.control.TreeItem;

import java.util.List;
import java.util.ResourceBundle;
import java.util.stream.Collectors;

/**
* @author Nassirou Nambiema <nassirou.nambiena at rte-france.com>
*/
public final class GseAlerts {
private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle("lang.GseAlerts");

private GseAlerts() {
}

public static void showDraggingError() {
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle(RESOURCE_BUNDLE.getString("DragError"));
alert.setHeaderText(RESOURCE_BUNDLE.getString("Error"));
alert.setContentText(RESOURCE_BUNDLE.getString("FileExists"));
alert.showAndWait();
}

public static void showDialogError(String message) {
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle(RESOURCE_BUNDLE.getString("Error"));
alert.setResizable(true);
alert.setContentText(message);
alert.showAndWait();
}

public static Alert deleteNodesAlert(List<? extends TreeItem> selectedTreeItems) {
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
alert.setTitle(RESOURCE_BUNDLE.getString("ConfirmationDialog"));
String headerText;
final String fileWillBeDeleted = RESOURCE_BUNDLE.getString("FileWillBeDeleted");
AbstractNodeBase node;
if (selectedTreeItems.size() == 1) {
if (selectedTreeItems.get(0).getValue() instanceof ProjectNode) {
node = (ProjectNode) selectedTreeItems.get(0).getValue();
headerText = String.format(fileWillBeDeleted, node.getName());
} else if (selectedTreeItems.get(0).getValue() instanceof Node) {
node = (Node) selectedTreeItems.get(0).getValue();
headerText = String.format(fileWillBeDeleted, node.getName());
} else {
headerText = String.format(fileWillBeDeleted, "the selected file");
}
} else if (selectedTreeItems.size() > 1) {
String names = selectedTreeItems.stream()
.map(selectedTreeItem -> selectedTreeItem.getValue().toString())
.collect(Collectors.joining(", "));
headerText = String.format(RESOURCE_BUNDLE.getString("FilesWillBeDeleted"), names);
} else {
throw new AssertionError();
}
alert.setHeaderText(headerText);
alert.setContentText(RESOURCE_BUNDLE.getString("DoYouConfirm"));
return alert;
}
}
9 changes: 0 additions & 9 deletions gse-util/src/main/java/com/powsybl/gse/util/GseUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import javafx.concurrent.Task;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.Labeled;
import javafx.scene.control.ListView;
import javafx.scene.control.TreeView;
Expand Down Expand Up @@ -147,14 +146,6 @@ public static void showDialogError(Throwable t) {
});
}

public static void showDialogError(String message) {
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle(RESOURCE_BUNDLE.getString("Error"));
alert.setResizable(true);
alert.setContentText(message);
alert.showAndWait();
}

public static <T> Service<T> createService(Task<T> task, Executor executor) {
Service<T> service = new Service<T>() {
@Override
Expand Down
29 changes: 3 additions & 26 deletions gse-util/src/main/java/com/powsybl/gse/util/NodeChooser.java
Original file line number Diff line number Diff line change
Expand Up @@ -390,14 +390,7 @@ private void refresh(TreeItem<N> item) {
}
}

private Alert nameAlreadyExistsAlert() {
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle(RESOURCE_BUNDLE.getString("DragError"));
alert.setHeaderText(RESOURCE_BUNDLE.getString("Error"));
alert.setContentText(RESOURCE_BUNDLE.getString("DragFileExists"));
alert.showAndWait();
return alert;
}


private void onMouseClickedEvent(MouseEvent event) {
TreeItem<N> item = tree.getSelectionModel().getSelectedItem();
Expand Down Expand Up @@ -519,7 +512,7 @@ private void treeItemChildrenSize(TreeItem<N> treeItem, int compte) {
private void accepTransferDrag(Folder folder, boolean s) {
success = s;
if (getCounter() >= 1) {
nameAlreadyExistsAlert();
GseAlerts.showDraggingError();
} else if (getCounter() < 1) {
Project monfichier = (Project) dragAndDropMove.getSource();
monfichier.moveTo(folder);
Expand Down Expand Up @@ -623,23 +616,7 @@ private MenuItem createDeleteNodeMenuItem(List<? extends TreeItem<N>> selectedTr
}

public void createDeleteAlert(List<? extends TreeItem<N>> selectedTreeItems) {
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
alert.setTitle(RESOURCE_BUNDLE.getString("ConfirmationDialog"));
String headerText;
if (selectedTreeItems.size() == 1) {
Node node = (Node) selectedTreeItems.get(0).getValue();
headerText = String.format(RESOURCE_BUNDLE.getString("FileWillBeDeleted"), node.getName());
} else if (selectedTreeItems.size() > 1) {
String names = selectedTreeItems.stream()
.map(selectedItem -> selectedItem.getValue().toString())
.collect(Collectors.joining(", "));
headerText = String.format(RESOURCE_BUNDLE.getString("FilesWillBeDeleted"), names);
} else {
throw new AssertionError();
}
alert.setHeaderText(headerText);
alert.setContentText(RESOURCE_BUNDLE.getString("DoYouConfirm"));
alert.showAndWait().ifPresent(result -> {
GseAlerts.deleteNodesAlert(selectedTreeItems).showAndWait().ifPresent(result -> {
if (result == ButtonType.OK) {
setOnOkButton(selectedTreeItems);
}
Expand Down
9 changes: 9 additions & 0 deletions gse-util/src/main/resources/lang/GseAlerts.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
DragError=Drag error
FileExists=The file name already exists
Error=Error
ConfirmationDialog=Confirmation Dialog
FileWillBeDeleted=File %s will be deleted
FilesWillBeDeleted=Files %s will be deleted
DoYouConfirm=Do you confirm?


7 changes: 7 additions & 0 deletions gse-util/src/main/resources/lang/GseAlerts_fr.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
DragError=Erreur de déplacement
FileExists=Le nom du fichier existe déja
Error=Erreur
ConfirmationDialog=Fenêtre de confirmation
FileWillBeDeleted=Le fichier %s sera supprimé
FilesWillBeDeleted=Les fichiers %s seront supprimé
DoYouConfirm=confirmez-vous?
5 changes: 0 additions & 5 deletions gse-util/src/main/resources/lang/NodeChooser.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,8 @@ Delete=Delete
DeleteError=Delete error
DeletedFolderContainsProjects=The folder %s contains at least one project
Description=Description
DoYouConfirm=Do you confirm?
DragError=Drag error
DragFileExists=The dragged file already exists
Error=Error
File=File
FileWillBeDeleted=File %s will be deleted
FilesWillBeDeleted=Files %s will be deleted
Name=Name
NewName=New Name
OpenFile=Open file
Expand Down
5 changes: 0 additions & 5 deletions gse-util/src/main/resources/lang/NodeChooser_fr.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,8 @@ Delete=Supprimer
DeleteError=Erreur de Suppression
DeletedFolderContainsProjects=le Dossier %s Contient au moins un projet
Description=Description
DoYouConfirm=Confirmez vous?
DragError=Erreur de déplacement
DragFileExists=le fichier déplacé existe déja
Error=Erreur
File=Fichier
FileWillBeDeleted=Le fichier %s sera supprimé
FilesWillBeDeleted=Les fichiers %s seront supprimés
Name=Nom
NewName=Entrez un nouveau nom
OpenFile=Ouvrir un fichier
Expand Down

0 comments on commit 6937de6

Please sign in to comment.