Subversion Repositories eFlore/Applications.coel

Rev

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