Subversion Repositories eFlore/Applications.coel

Rev

Rev 60 | Rev 64 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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