| 60 |
jpm |
1 |
package org.tela_botanica.client.composants;
|
|
|
2 |
|
|
|
3 |
/*
|
|
|
4 |
* Ext GWT - Ext for GWT
|
|
|
5 |
* Copyright(c) 2007, 2008, Ext JS, LLC.
|
|
|
6 |
* licensing@extjs.com
|
|
|
7 |
*
|
|
|
8 |
* http://extjs.com/license
|
|
|
9 |
*/
|
| 61 |
jpm |
10 |
import org.tela_botanica.client.Mediateur;
|
|
|
11 |
import org.tela_botanica.client.RegistreId;
|
|
|
12 |
|
|
|
13 |
import com.extjs.gxt.ui.client.Registry;
|
| 60 |
jpm |
14 |
import com.extjs.gxt.ui.client.event.ButtonEvent;
|
|
|
15 |
import com.extjs.gxt.ui.client.event.ComponentEvent;
|
|
|
16 |
import com.extjs.gxt.ui.client.event.KeyListener;
|
|
|
17 |
import com.extjs.gxt.ui.client.event.SelectionListener;
|
|
|
18 |
import com.extjs.gxt.ui.client.widget.Dialog;
|
|
|
19 |
import com.extjs.gxt.ui.client.widget.button.Button;
|
|
|
20 |
import com.extjs.gxt.ui.client.widget.button.StatusButtonBar;
|
|
|
21 |
import com.extjs.gxt.ui.client.widget.form.TextField;
|
|
|
22 |
import com.extjs.gxt.ui.client.widget.layout.FormLayout;
|
|
|
23 |
import com.google.gwt.user.client.Timer;
|
|
|
24 |
|
|
|
25 |
public class IdentificationFenetre extends Dialog {
|
|
|
26 |
|
| 66 |
jpm |
27 |
protected StatusButtonBar barreDeBoutons;
|
|
|
28 |
protected TextField<String> login;
|
|
|
29 |
protected TextField<String> motDePasse;
|
|
|
30 |
protected Button reinitialiserBouton;
|
|
|
31 |
protected Button validerBouton;
|
| 60 |
jpm |
32 |
|
| 61 |
jpm |
33 |
public IdentificationFenetre() {
|
|
|
34 |
FormLayout layout = new FormLayout();
|
|
|
35 |
layout.setLabelWidth(90);
|
|
|
36 |
layout.setDefaultWidth(155);
|
|
|
37 |
setLayout(layout);
|
| 60 |
jpm |
38 |
|
| 61 |
jpm |
39 |
setButtons("");
|
| 69 |
jpm |
40 |
setIconStyle("icone-utilisateur");
|
| 61 |
jpm |
41 |
setHeading("Collections en ligne - Identification");
|
|
|
42 |
setModal(true);
|
|
|
43 |
setBodyBorder(true);
|
|
|
44 |
setBodyStyle("padding: 10px;background: none");
|
| 64 |
jpm |
45 |
setWidth(310);
|
| 61 |
jpm |
46 |
setResizable(false);
|
| 64 |
jpm |
47 |
setAutoWidth(false);
|
|
|
48 |
|
| 61 |
jpm |
49 |
KeyListener keyListener = new KeyListener() {
|
|
|
50 |
public void componentKeyUp(ComponentEvent event) {
|
|
|
51 |
validate();
|
|
|
52 |
}
|
| 60 |
jpm |
53 |
|
| 61 |
jpm |
54 |
};
|
| 60 |
jpm |
55 |
|
| 66 |
jpm |
56 |
login = new TextField<String>();
|
|
|
57 |
login.setMinLength(4);
|
|
|
58 |
login.setFieldLabel("Courriel");
|
|
|
59 |
login.addKeyListener(keyListener);
|
|
|
60 |
add(login);
|
| 60 |
jpm |
61 |
|
| 66 |
jpm |
62 |
motDePasse = new TextField<String>();
|
|
|
63 |
motDePasse.setMinLength(4);
|
|
|
64 |
motDePasse.setPassword(true);
|
|
|
65 |
motDePasse.setFieldLabel("Mot de passe");
|
|
|
66 |
motDePasse.addKeyListener(keyListener);
|
|
|
67 |
add(motDePasse);
|
| 60 |
jpm |
68 |
|
| 66 |
jpm |
69 |
setFocusWidget(login);
|
| 60 |
jpm |
70 |
|
| 66 |
jpm |
71 |
barreDeBoutons = new StatusButtonBar();
|
|
|
72 |
setButtonBar(barreDeBoutons);
|
| 61 |
jpm |
73 |
|
|
|
74 |
}
|
| 277 |
jp_milcent |
75 |
|
| 61 |
jpm |
76 |
@Override
|
|
|
77 |
protected void createButtons() {
|
| 66 |
jpm |
78 |
reinitialiserBouton = new Button("Réinitialiser");
|
|
|
79 |
reinitialiserBouton.addSelectionListener(new SelectionListener<ButtonEvent>() {
|
| 61 |
jpm |
80 |
public void componentSelected(ButtonEvent ce) {
|
| 66 |
jpm |
81 |
login.reset();
|
|
|
82 |
motDePasse.reset();
|
| 61 |
jpm |
83 |
validate();
|
| 66 |
jpm |
84 |
login.focus();
|
| 61 |
jpm |
85 |
}
|
| 60 |
jpm |
86 |
|
| 61 |
jpm |
87 |
});
|
| 60 |
jpm |
88 |
|
| 66 |
jpm |
89 |
validerBouton = new Button("Valider");
|
| 61 |
jpm |
90 |
//login.disable(); // Par défaut : dois être en mode disable
|
| 66 |
jpm |
91 |
validerBouton.addSelectionListener(new SelectionListener<ButtonEvent>() {
|
| 61 |
jpm |
92 |
public void componentSelected(ButtonEvent ce) {
|
|
|
93 |
onSubmit();
|
|
|
94 |
}
|
|
|
95 |
});
|
| 60 |
jpm |
96 |
|
| 66 |
jpm |
97 |
barreDeBoutons.add(reinitialiserBouton);
|
|
|
98 |
barreDeBoutons.add(validerBouton);
|
| 61 |
jpm |
99 |
}
|
| 60 |
jpm |
100 |
|
| 61 |
jpm |
101 |
protected void onSubmit() {
|
| 66 |
jpm |
102 |
barreDeBoutons.getStatusBar().showBusy("Chargement en cours ...");
|
|
|
103 |
barreDeBoutons.disable();
|
| 61 |
jpm |
104 |
Timer t = new Timer() {
|
| 60 |
jpm |
105 |
|
| 61 |
jpm |
106 |
@Override
|
|
|
107 |
public void run() {
|
|
|
108 |
IdentificationFenetre.this.hide();
|
| 66 |
jpm |
109 |
((Mediateur) Registry.get(RegistreId.MEDIATEUR)).connecterUtilisateur(login.getValue(), motDePasse.getValue());
|
| 61 |
jpm |
110 |
}
|
| 60 |
jpm |
111 |
|
| 61 |
jpm |
112 |
};
|
|
|
113 |
t.schedule(2);// Par défaut : 2000
|
|
|
114 |
}
|
| 60 |
jpm |
115 |
|
| 61 |
jpm |
116 |
protected boolean hasValue(TextField<String> field) {
|
|
|
117 |
return field.getValue() != null && field.getValue().length() > 0;
|
|
|
118 |
}
|
| 60 |
jpm |
119 |
|
| 61 |
jpm |
120 |
protected void validate() {
|
| 66 |
jpm |
121 |
validerBouton.setEnabled(hasValue(login) && hasValue(motDePasse) && motDePasse.getValue().length() > 3);
|
| 61 |
jpm |
122 |
}
|
| 277 |
jp_milcent |
123 |
|
| 60 |
jpm |
124 |
}
|