24c47febe7
Chargement du fichier d'analyse source si la date est postérieure à la date du fichier d'analyse base.
99 lines
3.8 KiB
Java
99 lines
3.8 KiB
Java
package action;
|
|
|
|
import java.awt.event.ActionEvent;
|
|
import java.awt.event.KeyEvent;
|
|
import java.io.File;
|
|
import java.io.IOException;
|
|
import java.text.ParseException;
|
|
import java.util.regex.Matcher;
|
|
import java.util.regex.Pattern;
|
|
|
|
import javax.swing.AbstractAction;
|
|
import javax.swing.Action;
|
|
import javax.swing.ImageIcon;
|
|
import javax.swing.JFileChooser;
|
|
|
|
import MEPTL.commandes;
|
|
import MEPTL.verificationFichierAnalyse;
|
|
import cXML.Run;
|
|
|
|
public class actSaveAs extends AbstractAction{
|
|
|
|
/**
|
|
*
|
|
*/
|
|
private static final long serialVersionUID = 1L;
|
|
{
|
|
putValue( Action.NAME, "Enregistrer le fichier d'analyse sous..." );
|
|
putValue( Action.SMALL_ICON, new ImageIcon(getClass().getResource("/save_as.png") ));
|
|
putValue( Action.MNEMONIC_KEY, KeyEvent.VK_A );
|
|
putValue( Action.SHORT_DESCRIPTION, "Enregistrer le fichier d'analyse de l'évaluation sous..." );
|
|
}
|
|
@Override
|
|
public void actionPerformed(ActionEvent e) {
|
|
JFileChooser fileChooser = new JFileChooser();
|
|
fileChooser.setDialogTitle("Enregistrer sous...");
|
|
File file = null;
|
|
|
|
if(!commandes.nameSujet.isEmpty()) {
|
|
file = new File(commandes.PathFilenameAnalysis ); //+ "\\" + utils.filename + ".xml"
|
|
System.out.println("commandes.PathFilenameAnalysis="+commandes.PathFilenameAnalysis);
|
|
}
|
|
|
|
|
|
|
|
fileChooser.setCurrentDirectory(file);
|
|
|
|
int userSelection = fileChooser.showSaveDialog(null);
|
|
|
|
if (userSelection == JFileChooser.APPROVE_OPTION) {
|
|
File fileToSave = fileChooser.getSelectedFile();
|
|
try {
|
|
|
|
verificationFichierAnalyse.MiseAJourHashNomFichierAnalyse(fileToSave.getName());
|
|
//Mise à jour de la date d'enregistrement du fichier d'analyse
|
|
try {
|
|
commandes.sujet.getAttributs().put("date", calcul.formatDateWriter.dateTodayLibreOffice());
|
|
} catch (ParseException e1) {
|
|
e1.printStackTrace();
|
|
}
|
|
|
|
if(commandes.os.contains("Win")) {
|
|
Run.ecritureNodeEnXML(commandes.sujet, fileToSave.getName(), fileToSave.getPath().substring(0,fileToSave.getPath().lastIndexOf("\\")),Run.TypeFile.Sujet );
|
|
}else {
|
|
Run.ecritureNodeEnXML(commandes.sujet, fileToSave.getName(), fileToSave.getPath().substring(0,fileToSave.getPath().lastIndexOf("/")),Run.TypeFile.Sujet );
|
|
}
|
|
|
|
commandes.nameSujet = fileToSave.getName();
|
|
|
|
if(commandes.os.contains("Win")) {
|
|
commandes.PathFilenameAnalysis = fileToSave.getPath().substring(0,fileToSave.getPath().lastIndexOf("\\"));
|
|
}else{
|
|
commandes.PathFilenameAnalysis = fileToSave.getPath().substring(0,fileToSave.getPath().lastIndexOf("/"));
|
|
}
|
|
|
|
|
|
Pattern p = Pattern.compile("[.xml]\\b");
|
|
Matcher m = p.matcher(commandes.nameSujet);
|
|
|
|
if(m.find()) {
|
|
file = new File(commandes.PathFilenameAnalysis + "\\" + commandes.nameSujet);
|
|
fenetres.create.getTextNodeSelect().setText("Le fichier \"" + commandes.nameSujet + " a été renregistré.\n\nIl se trouve dans le dossier " + commandes.PathFilenameAnalysis);
|
|
}else {
|
|
file = new File(commandes.PathFilenameAnalysis + "\\" + commandes.nameSujet + ".xml");
|
|
fenetres.create.getTextNodeSelect().setText("Le fichier \"" + commandes.nameSujet + ".xml\" a été renregistré.\n\nIl se trouve dans le dossier " + commandes.PathFilenameAnalysis);
|
|
}
|
|
|
|
|
|
} catch (IOException e1) {
|
|
e1.printStackTrace();
|
|
} catch (CloneNotSupportedException e1) {
|
|
e1.printStackTrace();
|
|
}
|
|
System.out.println("Save as file: " + fileToSave.getAbsolutePath());
|
|
}
|
|
System.out.println( "Save as" );
|
|
}
|
|
|
|
}
|