analyseWriter/src/fenetres/ChargePathBaseEvaluation.java

151 lines
4.4 KiB
Java
Raw Normal View History

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;
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;
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;
import javax.swing.filechooser.FileNameExtensionFilter;
2024-04-27 18:14:55 +02: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
*
*/
public class ChargePathBaseEvaluation extends JFileChooser {
/**
*
*/
private static final long serialVersionUID = 1L;
boolean avecFusion = false;
/**
*
*/
2024-04-27 18:14:55 +02:00
public ChargePathBaseEvaluation(Boolean fusionWithDefaut) {
avecFusion = fusionWithDefaut;
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);
}
}
}
}
2024-04-27 17:01:17 +02:00
@Override
protected JDialog createDialog( Component parent ) throws HeadlessException {
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);
}
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)) {
}
}
}
}
}
}
}