2023-02-28 21:37:14 +01:00
|
|
|
package fenetres;
|
|
|
|
|
|
|
|
import java.awt.Component;
|
|
|
|
import java.awt.Dimension;
|
|
|
|
import java.awt.HeadlessException;
|
|
|
|
import java.awt.Image;
|
2024-04-27 18:14:55 +02:00
|
|
|
import java.io.BufferedReader;
|
2023-02-28 21:37:14 +01:00
|
|
|
import java.io.File;
|
2024-04-27 18:14:55 +02:00
|
|
|
import java.io.FileInputStream;
|
|
|
|
import java.io.InputStreamReader;
|
|
|
|
import java.nio.file.Paths;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
2023-02-28 21:37:14 +01:00
|
|
|
import javax.swing.ImageIcon;
|
|
|
|
import javax.swing.JDialog;
|
|
|
|
import javax.swing.JFileChooser;
|
2024-04-27 18:14:55 +02:00
|
|
|
import javax.swing.JFrame;
|
|
|
|
import javax.swing.JLabel;
|
|
|
|
import javax.swing.JOptionPane;
|
2023-02-28 21:37:14 +01:00
|
|
|
import javax.swing.filechooser.FileNameExtensionFilter;
|
2024-04-27 18:14:55 +02:00
|
|
|
|
2023-02-28 21:37:14 +01:00
|
|
|
import MEPTL.commandes;
|
2024-04-08 20:46:40 +02:00
|
|
|
import baseEvaluations.recupeNodeBaseEvaluations;
|
2024-04-27 18:14:55 +02:00
|
|
|
import cXML.node;
|
2024-04-08 20:46:40 +02:00
|
|
|
|
2024-04-09 14:50:03 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @author pabr6
|
|
|
|
*
|
|
|
|
*/
|
2023-02-28 21:37:14 +01:00
|
|
|
public class ChargePathBaseEvaluation extends JFileChooser {
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
private static final long serialVersionUID = 1L;
|
2023-04-01 09:54:28 +02:00
|
|
|
boolean avecFusion = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
2024-04-27 18:14:55 +02:00
|
|
|
public ChargePathBaseEvaluation(Boolean fusionWithDefaut) {
|
|
|
|
avecFusion = fusionWithDefaut;
|
2023-02-28 21:37:14 +01:00
|
|
|
setDialogTitle("Sélectionner la base de données des évaluations.");
|
|
|
|
FileNameExtensionFilter filter = new FileNameExtensionFilter("Base de données des évaluations", "xml");
|
|
|
|
setFileFilter(filter);
|
|
|
|
setPreferredSize(new Dimension(550, 420));
|
|
|
|
int response = showOpenDialog(null);
|
|
|
|
if(response == JFileChooser.APPROVE_OPTION) {
|
|
|
|
File file = new File(getSelectedFile().getAbsolutePath());
|
|
|
|
String ext = file.getName().substring(file.getName().lastIndexOf("."));
|
|
|
|
if(ext.equals(".xml")){
|
2024-04-27 18:14:55 +02:00
|
|
|
if(!avecFusion) {
|
|
|
|
openFileXML(file);
|
|
|
|
}else {
|
|
|
|
fusionBaseWithDefaut(file);
|
|
|
|
}
|
2023-04-01 09:54:28 +02:00
|
|
|
}
|
2023-02-28 21:37:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-27 17:01:17 +02:00
|
|
|
|
|
|
|
|
2023-04-01 09:54:28 +02:00
|
|
|
|
|
|
|
|
2023-02-28 21:37:14 +01:00
|
|
|
@Override
|
2023-04-01 09:54:28 +02:00
|
|
|
protected JDialog createDialog( Component parent ) throws HeadlessException {
|
2023-02-28 21:37:14 +01:00
|
|
|
JDialog dialog = super.createDialog( parent );
|
|
|
|
Image img = new ImageIcon(getClass().getResource("/evalwriter.png") ).getImage();
|
|
|
|
dialog.setIconImage(img);
|
|
|
|
return dialog;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param file
|
|
|
|
*/
|
|
|
|
private void openFileXML(File file) {
|
|
|
|
if(commandes.os.contains("Win")) {
|
|
|
|
commandes.path = file.getPath().substring(0,file.getPath().lastIndexOf("\\")); // Sur Windows
|
|
|
|
}else {
|
|
|
|
commandes.path = file.getPath().substring(0,file.getPath().lastIndexOf("/")); // Sur mac & Linux
|
|
|
|
}
|
2024-04-08 20:46:40 +02:00
|
|
|
String directoryName = getCurrentDirectory().getPath();
|
|
|
|
String nameNewBase = file.getName().toString();
|
2024-04-27 17:01:17 +02:00
|
|
|
new recupeNodeBaseEvaluations(directoryName,nameNewBase);
|
2023-02-28 21:37:14 +01:00
|
|
|
}
|
|
|
|
|
2024-04-27 18:14:55 +02:00
|
|
|
private void fusionBaseWithDefaut(File file) {
|
|
|
|
node copieDefault = new node();
|
|
|
|
|
|
|
|
try {
|
|
|
|
commandes.PathBaseEvaluations = Paths.get("").toAbsolutePath().toString();
|
|
|
|
commandes.NameBaseEvaluations = "base_evaluations_analyseWriter.xml";
|
|
|
|
commandes.PathBaseEvaluationDefaut = true;
|
|
|
|
copieDefault = commandes.evaluationsBase.clone();
|
|
|
|
} catch (CloneNotSupportedException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(!copieDefault.isVide() && !commandes.evaluationsBase.isVide()) {
|
|
|
|
|
|
|
|
BufferedReader br;
|
|
|
|
node evaluations = new node();
|
|
|
|
try {
|
|
|
|
br = new BufferedReader(
|
|
|
|
new InputStreamReader(
|
|
|
|
new FileInputStream(file.getAbsoluteFile()), "UTF-8"));
|
|
|
|
String line;
|
|
|
|
StringBuilder targetString = new StringBuilder();
|
|
|
|
while ((line = br.readLine()) != null) {
|
|
|
|
targetString.append(line);
|
|
|
|
}
|
|
|
|
String CodeTexte = targetString.toString().replace("\t","").replace("\r", "").replace("\n", "");
|
|
|
|
evaluations = new node(CodeTexte);
|
|
|
|
|
|
|
|
}catch (Exception e) {
|
|
|
|
JFrame frame = new JFrame("Erreur");
|
|
|
|
JLabel texte = new JLabel("<html><h1>Erreur</h1><p>L'évaluation n'a pas été trouvé dans la base de données.</p></html>");
|
|
|
|
JOptionPane.showMessageDialog(frame, texte);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for(int i = 0 ; i < evaluations.getNodes().size();i++) {
|
|
|
|
String date = evaluations.getNodes().get(i).getAttributs().get("date");
|
|
|
|
ArrayList<node> A = copieDefault.retourneEnfantsByNameAndValueAttribut("evaluation", "date", date, new ArrayList<node>());
|
|
|
|
|
|
|
|
// l'évaluation n'existe pas dans la base par défaut
|
|
|
|
if(A.size()==0) {
|
|
|
|
evaluations.getNodes().get(i);
|
|
|
|
|
|
|
|
}else {
|
|
|
|
// L'évaluation existe dans la base par défaut
|
|
|
|
for(int j = 0; j < A.size();j++) {
|
|
|
|
String dateModification = evaluations.getNodes().get(i).getAttributs().get("dateModification");
|
|
|
|
if(!A.get(j).getAttributs().get("dateModification").equals(dateModification)) {
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2023-02-28 21:37:14 +01:00
|
|
|
|
|
|
|
}
|