Rev 69 | Rev 498 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
package org.tela_botanica.client.composants;/** Ext GWT - Ext for GWT* Copyright(c) 2007, 2008, Ext JS, LLC.* licensing@extjs.com** http://extjs.com/license*/import org.tela_botanica.client.Mediateur;import org.tela_botanica.client.RegistreId;import com.extjs.gxt.ui.client.Registry;import com.extjs.gxt.ui.client.event.ButtonEvent;import com.extjs.gxt.ui.client.event.ComponentEvent;import com.extjs.gxt.ui.client.event.KeyListener;import com.extjs.gxt.ui.client.event.SelectionListener;import com.extjs.gxt.ui.client.widget.Dialog;import com.extjs.gxt.ui.client.widget.button.Button;import com.extjs.gxt.ui.client.widget.button.StatusButtonBar;import com.extjs.gxt.ui.client.widget.form.TextField;import com.extjs.gxt.ui.client.widget.layout.FormLayout;import com.google.gwt.user.client.Timer;public class IdentificationFenetre extends Dialog {protected StatusButtonBar barreDeBoutons;protected TextField<String> login;protected TextField<String> motDePasse;protected Button reinitialiserBouton;protected Button validerBouton;public IdentificationFenetre() {FormLayout layout = new FormLayout();layout.setLabelWidth(90);layout.setDefaultWidth(155);setLayout(layout);setButtons("");setIconStyle("icone-utilisateur");setHeading("Collections en ligne - Identification");setModal(true);setBodyBorder(true);setBodyStyle("padding: 10px;background: none");setWidth(310);setResizable(false);setAutoWidth(false);KeyListener keyListener = new KeyListener() {public void componentKeyUp(ComponentEvent event) {validate();}};login = new TextField<String>();login.setMinLength(4);login.setFieldLabel("Courriel");login.addKeyListener(keyListener);add(login);motDePasse = new TextField<String>();motDePasse.setMinLength(4);motDePasse.setPassword(true);motDePasse.setFieldLabel("Mot de passe");motDePasse.addKeyListener(keyListener);add(motDePasse);setFocusWidget(login);barreDeBoutons = new StatusButtonBar();setButtonBar(barreDeBoutons);}@Overrideprotected void createButtons() {reinitialiserBouton = new Button("Réinitialiser");reinitialiserBouton.addSelectionListener(new SelectionListener<ButtonEvent>() {public void componentSelected(ButtonEvent ce) {login.reset();motDePasse.reset();validate();login.focus();}});validerBouton = new Button("Valider");//login.disable(); // Par défaut : dois être en mode disablevaliderBouton.addSelectionListener(new SelectionListener<ButtonEvent>() {public void componentSelected(ButtonEvent ce) {onSubmit();}});barreDeBoutons.add(reinitialiserBouton);barreDeBoutons.add(validerBouton);}protected void onSubmit() {barreDeBoutons.getStatusBar().showBusy("Chargement en cours ...");barreDeBoutons.disable();Timer t = new Timer() {@Overridepublic void run() {IdentificationFenetre.this.hide();((Mediateur) Registry.get(RegistreId.MEDIATEUR)).connecterUtilisateur(login.getValue(), motDePasse.getValue());}};t.schedule(2);// Par défaut : 2000}protected boolean hasValue(TextField<String> field) {return field.getValue() != null && field.getValue().length() > 0;}protected void validate() {validerBouton.setEnabled(hasValue(login) && hasValue(motDePasse) && motDePasse.getValue().length() > 3);}}