analyseWriter/src/fenetres/baseDonneesEvaluations.java

664 lines
25 KiB
Java

package fenetres;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.SystemColor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.File;
import java.io.IOException;
import java.nio.file.Paths;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextPane;
import javax.swing.ListSelectionModel;
import javax.swing.SwingConstants;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.TableColumnModel;
import MEPTL.commandes;
import baseEvaluations.chargeEvaluation;
import baseEvaluations.creerNouvelleEvaluation;
import baseEvaluations.myTableBaseEvaluation;
import baseEvaluations.recupeNodeBaseEvaluations;
import baseEvaluations.removeEvaluation;
import baseEvaluations.trierParDateDecroissanteLaBase;
import cXML.Run;
import cXML.node;
import net.lingala.zip4j.exception.ZipException;
import net.miginfocom.swing.MigLayout;
public class baseDonneesEvaluations extends JFrame { /**
*
*/
private static final long serialVersionUID = 1L;
private static baseDonneesEvaluations instance;
private myTableBaseEvaluation model = new myTableBaseEvaluation();
static JTable table = new JTable();
private JPanel panelHaut = new JPanel();
private JPanel panelBas = new JPanel();
private JPanel panelGauche = new JPanel();
private JLabel lblInformationBaseEvluation = new JLabel("");
private JButton btnSupprimeEvaluation = new JButton("<html>Supprimer une<br>évaluation</html>");
private JButton btnSaveEvaluation = new JButton("<html>Enregistrer l'évaluation<br>chargée en mémoire.</html>");
private JButton btnRenommeFichierAnalyse = new JButton("<html>Renommer le fichier d'analyse<br>de l'évaluation sélectionnée</html>");
private JButton btnRenommerEvaluation = new JButton("<html>Renommer l'évaluation<br>sélectionnée</html>");
private JButton btndefautBaseEvaluation = new JButton("<html>Base par défaut</html>");
public static boolean isDispose = true;
int indexSelect=0;
ListSelectionModel lsm = null;
JScrollPane scrollPaneTable = new JScrollPane();
JScrollPane scrollPaneBoutons = new JScrollPane();
private final JButton btnChargerNewBase = new JButton("<html>Utiliser une autre<br>base d'évaluation</html>");
private final JButton btnFermer = new JButton("<html>Femer</html>");
private final JTextPane textPane = new JTextPane();
private final JTextPane textPane_1 = new JTextPane();
private final JButton btnExtraireFileAnalysis = new JButton("<html>Extraire le fichier d'analyse<br>de l'évaluation sélectionnée</html>");
private final JButton btnFusionnerBase = new JButton("<html>Importer des évaluations<br>depuis une autre base</html>");
private final JButton btnChargerFichierAnalyse = new JButton("<html>Créer une évaluation à <br>partir d'un fichier d'analyse</html>");
private final static JLabel lblCheminVersBase = new JLabel(commandes.PathBaseEvaluations);
private final JButton btnArchiveBase = new JButton("<html>Copie de sauvegarde</html>");
public baseDonneesEvaluations() {
super();
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setLocationRelativeTo( null );
setSize(1600,900);
int screenWidth = (int) java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds().getWidth();
int screenHeight = (int) java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds().getHeight();
setLocation(( (screenWidth) - getWidth()) / 2, (screenHeight - getHeight()) / 2);
ImageIcon img = new ImageIcon(getClass().getResource("/evalwriter.png") );
setIconImage(img.getImage());
setTitle(commandes.Titre + " - La base de données des évaluations");
getContentPane().setLayout(new BorderLayout(2, 2));
model.addOrUpdate();
table = new JTable(model);
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
TableColumnModel columnModel = table.getColumnModel();
columnModel.getColumn(0).setPreferredWidth(300);
columnModel.getColumn(0).setMaxWidth(400);
columnModel.getColumn(1).setPreferredWidth(300);
columnModel.getColumn(1).setMaxWidth(400);
columnModel.getColumn(2).setPreferredWidth(300);
columnModel.getColumn(2).setMaxWidth(400);
columnModel.getColumn(3).setPreferredWidth(300);
columnModel.getColumn(3).setMaxWidth(400);
columnModel.getColumn(3).setPreferredWidth(300);
columnModel.getColumn(3).setMaxWidth(400);
columnModel.getColumn(4).setPreferredWidth(300);
columnModel.getColumn(4).setMaxWidth(400);
columnModel.getColumn(5).setPreferredWidth(300);
columnModel.getColumn(5).setMaxWidth(400);
table.setFont(new Font("Tahoma", Font.PLAIN, 14));
scrollPaneTable = new JScrollPane(table);
//Add the scroll pane to this panel.
getContentPane().add(scrollPaneTable,BorderLayout.CENTER);
getContentPane().add(panelBas, BorderLayout.SOUTH);
FlowLayout fl_panelBas = new FlowLayout(FlowLayout.LEADING, 10, 10);
panelBas.setLayout(fl_panelBas);
textPane.setBackground(SystemColor.menu);
panelBas.add(textPane);
textPane_1.setBackground(SystemColor.menu);
panelBas.add(textPane_1);
lblCheminVersBase.setIcon(new ImageIcon(baseDonneesEvaluations.class.getResource("/resources/BaseEvaluationsmini.png")));
panelBas.add(lblCheminVersBase);
if(commandes.evaluationChargeEnMemoire!=null) {
textPane.setText("Evaluation chargée en mémoire : " + commandes.evaluationChargeEnMemoire.getAttributs().get("name"));
}
//*Le haut
getContentPane().add(panelHaut, BorderLayout.NORTH);
panelHaut.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
lblInformationBaseEvluation.setIcon(new ImageIcon(baseDonneesEvaluations.class.getResource("/resources/accueilChargeEvaluation.png")));
lblInformationBaseEvluation.setFont(new Font("Tahoma", Font.BOLD, 14));
panelHaut.add(lblInformationBaseEvluation);
panelGauche.setBorder(null);
scrollPaneBoutons = new JScrollPane(panelGauche);
getContentPane().add(scrollPaneBoutons, BorderLayout.WEST);
panelGauche.setLayout(new MigLayout("", "[:300px:400px,fill]", "[53px][][][][20px:n][][][][][30.00][20px:n][][][]"));
btndefautBaseEvaluation.setToolTipText("Recharge la base de données par défaut.");
btndefautBaseEvaluation.setHorizontalAlignment(SwingConstants.LEFT);
btndefautBaseEvaluation.setForeground(new Color(0, 128, 192));
panelGauche.add(btndefautBaseEvaluation, "cell 0 0,grow");
btndefautBaseEvaluation.setFont(new Font("Tahoma", Font.BOLD, 18));
btndefautBaseEvaluation.setIcon(new ImageIcon(baseDonneesEvaluations.class.getResource("/resources/defautBaseEvaluation.png")));
btnChargerNewBase.setToolTipText("Charge les évaluations d'une autre base de données.");
btnChargerNewBase.setHorizontalAlignment(SwingConstants.LEFT);
btnChargerNewBase.setForeground(new Color(0, 128, 192));
panelGauche.add(btnChargerNewBase, "cell 0 1,growx,aligny top");
btnChargerNewBase.setFont(new Font("Tahoma", Font.BOLD, 15));
btnChargerNewBase.setIcon(new ImageIcon(baseDonneesEvaluations.class.getResource("/resources/sauvegardehistoriqueevaluation.png")));
btnArchiveBase.setToolTipText("Archiver la base de données pour la sauvegarder et la réutiliser.");
btnArchiveBase.setForeground(new Color(128, 128, 192));
btnArchiveBase.setFont(new Font("Tahoma", Font.BOLD, 15));
btnArchiveBase.setHorizontalAlignment(SwingConstants.LEFT);
btnArchiveBase.setIcon(new ImageIcon(baseDonneesEvaluations.class.getResource("/resources/saveZipEvaluation.png")));
panelGauche.add(btnArchiveBase, "cell 0 2,growx,aligny top");
btnFusionnerBase.setToolTipText("Importer des évaluations dans la base par défaut depuis une autre base.");
btnFusionnerBase.setForeground(new Color(56, 184, 149));
btnFusionnerBase.setHorizontalAlignment(SwingConstants.LEFT);
btnFusionnerBase.setIcon(new ImageIcon(baseDonneesEvaluations.class.getResource("/resources/fusionneBaseEvaluation.png")));
btnFusionnerBase.setFont(new Font("Tahoma", Font.BOLD, 15));
panelGauche.add(btnFusionnerBase, "cell 0 3,growx,aligny top");
btnSaveEvaluation.setToolTipText("Enregistre l'évaluation chargée en mémoire.");
btnSaveEvaluation.setHorizontalAlignment(SwingConstants.LEFT);
btnSaveEvaluation.setIcon(new ImageIcon(baseDonneesEvaluations.class.getResource("/resources/saveEvaluation.png")));
panelGauche.add(btnSaveEvaluation, "flowy,cell 0 5,growx,aligny top");
btnSaveEvaluation.setForeground(new Color(0, 64, 128));
btnSaveEvaluation.setFont(new Font("Tahoma", Font.BOLD, 15));
btnRenommerEvaluation.setToolTipText("Renommer l'évaluation sélectionnée.");
btnRenommerEvaluation.setHorizontalAlignment(SwingConstants.LEFT);
btnRenommerEvaluation.setIcon(new ImageIcon(baseDonneesEvaluations.class.getResource("/resources/renommeEvaluaton.png")));
panelGauche.add(btnRenommerEvaluation, "cell 0 6,growx,aligny top");
btnRenommerEvaluation.setForeground(new Color(153, 50, 204));
btnRenommerEvaluation.setFont(new Font("Tahoma", Font.BOLD, 15));
btnChargerFichierAnalyse.setToolTipText("Création d'une évaluation à partir d'un fichier d'analyse au format XML.");
btnChargerFichierAnalyse.setForeground(new Color(0, 64, 128));
btnChargerFichierAnalyse.setHorizontalAlignment(SwingConstants.LEFT);
btnChargerFichierAnalyse.setIcon(new ImageIcon(baseDonneesEvaluations.class.getResource("/resources/fichierAnalyse.png")));
btnChargerFichierAnalyse.setFont(new Font("Tahoma", Font.BOLD, 15));
panelGauche.add(btnChargerFichierAnalyse, "cell 0 7,growx,aligny top");
btnExtraireFileAnalysis.setToolTipText("Extraire le fichier d'analyse de l'évaluation sélectionnée.");
btnExtraireFileAnalysis.setHorizontalAlignment(SwingConstants.LEFT);
btnExtraireFileAnalysis.setIcon(new ImageIcon(baseDonneesEvaluations.class.getResource("/resources/extraireFichierAnalyse.png")));
btnExtraireFileAnalysis.setForeground(new Color(209, 105, 35));
btnExtraireFileAnalysis.setFont(new Font("Tahoma", Font.BOLD, 15));
panelGauche.add(btnExtraireFileAnalysis, "cell 0 8,growx,aligny top");
btnRenommeFichierAnalyse.setHorizontalAlignment(SwingConstants.LEFT);
btnRenommeFichierAnalyse.setIcon(new ImageIcon(baseDonneesEvaluations.class.getResource("/resources/fichierAnalyseRenomme.png")));
panelGauche.add(btnRenommeFichierAnalyse, "cell 0 9,growx,aligny top");
btnRenommeFichierAnalyse.setForeground(new Color(255, 140, 0));
btnRenommeFichierAnalyse.setFont(new Font("Tahoma", Font.BOLD, 15));
btnSupprimeEvaluation.setHorizontalAlignment(SwingConstants.LEFT);
btnSupprimeEvaluation.setIcon(new ImageIcon(baseDonneesEvaluations.class.getResource("/resources/removeEvaluaton.png")));
panelGauche.add(btnSupprimeEvaluation, "cell 0 11,growx,aligny top");
btnSupprimeEvaluation.setForeground(new Color(255, 0, 0));
btnSupprimeEvaluation.setFont(new Font("Tahoma", Font.BOLD, 15));
btnFermer.setIcon(new ImageIcon(baseDonneesEvaluations.class.getResource("/resources/quitteEvaluation.png")));
btnFermer.setHorizontalAlignment(SwingConstants.LEFT);
btnFermer.setFont(new Font("Tahoma", Font.BOLD, 15));
panelGauche.add(btnFermer, "cell 0 12,growx,aligny top");
//*Détection de la ligne sélectionnée
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
ListSelectionModel rowSM = table.getSelectionModel();
rowSM.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
//Ignore extra messages.
if (e.getValueIsAdjusting()) return;
lsm = (ListSelectionModel)e.getSource();
if (lsm.isSelectionEmpty()) {
System.out.println("Aucune ligne sélectionnée.");
} else {
indexSelect = lsm.getMinSelectionIndex();
System.out.println("La ligne " + indexSelect + " est sélectionnée.");
}
}
});
ListenerAction();
}
public static baseDonneesEvaluations getInstance() {
if (isDispose) {
instance = new baseDonneesEvaluations();
}
// afficheLesBoutonGestionBase();
instance.setVisible(true);
if(commandes.IndexEvaluationCharger!=-1) {
selectRow(commandes.IndexEvaluationCharger);
}
isDispose=false;
if(commandes.PathBaseEvaluationDefaut) {
lblCheminVersBase.setText(commandes.PathBaseEvaluations);
}else {
lblCheminVersBase.setText(commandes.PathBaseEvaluations+"/"+commandes.NameBaseEvaluations);
}
return instance;
}
public static void selectRow(int indexRow) {
table.setRowSelectionInterval(indexRow, indexRow);
}
/**
* Ferme l'instance.
*/
public static void ferme() {
if(!isDispose) {
isDispose=true;
instance.dispose();
}
}
private void ListenerAction() {
/**
* Quitter le fenêtre.</br>
*/
addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void windowClosing(java.awt.event.WindowEvent windowEvent) {
isDispose=true;
dispose();
}
});
/**
* Archive la base des évaluations.
*/
btnArchiveBase.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if(commandes.evaluationsBase!=null) {
try {
String nameFile = Run.AddBaseToZip(Run.ecritureNode(commandes.evaluationsBase, 0));
JOptionPane.showMessageDialog(null, "La base des évaluations a été sauvegardée dans \"Archive des bases.zip\"\nSous le nom " + nameFile );
} catch (ZipException e1) {
e1.printStackTrace();
}
}
}
});
/**
* Extrait le fichier d'analyse de l'évaluation.
*/
btnExtraireFileAnalysis.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if(lsm!=null) {
if (!lsm.isSelectionEmpty()) {
node evaluation = chargeEvaluation.retourneEvaluationSelected(indexSelect);
String nameFile ="fichier analyse.xml";
if(evaluation.getAttributs().get("analysis_filename")!=null) {
nameFile = evaluation.getAttributs().get("analysis_filename");
}
JFileChooser fileChooser = new JFileChooser();
fileChooser.setDialogTitle("Enregistrer sous...");
File file = null;
String analysis_filename ="";
if(evaluation.getAttributs().get("analysis_filename")!=null) {
if(!evaluation.getAttributs().get("analysis_filename").isEmpty()) {
file = new File(commandes.PathBaseEvaluations);
analysis_filename = evaluation.getAttributs().get("analysis_filename");
}
}else {
file = new File(commandes.PathBaseEvaluations);
}
fileChooser.setCurrentDirectory(file);
fileChooser.setSelectedFile(new File(nameFile));
int userSelection = fileChooser.showSaveDialog(null);
boolean notError = false;
if (userSelection == JFileChooser.APPROVE_OPTION) {
File fileToSave = fileChooser.getSelectedFile();
try {
if(commandes.os.contains("Win")) {
notError = Run.ecritureNodeEnXML(evaluation.retourneFirstEnfantsByName("fichier"), fileToSave.getName(), fileToSave.getPath().substring(0,fileToSave.getPath().lastIndexOf("\\")),Run.TypeFile.Sujet );
}else {
notError = Run.ecritureNodeEnXML(evaluation.retourneFirstEnfantsByName("fichier"), fileToSave.getName(), fileToSave.getPath().substring(0,fileToSave.getPath().lastIndexOf("/")),Run.TypeFile.Sujet );
}
if(notError) {
JFrame frame = new JFrame("Extration");
JLabel texte = new JLabel("<html><h1>Extration réussie</h1><p>Le fichier d'analyse <b>"+ analysis_filename +"</b> a été extrait de la base.</p>"
+ "<p>"+fileToSave.getAbsolutePath()+"<p></html>");
JOptionPane.showMessageDialog(frame, texte);
}else {
JFrame frame = new JFrame("Erreur");
JLabel texte = new JLabel("<html><h1>Erreur</h1><p>Le fichier d'analyse n'a pas été extrait de la base.</p>"
+ "<p><p></html>");
JOptionPane.showMessageDialog(frame, texte);
}
} catch (IOException e1) {
e1.printStackTrace();
}
System.out.println("Save as file: " + fileToSave.getAbsolutePath());
new recupeNodeBaseEvaluations();
}
System.out.println( "Save as" );
}
}
}
});
/**
* Charger un fichier d'analyse
*/
btnChargerFichierAnalyse.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
new ChargeFichierXML();
//Encapsulation du node d'analyse fichier dans un node evaluation.
node evaluation = new node();
evaluation.setNomElt("evaluation");
String name = "Nouvelle évaluation";
evaluation.getNodes().add(commandes.sujet);
name = JOptionPane.showInputDialog(null,"Donner un nom à cette évaluation ?",name);
if(name!=null) {
if(!name.isBlank()) {
evaluation.getNodes().add(commandes.sujet);
new creerNouvelleEvaluation(evaluation,name,false,false);
new recupeNodeBaseEvaluations();
model.addOrUpdate();
table.setModel(model);
}
}else {
JOptionPane.showConfirmDialog(null, "L'évaluation n'a pas été enregistrée.\nVous devez fournir un nom à l'évaluation.");
}
}
});
/**
* Fusionner deux bases d'évaluations
*/
btnFusionnerBase.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
new ChargePathBaseEvaluation(true);
new trierParDateDecroissanteLaBase();
model.addOrUpdate();
table.setModel(model);
selectRow(commandes.IndexEvaluationCharger);
}
});
/**
* Femer la fenêtre.
*/
btnFermer.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
isDispose=true;
dispose();
}
});
/**
* Charger une nouvelle base d'évaluation
*/
btnChargerNewBase.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
new ChargePathBaseEvaluation(false);
if(commandes.evaluationsBase!=null) {
baseDonneesEvaluations.getInstance();
}
if(commandes.PathBaseEvaluationDefaut) {
lblCheminVersBase.setText(commandes.PathBaseEvaluations);
}else {
lblCheminVersBase.setText(commandes.PathBaseEvaluations+"/"+commandes.NameBaseEvaluations);
}
model.addOrUpdate();
table = new JTable(model);
}
});
/**
* Charge la base par défaut
*/
btndefautBaseEvaluation.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
commandes.PathBaseEvaluations = Paths.get("").toAbsolutePath().toString();
commandes.NameBaseEvaluations = "base_evaluations_analyseWriter.xml";
commandes.PathBaseEvaluationDefaut = true;
new recupeNodeBaseEvaluations();
if(commandes.PathBaseEvaluationDefaut) {
lblCheminVersBase.setText(commandes.PathBaseEvaluations);
}else {
lblCheminVersBase.setText(commandes.PathBaseEvaluations+"/"+commandes.NameBaseEvaluations);
}
model.addOrUpdate();
table = new JTable(model);
}
});
/**
* Chargement d'une évaluation par double click.
*/
table.addMouseListener( new MouseListener() {
@Override
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
if (e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1) {
System.out.println("un click ou deux click");
if(lsm!=null) {
if (!lsm.isSelectionEmpty()) {
indexSelect = lsm.getMinSelectionIndex();
chargeEvaluation.chargeEnMémoireEvaluationSelected(indexSelect);
commandes.IndexEvaluationCharger = indexSelect;
if(!create.isDispose) {
create.getInstance();
}else {
evaluate.getInstance();
}
isDispose=true;
dispose();
}
}
}
}
}
@Override
public void mousePressed(MouseEvent e) {
}
@Override
public void mouseReleased(MouseEvent e) {
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
}
});
/**
* Bouton Sauvegarde de l'évaluation en cours</br>
* avec renommage de l'évaluation.</br>
*/
btnSaveEvaluation.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(commandes.evaluationChargeEnMemoire!=null) {
String name = commandes.evaluationChargeEnMemoire.getAttributs().get("name");
name = JOptionPane.showInputDialog(null,"Voulez-vous renommer l'évaluation ?",name);
if(name!=null) {
if(!name.isBlank()) {
new creerNouvelleEvaluation(commandes.evaluationChargeEnMemoire, name,true,false);
}
}
}else {
String name = JOptionPane.showInputDialog(null,"Voulez-vous renommer l'évaluation ?","Nouvelle évaluation");
if(name!=null) {
if(!name.isBlank()) {
new creerNouvelleEvaluation(new node(), name,false,false);
}
}
}
new trierParDateDecroissanteLaBase();
new recupeNodeBaseEvaluations();
model.addOrUpdate();
table.setModel(model);
selectRow(commandes.IndexEvaluationCharger);
}
});
/**
* Bouton supprimer une évaluation.</br>
*/
btnSupprimeEvaluation.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(lsm!=null) {
if (!lsm.isSelectionEmpty()) {
if(JOptionPane.showConfirmDialog(null,"Voulez-vous supprimer l'évaluation sélectionnée ?",
"Suppression", JOptionPane.YES_NO_OPTION,JOptionPane.WARNING_MESSAGE)==JOptionPane.YES_OPTION) {
indexSelect = lsm.getMinSelectionIndex();
node evaluation = chargeEvaluation.retourneEvaluationSelected(indexSelect);
new removeEvaluation(evaluation);
new recupeNodeBaseEvaluations();
model.addOrUpdate();
table.setModel(model);
}
}
}
}
});
/**
* Renomme le fichier d'analyse
*/
btnRenommeFichierAnalyse.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(lsm!=null)if (!lsm.isSelectionEmpty()) {
// indexSelect = lsm.getMinSelectionIndex();
node evaluation = chargeEvaluation.retourneEvaluationSelected(indexSelect);
String nomFichierAnalyse = "";
if(evaluation.retourneFirstEnfantsByName("fichier").getAttributs().get("analysis_filename")!=null) {
nomFichierAnalyse = evaluation.retourneFirstEnfantsByName("fichier").getAttributs().get("analysis_filename");
}
JPanel panel = new JPanel();
JLabel Text = new JLabel();
Text.setText("<html><p>Renommer le fichier d'analyse avec le nom : </p></html>");
panel.add(Text);
nomFichierAnalyse = JOptionPane.showInputDialog(null,panel, nomFichierAnalyse);
if(nomFichierAnalyse!=null) {
if(nomFichierAnalyse!=null) {
if(!nomFichierAnalyse.isBlank()) {
Pattern pt = Pattern.compile("\\.xml$");
Matcher match= pt.matcher(nomFichierAnalyse);
if(!match.find()) {
nomFichierAnalyse = nomFichierAnalyse + ".xml";
}
evaluation.retourneFirstEnfantsByName("fichier").getAttributs().put("analysis_filename", nomFichierAnalyse);
evaluation.retourneFirstEnfantsByName("fichier").getAttributs().put("filenameAnalyse", nomFichierAnalyse);
evaluation.getAttributs().put("analysis_filename", nomFichierAnalyse);
new creerNouvelleEvaluation(evaluation);
new recupeNodeBaseEvaluations();
model.addOrUpdate();
table.setModel(model);
}
}
}
}
}
});
/**
* Renommer une évaluation sélectionnée.
*/
btnRenommerEvaluation.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(lsm!=null)if (!lsm.isSelectionEmpty()) {
indexSelect = lsm.getMinSelectionIndex();
node evaluation = chargeEvaluation.retourneEvaluationSelected(indexSelect);
String nomEvaluation = "";
if(evaluation.getAttributs().get("name")!=null) {
nomEvaluation = evaluation.getAttributs().get("name");
}
nomEvaluation = JOptionPane.showInputDialog(null,"Renommer cette évaluation ?",nomEvaluation);
if(!nomEvaluation.isBlank()) {
evaluation.getAttributs().put("name",nomEvaluation);
new creerNouvelleEvaluation(evaluation);
new recupeNodeBaseEvaluations();
model.addOrUpdate();
table = new JTable(model);
}
}
}
});
}
}