1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
| public class SocietePanel extends javax.swing.JPanel{
//Données significatives
private static Societe societe;
private Session currentSession
private JXTable tHisto
private void initGUI() {
...
//JTable allant contenir respectivement l'historique des modifications et la liste des sociétés du groupe
tHisto = new JXTable();
tSocGroupe = new JXTable();
//Initialisation de l'interface graphique
this.addComponentListener(new ComponentListener() {
@Override
public void componentShown(ComponentEvent e) {
currentSession = HibernateUtil.getSessionFactory().openSession();
System.out.println("SocietePanel - Session Opened");
//Reattachement de la socieété
currentSession.update(societe);
try {
populateData(societe);
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
@Override
public void componentResized(ComponentEvent e) {
System.out.println(e);
@Override
public void componentMoved(ComponentEvent e) {
System.out.println(e);
}
@Override
public void componentHidden(ComponentEvent e) {
if(currentSession != null) {
currentSession.close();
System.out.println("SocietePanel - Session Closed");
societe = null;
}
}
});
}
private void populateData(final Societe s) throws Exception {
Runnable loadData = new Runnable() {
@Override
public void run() {
try {
initHist(s);
initGroupe(s);
societe = s;
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
};
Thread t = new Thread(loadData);
t.start();
}
public static void setSociete(Societe s) {
societe = s;
}
private void initHist(final Societe s) {
EventList<HistoriqueSociete> lstHist = GlazedLists.eventList(s.getHistorique());
String[] prop = {"champ", "oldValue", "newValue", "commiter", "dateModif"};
String[] col = {"Champ", "Ancienne valeur", "Nouvelle valeur", "Utilisateur", "Date de modification"};
TableFormat<HistoriqueSociete> tf = GlazedLists.tableFormat(HistoriqueSociete.class, prop, col);
EventTableModel<HistoriqueSociete> etm = new EventTableModel<HistoriqueSociete>(lstHist, tf);
tHisto.setModel(etm);
}
private void initGroupe(final Societe s) {
if(s.getGroupe() != null) {
Groupe grp = s.getGroupe();
//Ligne qui déclenche l'exception
EventList<Societe> lstSoc = GlazedLists.eventList(grp.getSocietes());
String[] prop = {"nom", "countryTel", "tel", "countryFax", "fax", "cp", "ville", "mail", "adresse1", "adresse2", "adresse3", "commercial", "secteur", "statut", "recommanded", "effectif", "porteurs", "groupe", "categorie", "solvabilite", "naf"};
String[] col = {"Nom", "Indic. Pays", "Telephone", "Indic. Pays", "Fax", "Code Postal", "Ville", "E-mail", "Adresse 1", "Adresse 2", "Adresse 3", "Commercial", "Secteur", "Statut", "Recommandé par", "Effectif", "Porteurs", "Groupe", "Categorie", "Solvabilité", "Code NAF"};
TableFormat<Societe> tf = GlazedLists.tableFormat(Societe.class, prop, col);
EventTableModel<Societe> etm = new EventTableModel<Societe>(lstSoc, tf);
tSocGroupe.setModel(etm);
esm = new EventSelectionModel<Societe>(lstSoc);
tSocGroupe.setSelectionModel(esm);
}
}
} |
Partager