analyseWriter/src/action/actSaveHistoriqueEvaluation...

125 lines
4.4 KiB
Java

package action;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import javax.swing.filechooser.FileSystemView;
import MEPTL.commandes;
import cXML.node;
import fenetres.create;
public class actSaveHistoriqueEvaluation extends AbstractAction{
{
putValue( Action.NAME, "Sauvegarder l'évaluation" );
putValue( Action.SMALL_ICON, new ImageIcon(create.class.getResource("/resources/sauvegardehistoriqueevaluationmini.png")) );
putValue( Action.MNEMONIC_KEY, KeyEvent.VK_O );
putValue( Action.SHORT_DESCRIPTION, "Sauvegarder l'évaluation" );
}
private static final long serialVersionUID = 1L;
@Override
public void actionPerformed(ActionEvent e) {
if(commandes.fichierAnalyseValide) {
String name = JOptionPane.showInputDialog(null,"Donner un nom à cette évaluation ?","Nom de l'évaluation");
if(!name.isBlank()) {
node evaluations = nodeEvaluations();
if(!isEvaluationExist(evaluations, name)) {
sauvegardeEvaluation(new node(), name);
}else {
sauvegardeEvaluation(evaluations.retourneFirstNodeByNameAndAttributValueExactStrict("evaluation", "name", name), name);
}
}
}
}
private boolean isEvaluationExist(node evaluations, String nameEvaluation) {
if(evaluations.retourneFirstNodeByNameAndAttributValueExactStrict("evaluation", "name", nameEvaluation)!=null) return true;
return false;
}
@SuppressWarnings("unused")
private node nodeEvaluations() {
node evaluations = null;
File directory = new File(FileSystemView.getFileSystemView().getDefaultDirectory().getPath());
if (directory.exists()){
File file = null;
if(commandes.os.contains("Win")) {
file = new File(directory.getAbsolutePath() + "\\" + "evaluations.xml");
}else {
file = new File(directory.getAbsolutePath() + "/" + "evaluations.xml");
}
if(file!=null) {
BufferedReader br;
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);
}
evaluations = new node(targetString.toString());
}catch (Exception e) {
// TODO: handle exception
}
}else {
evaluations = new node();
evaluations.setNomElt("evaluations");
}
}
return evaluations;
}
private void sauvegardeEvaluation(node evaluation, String name) {
evaluation.setNomElt("evaluation");
evaluation.getAttributs().put("name", name);
evaluation.getAttributs().put("PathFilenameAnalysis", commandes.PathFilenameAnalysis);
evaluation.getAttributs().put("path", commandes.path );
evaluation.getAttributs().put("fichierStudentMoodle", String.valueOf(commandes.fichierStudentMoodle) );
evaluation.getAttributs().put("sansFeeback", String.valueOf(commandes.sansFeeback) );
evaluation.getAttributs().put("noDetail", String.valueOf(commandes.noDetail) );
evaluation.getAttributs().put("noNote", String.valueOf(commandes.noNote) );
evaluation.getAttributs().put("zipfeedback", String.valueOf(commandes.zipfeedback) );
evaluation.getAttributs().put("verifHisto2", String.valueOf(commandes.verifHisto2) );
evaluation.getAttributs().put("ecritNoteCSV", String.valueOf(commandes.ecritNoteCSV) );
evaluation.getAttributs().put("newLogo", String.valueOf(commandes.newLogo) );
evaluation.getAttributs().put("noLogo", String.valueOf(commandes.noLogo) );
evaluation.getAttributs().put("fourniCSV", String.valueOf(commandes.fourniCSV) );
evaluation.getAttributs().put("nameCSV", commandes.nameCSV );
evaluation.getAttributs().put("fourniCSV", String.valueOf(commandes.fourniCSV) );
evaluation.getAttributs().put("nameSVG", commandes.nameSVG );
evaluation.getNodes().add(commandes.sujet);
evaluation.getNodes().add(commandes.nodeCSV);
if(!commandes.nameSVG.isBlank() && !commandes.contenuFichierSVG.isBlank()) {
node SVG = new node();
SVG.setNomElt("nodSVG");
SVG.setContenu(commandes.contenuFichierSVG);
evaluation.getNodes().add(SVG);
}
}
}