2022-11-26 19:46:16 +01:00
|
|
|
package Test;
|
|
|
|
|
|
|
|
import API.Etudiant;
|
|
|
|
import API.Groupe;
|
|
|
|
|
2022-11-27 14:16:11 +01:00
|
|
|
// TODO: Trier ca pour faire un import par package utilises (j'ai eu la flemme de le faire)
|
2022-11-27 14:14:19 +01:00
|
|
|
import javax.swing.*;
|
2022-11-27 14:16:11 +01:00
|
|
|
import java.awt.*;
|
|
|
|
|
2022-11-27 13:10:18 +01:00
|
|
|
import javax.swing.event.ListSelectionEvent;
|
|
|
|
import javax.swing.event.ListSelectionListener;
|
|
|
|
import javax.swing.table.TableModel;
|
2022-11-26 19:46:16 +01:00
|
|
|
import java.awt.event.ActionEvent;
|
|
|
|
import java.awt.event.ActionListener;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Objects;
|
2022-11-27 13:10:18 +01:00
|
|
|
|
|
|
|
public class Controller implements ActionListener, ListSelectionListener {
|
2022-11-26 19:46:16 +01:00
|
|
|
private final BDatabase db;
|
2022-11-27 18:27:50 +01:00
|
|
|
|
2022-11-26 19:46:16 +01:00
|
|
|
private final ProfView pv;
|
|
|
|
private final AdminView av;
|
2022-11-27 18:27:50 +01:00
|
|
|
|
|
|
|
private BFrame lastModal;
|
|
|
|
private BFrame currentModal;
|
|
|
|
|
2022-11-26 19:46:16 +01:00
|
|
|
private final ArrayList<Etudiant> e;
|
|
|
|
private final ArrayList<Groupe> g;
|
2022-11-27 18:27:50 +01:00
|
|
|
|
2022-11-27 13:10:18 +01:00
|
|
|
private JTable currentJTableUse;
|
2022-11-27 18:27:50 +01:00
|
|
|
private JComboBox<String> list;
|
|
|
|
|
|
|
|
private String[] tmpStud;
|
2022-11-26 19:46:16 +01:00
|
|
|
|
|
|
|
public Controller(ArrayList<Etudiant> e, ArrayList<Groupe> g) {
|
|
|
|
this.e = e;
|
|
|
|
this.g = g;
|
|
|
|
this.db = new BDatabase();
|
|
|
|
this.pv = new ProfView(e, g, this);
|
|
|
|
System.out.println("[+] Demarrage de la vue professeur -> " + pv);
|
|
|
|
this.av = new AdminView(e, g, this);
|
|
|
|
System.out.println("[+] Demarrage de la vue Administrateur -> " + av);
|
|
|
|
}
|
|
|
|
|
2022-11-27 13:10:18 +01:00
|
|
|
/**
|
|
|
|
* Pour creer une JTable
|
|
|
|
* @param data Les donnees
|
|
|
|
* @param title Les titres
|
|
|
|
* */
|
|
|
|
private JTable createJTable(Object[][] data, String[] title) {
|
|
|
|
return new JTable(data, title) {
|
|
|
|
public boolean editCellAt(int row, int column, java.util.EventObject e) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-11-27 13:36:53 +01:00
|
|
|
* Pour afficher une JTable sans listener
|
|
|
|
*
|
|
|
|
* @param parent La fenetre qui sera bloque
|
|
|
|
* @param frameTitle Le titre de la fenetre
|
|
|
|
* @param size_x Taille en x
|
|
|
|
* @param size_y Taille en y
|
|
|
|
* @param loca_x Localisation en x
|
|
|
|
* @param loca_y Localisation en y
|
2022-11-27 13:10:18 +01:00
|
|
|
* @param liste La JTable
|
|
|
|
* */
|
2022-11-27 13:36:53 +01:00
|
|
|
private void Display(BFrame parent, String frameTitle, int size_x, int size_y, int loca_x, int loca_y, JTable liste) {
|
|
|
|
JPanel forModal = new JPanel();
|
|
|
|
|
|
|
|
ListSelectionModel lsm = liste.getSelectionModel();
|
2022-11-27 13:10:18 +01:00
|
|
|
liste.getTableHeader().setReorderingAllowed(false);
|
|
|
|
liste.setFillsViewportHeight(true);
|
|
|
|
|
|
|
|
this.currentJTableUse = liste;
|
|
|
|
|
2022-11-27 13:36:53 +01:00
|
|
|
forModal.add(liste);
|
2022-11-27 13:10:18 +01:00
|
|
|
|
2022-11-27 13:36:53 +01:00
|
|
|
BFrame frame = new BFrame(frameTitle, loca_x, loca_y, size_x, size_y, parent, forModal);
|
2022-11-27 13:10:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Pour afficher une JTable contenant un listener
|
2022-11-27 13:36:53 +01:00
|
|
|
*
|
|
|
|
* @param parent La fenetre qui sera bloque
|
|
|
|
* @param frameTitle Le titre de la fenetre
|
|
|
|
* @param size_x Taille en x
|
|
|
|
* @param size_y Taille en y
|
|
|
|
* @param loca_x Localisation en x
|
|
|
|
* @param loca_y Localisation en y
|
2022-11-27 13:10:18 +01:00
|
|
|
* @param liste La JTable
|
|
|
|
* */
|
2022-11-27 13:36:53 +01:00
|
|
|
private void DisplayWithListner(BFrame parent, String frameTitle, int size_x, int size_y, int loca_x, int loca_y, JTable liste) {
|
2022-11-27 13:10:18 +01:00
|
|
|
JPanel forModal = new JPanel();
|
|
|
|
|
|
|
|
ListSelectionModel lsm = liste.getSelectionModel();
|
|
|
|
lsm.addListSelectionListener(this);
|
|
|
|
liste.getTableHeader().setReorderingAllowed(false);
|
|
|
|
liste.setFillsViewportHeight(true);
|
|
|
|
|
|
|
|
this.currentJTableUse = liste;
|
|
|
|
|
|
|
|
forModal.add(liste);
|
|
|
|
|
2022-11-27 13:36:53 +01:00
|
|
|
BFrame frame = new BFrame(frameTitle, loca_x, loca_y, size_x, size_y, parent, forModal);
|
2022-11-27 13:10:18 +01:00
|
|
|
}
|
|
|
|
|
2022-11-27 14:14:19 +01:00
|
|
|
/**
|
|
|
|
* Pour afficher une modale classique pour plus de liberte (panel a creer au prealable)
|
|
|
|
*
|
|
|
|
* @param parent La fenetre qui sera bloque
|
|
|
|
* @param frameTitle Le titre de la fenetre
|
|
|
|
* @param size_x Taille en x
|
|
|
|
* @param size_y Taille en y
|
|
|
|
* @param loca_x Localisation en x
|
|
|
|
* @param loca_y Localisation en y
|
|
|
|
* @param forModal Le panel a mettre dans la fenetre (libre)
|
|
|
|
* */
|
2022-11-27 18:27:50 +01:00
|
|
|
private void DisplayModal(BFrame parent, String frameTitle, int size_x, int size_y, int loca_x, int loca_y, JPanel forModal) {
|
|
|
|
this.currentModal = new BFrame(frameTitle, loca_x, loca_y, size_x, size_y, parent, forModal);
|
2022-11-27 14:14:19 +01:00
|
|
|
}
|
|
|
|
|
2022-11-26 19:46:16 +01:00
|
|
|
@Override
|
|
|
|
public void actionPerformed(ActionEvent e) {
|
|
|
|
String command = e.getActionCommand();
|
|
|
|
|
|
|
|
String groupeOption = this.pv.getComboSelection();
|
|
|
|
int groupeIndex = this.pv.getComboSelectionIndex();
|
|
|
|
String text = this.pv.getSearchStud();
|
|
|
|
|
2022-11-26 20:34:37 +01:00
|
|
|
if(Objects.equals(command, "pv::GetStudList")) {
|
2022-11-26 19:46:16 +01:00
|
|
|
String[][] data = new String[this.e.size()][2];
|
|
|
|
|
|
|
|
String[] titre = {
|
|
|
|
"Nom",
|
|
|
|
"Prenom",
|
|
|
|
"Groupe"
|
|
|
|
};
|
|
|
|
|
|
|
|
for(int i = 0; i <= this.e.size()-1; i++) {
|
|
|
|
String[] info = {
|
|
|
|
this.e.get(i).getNom(),
|
|
|
|
this.e.get(i).getPrenom(),
|
|
|
|
String.valueOf(this.e.get(i).getGroupe())
|
|
|
|
};
|
|
|
|
|
|
|
|
data[i] = info;
|
|
|
|
}
|
|
|
|
|
2022-11-27 13:36:53 +01:00
|
|
|
Display(
|
|
|
|
this.pv,
|
|
|
|
"Liste des etudiants",
|
|
|
|
350,
|
|
|
|
400,
|
|
|
|
this.pv.getX(),
|
|
|
|
this.pv.getY(),
|
|
|
|
this.createJTable(data, titre)
|
|
|
|
);
|
2022-11-26 19:46:16 +01:00
|
|
|
}
|
|
|
|
|
2022-11-26 20:34:37 +01:00
|
|
|
else if(Objects.equals(command, "pv::GetListFiltered")) {
|
2022-11-26 19:46:16 +01:00
|
|
|
String[][] data = new String[this.e.size()][1];
|
|
|
|
|
|
|
|
String[] titre = {
|
|
|
|
"Nom",
|
|
|
|
"Prenom"
|
|
|
|
};
|
|
|
|
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
for(i = 0, j = 0; i <= this.e.size()-1; i++) {
|
|
|
|
if(this.e.get(i).getGroupe() == groupeIndex) {
|
|
|
|
String[] info = {
|
|
|
|
this.e.get(i).getNom(),
|
|
|
|
this.e.get(i).getPrenom()
|
|
|
|
};
|
|
|
|
|
|
|
|
data[j] = info;
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
String[][] data_final = new String[j][1];
|
|
|
|
for(int x = 0; x <= j-1; x++) {
|
|
|
|
data_final[x] = data[x];
|
|
|
|
}
|
|
|
|
|
2022-11-27 13:36:53 +01:00
|
|
|
Display(
|
|
|
|
this.pv,
|
|
|
|
"Liste d'eleve du " + groupeOption,
|
|
|
|
350,
|
|
|
|
400,
|
|
|
|
this.pv.getX(),
|
|
|
|
this.pv.getY(),
|
|
|
|
this.createJTable(data_final, titre)
|
|
|
|
);
|
2022-11-26 19:46:16 +01:00
|
|
|
}
|
|
|
|
|
2022-11-26 20:34:37 +01:00
|
|
|
else if(Objects.equals(command, "pv::SearchStudentPer3Letters")) {
|
2022-11-26 19:46:16 +01:00
|
|
|
if(text.length() < 3 || text == null) {
|
|
|
|
JOptionPane.showMessageDialog(
|
|
|
|
this.pv,
|
|
|
|
"Veuillez ecrire 3 lettres",
|
|
|
|
"Erreur.",
|
|
|
|
JOptionPane.ERROR_MESSAGE
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
char[] beg = text.toCharArray();
|
|
|
|
|
|
|
|
ArrayList<String> filtreEleveNom = db.fetchAll("SELECT nom FROM fi_eleves WHERE nom LIKE '" + beg[0] + beg[1] + beg[2] + "%'");
|
|
|
|
ArrayList<String> filtreElevePrenom = db.fetchAll("SELECT prenom FROM fi_eleves WHERE nom LIKE '" + beg[0] + beg[1] + beg[2] + "%'");
|
|
|
|
ArrayList<String> filtreEleveGroupe = db.fetchAll("SELECT groupe FROM fi_eleves WHERE nom LIKE '" + beg[0] + beg[1] + beg[2] + "%'");
|
|
|
|
|
|
|
|
System.out.println(filtreEleveGroupe.size() + filtreElevePrenom.size() + filtreEleveGroupe.size());
|
|
|
|
|
|
|
|
if(filtreEleveGroupe.size() == 0 || filtreEleveNom.size() == 0 || filtreElevePrenom.size() == 0) {
|
|
|
|
JOptionPane.showMessageDialog(
|
|
|
|
this.pv,
|
|
|
|
"Eleve introuvable !",
|
|
|
|
"Erreur.",
|
|
|
|
JOptionPane.ERROR_MESSAGE
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
String[] titre = {
|
|
|
|
"Nom",
|
|
|
|
"Prenom",
|
|
|
|
"Groupe"
|
|
|
|
};
|
|
|
|
|
|
|
|
String[][] data = new String[filtreEleveNom.size()][2];
|
|
|
|
|
|
|
|
for(int i = 0; i <= filtreEleveNom.size()-1; i++){
|
|
|
|
data[i] = new String[]{
|
|
|
|
filtreEleveNom.get(i),
|
|
|
|
filtreElevePrenom.get(i),
|
|
|
|
String.valueOf(filtreEleveGroupe.get(i))
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-11-27 13:36:53 +01:00
|
|
|
Display(
|
|
|
|
this.pv,
|
|
|
|
"Recherche",
|
|
|
|
350,
|
|
|
|
400,
|
|
|
|
this.pv.getX(),
|
|
|
|
this.pv.getY(),
|
|
|
|
this.createJTable(data, titre)
|
|
|
|
);
|
2022-11-26 19:46:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-11-26 20:34:37 +01:00
|
|
|
|
2022-11-26 22:30:18 +01:00
|
|
|
else if(Objects.equals(command, "av::MoveStudGrup")) {
|
2022-11-27 13:36:53 +01:00
|
|
|
Object[][] data = new Object[this.e.size()][3];
|
2022-11-26 22:30:18 +01:00
|
|
|
|
2022-11-27 13:10:18 +01:00
|
|
|
String[] titre = {
|
|
|
|
"Nom",
|
|
|
|
"Prenom",
|
2022-11-27 13:36:53 +01:00
|
|
|
"Groupe",
|
|
|
|
"Action"
|
2022-11-26 22:30:18 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
for(int i = 0; i <= this.e.size()-1; i++) {
|
|
|
|
Object[] info = {
|
2022-11-27 13:10:18 +01:00
|
|
|
this.e.get(i).getNom(),
|
|
|
|
this.e.get(i).getPrenom(),
|
|
|
|
String.valueOf(this.e.get(i).getGroupe()),
|
2022-11-27 13:36:53 +01:00
|
|
|
"[DEPLACER]"
|
2022-11-26 22:30:18 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
data[i] = info;
|
|
|
|
}
|
|
|
|
|
2022-11-27 13:36:53 +01:00
|
|
|
DisplayWithListner(
|
|
|
|
this.av,
|
|
|
|
"Deplacer un etudiant",
|
|
|
|
350,
|
|
|
|
400,
|
|
|
|
this.av.getX(),
|
|
|
|
this.av.getY(),
|
|
|
|
this.createJTable(data, titre)
|
|
|
|
);
|
2022-11-26 20:34:37 +01:00
|
|
|
}
|
2022-11-27 18:27:50 +01:00
|
|
|
|
|
|
|
else if(Objects.equals(command, "crtll::ActionMoveGrup")) {
|
|
|
|
// TODO: CHANGE GROUPE
|
|
|
|
db.updateRow("UPDATE fi_eleves SET ");
|
|
|
|
|
|
|
|
JOptionPane.showMessageDialog(
|
|
|
|
this.currentModal,
|
|
|
|
this.tmpStud[0] + " " + this.tmpStud[1] + " a bien ete deplace dans le " + this.list.getSelectedItem(),
|
|
|
|
"Deplacement effectue",
|
|
|
|
JOptionPane.INFORMATION_MESSAGE
|
|
|
|
);
|
|
|
|
}
|
2022-11-26 19:46:16 +01:00
|
|
|
}
|
|
|
|
|
2022-11-27 13:10:18 +01:00
|
|
|
@Override
|
|
|
|
public void valueChanged(ListSelectionEvent e) {
|
2022-11-27 14:14:19 +01:00
|
|
|
if(!e.getValueIsAdjusting()) {
|
|
|
|
int[] cell = this.currentJTableUse.getSelectedRows();
|
|
|
|
int collumnCount = this.currentJTableUse.getColumnCount();
|
|
|
|
Object value;
|
|
|
|
System.out.println(e.getSource());
|
|
|
|
|
|
|
|
if(cell.length > 0) {
|
|
|
|
for(int i = 0; i < collumnCount; i++) {
|
2022-11-27 13:10:18 +01:00
|
|
|
TableModel tm = this.currentJTableUse.getModel();
|
2022-11-27 13:36:53 +01:00
|
|
|
value = tm.getValueAt(cell[0], i);
|
2022-11-26 19:46:16 +01:00
|
|
|
|
2022-11-27 14:14:19 +01:00
|
|
|
if(Objects.equals(value, "[DEPLACER]")) {
|
|
|
|
JPanel forModal = new JPanel(new GridBagLayout());
|
|
|
|
BLayout settings = new BLayout();
|
2022-11-27 18:27:50 +01:00
|
|
|
this.tmpStud = new String[] {
|
|
|
|
(String) tm.getValueAt(cell[0], 0),
|
|
|
|
(String) tm.getValueAt(cell[0], 1)
|
|
|
|
};
|
|
|
|
|
|
|
|
settings.setPositionX(0);
|
|
|
|
settings.setPositionY(0);
|
|
|
|
JLabel intro = new JLabel(
|
|
|
|
"Deplacer " + tm.getValueAt(cell[0], 0) + " " +
|
|
|
|
tm.getValueAt(cell[0], 1) +
|
|
|
|
" dans le groupe : "
|
|
|
|
);
|
|
|
|
forModal.add(intro, settings);
|
|
|
|
|
|
|
|
settings.setPositionX(1);
|
|
|
|
settings.setPositionY(0);
|
|
|
|
forModal.add(new JLabel(" "), settings);
|
|
|
|
|
|
|
|
settings.setPositionX(2);
|
|
|
|
settings.setPositionY(0);
|
|
|
|
forModal.add(new JLabel(" "), settings);
|
|
|
|
|
|
|
|
settings.setPositionX(3);
|
|
|
|
settings.setPositionY(0);
|
|
|
|
|
|
|
|
this.list = new JComboBox<>();
|
|
|
|
|
|
|
|
for (Groupe groupe : this.g) {
|
|
|
|
this.list.addItem(groupe.getName());
|
|
|
|
}
|
|
|
|
|
|
|
|
forModal.add(list, settings);
|
|
|
|
|
|
|
|
settings.setPositionX(4);
|
|
|
|
settings.setPositionY(0);
|
|
|
|
forModal.add(new JLabel(" "), settings);
|
|
|
|
|
|
|
|
settings.setPositionX(5);
|
|
|
|
settings.setPositionY(0);
|
|
|
|
forModal.add(new JLabel(" "), settings);
|
2022-11-27 14:14:19 +01:00
|
|
|
|
2022-11-27 18:27:50 +01:00
|
|
|
settings.setPositionX(6);
|
|
|
|
settings.setPositionY(0);
|
|
|
|
JButton moveBtn = new JButton("Deplacer");
|
|
|
|
moveBtn.setActionCommand("crtll::ActionMoveGrup");
|
|
|
|
moveBtn.addActionListener(this);
|
|
|
|
forModal.add(moveBtn, settings);
|
2022-11-27 14:14:19 +01:00
|
|
|
|
|
|
|
DisplayModal(
|
|
|
|
this.av,
|
2022-11-27 18:27:50 +01:00
|
|
|
"Deplacer l'eleve : "
|
|
|
|
+ tm.getValueAt(cell[0], 0) + " " + tm.getValueAt(cell[0], 1),
|
2022-11-27 14:14:19 +01:00
|
|
|
500,
|
|
|
|
250,
|
|
|
|
this.av.getX(),
|
|
|
|
this.av.getY(),
|
2022-11-27 18:27:50 +01:00
|
|
|
forModal
|
2022-11-27 14:14:19 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2022-11-27 13:10:18 +01:00
|
|
|
}
|
|
|
|
}
|
2022-11-26 19:46:16 +01:00
|
|
|
}
|
|
|
|
}
|