Subversion Repositories eFlore/Applications.coel

Rev

Rev 66 | Rev 277 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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