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 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
|
public class DialogueNavigueCompte extends JDialog{
String libelleCompte = "";
DaoCompte daoCompte = new DaoCompte();
JList JlistCompte;
JFrame fenetre;
public DialogueNavigueCompte(JFrame f, String titre, boolean modal, String libelleCompte){
super(f,titre, modal);
Init(libelleCompte);
this.fenetre = f;
}
// récupère les données mises à jour par la boîte de dialogue
public Object [] getDonnees(){
return new Object[]{libelleCompte};
}
/**
* Action du bouton Annuler
* @param e
*/
void jButtonCANCEL_actionPerformed(ActionEvent e) {
setVisible(false);
}
/**
* Action du bouton OK
* @param e
*/
void jButtonOK_actionPerformed(ActionEvent e) {
if (JlistCompte.getSelectedValue() != null){
libelleCompte = JlistCompte.getSelectedValue().toString();
if (libelleCompte.equals("Créer un nouveau compte")){
libelleCompte = "";
DialogueCreateCompte dcc = new DialogueCreateCompte(fenetre, "Création de compte", true,"");
dcc.pack();
//créer le compte et renvoie le libelle
String libelle = "";
String numero = "";
boolean achat = false;
boolean vente = false;
boolean treso = false;
dcc.setVisible(true);
Object [] retour = dcc.getDonnees();
if (retour != null){
libelle = retour[0].toString();
numero = retour[1].toString();
achat = (Boolean)retour[2];
vente = (Boolean)retour[3];
treso = (Boolean)retour[4];
if (!numero.equals("") && !numero.equals("0")){
int result = 1;
try {
result = Comptes.creeCompte(libelle, numero, achat, vente, treso);
} catch (BusinessException be) {
Erreurs.Warning(be);
}
if (result == 0){
libelleCompte = libelle;
}
}
}
}
setVisible(false);
}
}
/**
* Gère l'interface pour le choix du compte
* @param libelleCompte
*/
private void Init(String libelleCpt) {
JPanel panelChoix = new JPanel();
panelChoix.setLayout(new GridBagLayout());
JButton jbtAnnuler = new JButton("Annuler");
jbtAnnuler.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ev) {
jButtonCANCEL_actionPerformed(ev);
}
});
JButton jbtOk = new JButton("Sélectionner");
jbtOk.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ev) {
jButtonOK_actionPerformed(ev);
}
});
//affiche les comptes qui commencent par libelleCompte
List<Compte> listeCompte = new ArrayList<Compte>();
//si le libelleCpt est un entier rechercher tous les comptes qui commencent
//avec ce numéro
try{
@SuppressWarnings("unused")
int numCpt = Integer.parseInt(libelleCpt);
try {
listeCompte = daoCompte.getAllComptesByNumero(libelleCpt);
} catch (BusinessException be) {
Erreurs.Warning(be);
}
}catch(NumberFormatException ne){
try {
listeCompte = daoCompte.getAllComptesByLibelle(libelleCpt);
} catch (BusinessException be) {
Erreurs.Warning(be);
be.printStackTrace();
}
}
String[] listeLibelleCompte = new String[listeCompte.size()+1];
int i = 0;
for (Compte unCompte : listeCompte){
listeLibelleCompte[i] = unCompte.getLibelle()+" ["+unCompte.getNumero()+"]";
i++;
}
//Ajouter le compte créer un compte
listeLibelleCompte[i] = "Créer un nouveau compte";
JlistCompte = new JList(listeLibelleCompte);
if (listeLibelleCompte.length>0){
JlistCompte.setSelectedIndex(0);
}
//ajoute un keylistener pour valider la sélection avec entrée
//et fermer la fenetre avec echap
JlistCompte.addKeyListener(new KeyListener(){
public void keyPressed(KeyEvent arg0) {}
public void keyReleased(KeyEvent arg0) {}
public void keyTyped(KeyEvent ev) {
if (ev.getKeyChar() == KeyEvent.VK_ENTER){
jButtonOK_actionPerformed(null);
}
if (ev.getKeyChar() == KeyEvent.VK_ESCAPE){
jButtonCANCEL_actionPerformed(null);
}
}
});
panelChoix.add(new JScrollPane(JlistCompte), new GBC(0,0,1,2));
panelChoix.add(jbtOk, new GBC(1,0));
panelChoix.add(jbtAnnuler, new GBC(1,1));
//positionner le jdialog
setLocation(200, 100);
this.setPreferredSize(new Dimension(450,200));
this.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
this.setResizable(false);
this.pack();
this.add(panelChoix);
}
} |
Partager