Subversion Repositories eFlore/Archives.cel-v1

Rev

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

Rev 14 Rev 15
1
/*
1
/**
-
 
2
 Ce logiciel est régi par la licence CeCILL soumise au droit français et
-
 
3
 respectant les principes de diffusion des logiciels libres. Vous pouvez
-
 
4
 utiliser, modifier et/ou redistribuer ce programme sous les conditions
-
 
5
 de la licence CeCILL telle que diffusée par le CEA, le CNRS et l'INRIA 
2
 * Copyright 2006 Google Inc.
6
 sur le site "http://www.cecill.info".
3
 * 
-
 
-
 
7
 En contrepartie de l'accessibilité au code source et des droits de copie,
4
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
8
 de modification et de redistribution accordés par cette licence, il n'est
5
 * use this file except in compliance with the License. You may obtain a copy of
9
 offert aux utilisateurs qu'une garantie limitée.  Pour les mêmes raisons,
-
 
10
 seule une responsabilité restreinte pèse sur l'auteur du programme,  le
6
 * the License at
11
 titulaire des droits patrimoniaux et les concédants successifs.
7
 * 
12
 
8
 * http://www.apache.org/licenses/LICENSE-2.0
13
 A cet égard  l'attention de l'utilisateur est attirée sur les risques
9
 * 
-
 
-
 
14
 associés au chargement,  à l'utilisation,  à la modification et/ou au
-
 
15
 développement et à la reproduction du logiciel par l'utilisateur étant 
10
 * Unless required by applicable law or agreed to in writing, software
16
 donné sa spécificité de logiciel libre, qui peut le rendre complexe à 
-
 
17
 manipuler et qui le réserve donc à des développeurs et des professionnels
-
 
18
 avertis possédant  des  connaissances  informatiques approfondies.  Les
-
 
19
 utilisateurs sont donc invités à charger  et  tester  l'adéquation  du
-
 
20
 logiciel à leurs besoins dans des conditions permettant d'assurer la
-
 
21
 sécurité de leurs systèmes et ou de leurs données et, plus généralement, 
11
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
22
 à l'utiliser et l'exploiter dans les mêmes conditions de sécurité. 
-
 
23
                                                                                                      
12
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
24
 Le fait que vous puissiez accéder à cet en-tête signifie que vous avez 
13
 * License for the specific language governing permissions and limitations under
25
 pris connaissance de la licence CeCILL, et que vous en avez accepté les
14
 * the License.
26
 termes.
-
 
27
 
-
 
28
 CVS : $Id: 
-
 
29
 
-
 
30
 
-
 
31
 *
15
 */
32
 */
-
 
33
 
16
package org.tela_botanica.client;
34
package org.tela_botanica.client;
17
 
35
 
18
 
36
 
19
import com.google.gwt.json.client.JSONArray;
37
import com.google.gwt.json.client.JSONArray;
20
import com.google.gwt.json.client.JSONBoolean;
38
import com.google.gwt.json.client.JSONBoolean;
21
import com.google.gwt.json.client.JSONParser;
39
import com.google.gwt.json.client.JSONParser;
22
import com.google.gwt.json.client.JSONString;
40
import com.google.gwt.json.client.JSONString;
23
import com.google.gwt.json.client.JSONValue;
41
import com.google.gwt.json.client.JSONValue;
24
import com.google.gwt.user.client.HTTPRequest;
42
import com.google.gwt.user.client.HTTPRequest;
25
import com.google.gwt.user.client.ResponseTextHandler;
43
import com.google.gwt.user.client.ResponseTextHandler;
26
import com.google.gwt.user.client.ui.ClickListener;
44
import com.google.gwt.user.client.ui.ClickListener;
27
import com.google.gwt.user.client.ui.DialogBox;
45
import com.google.gwt.user.client.ui.DialogBox;
28
import com.google.gwt.user.client.ui.Grid;
46
import com.google.gwt.user.client.ui.Grid;
29
import com.google.gwt.user.client.ui.HTML;
47
import com.google.gwt.user.client.ui.HTML;
30
import com.google.gwt.user.client.ui.KeyboardListener;
48
import com.google.gwt.user.client.ui.KeyboardListener;
31
import com.google.gwt.user.client.ui.PasswordTextBox;
49
import com.google.gwt.user.client.ui.PasswordTextBox;
32
import com.google.gwt.user.client.ui.TextBox;
50
import com.google.gwt.user.client.ui.TextBox;
33
import com.google.gwt.user.client.ui.VerticalPanel;
51
import com.google.gwt.user.client.ui.VerticalPanel;
34
import com.google.gwt.user.client.ui.Widget;
52
import com.google.gwt.user.client.ui.Widget;
35
 
53
 
36
public class LoginDialog extends DialogBox {
54
public class LoginDialog extends DialogBox {
37
 
55
 
38
 
56
 
39
  Mediator mediator=null;
57
  Mediator mediator=null;
40
 
58
 
41
  private String serviceBaseUrl = null;
59
  private String serviceBaseUrl = null;
42
  private TextBox login = new TextBox();
60
  private TextBox login = new TextBox();
43
  private PasswordTextBox  password = new PasswordTextBox();
61
  private PasswordTextBox  password = new PasswordTextBox();
44
  private String user=null;
62
  private String user=null;
45
  
63
  
46
  
64
  
47
	
65
	
48
  public LoginDialog(final Mediator med) {
66
  public LoginDialog(final Mediator med) {
49
	  
67
	  
50
    setText("Connexion");
68
    setText("Connexion");
51
 
69
 
52
    mediator=med;
70
    mediator=med;
53
 
71
 
54
    mediator.registerLoginDialog(this);
72
    mediator.registerLoginDialog(this);
55
 
73
 
56
    user=mediator.getUser();
74
    user=mediator.getUser();
57
  
75
  
58
    serviceBaseUrl = mediator.getServiceBaseUrl();
76
    serviceBaseUrl = mediator.getServiceBaseUrl();
59
 
77
 
60
    
78
    
61
    VerticalPanel outer = new VerticalPanel();
79
    VerticalPanel outer = new VerticalPanel();
62
 
80
 
63
    Grid inner = new Grid(3,2);
81
    Grid inner = new Grid(3,2);
64
    
82
    
65
    
83
    
66
   
84
   
67
    HTML textLogin = new HTML("E-mail:");
85
    HTML textLogin = new HTML("E-mail:");
68
    
86
    
69
    
87
    
70
    HTML textPassword = new HTML("Mot de passe:");
88
    HTML textPassword = new HTML("Mot de passe:");
71
 
89
 
72
	
90
	
73
	HTML okButton=new HTML("Ok");
91
	HTML okButton=new HTML("Ok");
74
	okButton.setStyleName("html_button");
92
	okButton.setStyleName("html_button");
75
	okButton.addClickListener(
93
	okButton.addClickListener(
76
	    	new ClickListener() {
94
	    	new ClickListener() {
77
	    		public void onClick(Widget sender) {
95
	    		public void onClick(Widget sender) {
78
					  loginFromService(login.getText(),password.getText());
96
					  loginFromService(login.getText(),password.getText());
79
			        hide();
97
			        hide();
80
	    		}
98
	    		}
81
	     	}
99
	     	}
82
	);		
100
	);		
83
 
101
 
84
	
102
	
85
	
103
	
86
	HTML cancelButton=new HTML("Annuler");
104
	HTML cancelButton=new HTML("Annuler");
87
	cancelButton.setStyleName("html_button");
105
	cancelButton.setStyleName("html_button");
88
	cancelButton.addClickListener(
106
	cancelButton.addClickListener(
89
	    	new ClickListener() {
107
	    	new ClickListener() {
90
	    		public void onClick(Widget sender) {
108
	    		public void onClick(Widget sender) {
91
					        hide();
109
					        hide();
92
	    		}
110
	    		}
93
	     	}
111
	     	}
94
	);		
112
	);		
95
 
113
 
96
	
114
	
97
	  login.addKeyboardListener( new KeyboardListener() {
115
	  login.addKeyboardListener( new KeyboardListener() {
98
 
116
 
99
		  public void onKeyDown(Widget arg0, char arg1, int arg2) {
117
		  public void onKeyDown(Widget arg0, char arg1, int arg2) {
100
			  
118
			  
101
			  
119
			  
102
			  if(arg1 == KEY_ENTER)
120
			  if(arg1 == KEY_ENTER)
103
			    {
121
			    {
104
				  loginFromService(login.getText(),password.getText());
122
				  loginFromService(login.getText(),password.getText());
105
			        hide();
123
			        hide();
106
			    }
124
			    }
107
 
125
 
108
		  }
126
		  }
109
		  
127
		  
110
		  public void onKeyUp(Widget arg0, char arg1, int arg2) {
128
		  public void onKeyUp(Widget arg0, char arg1, int arg2) {
111
		  }
129
		  }
112
 
130
 
113
		  public void onKeyPress(Widget arg0, char arg1, int arg2) {
131
		  public void onKeyPress(Widget arg0, char arg1, int arg2) {
114
		  }
132
		  }
115
		  
133
		  
116
		  }
134
		  }
117
  );
135
  );
118
	
136
	
119
 
137
 
120
		
138
		
121
	  password.addKeyboardListener( new KeyboardListener() {
139
	  password.addKeyboardListener( new KeyboardListener() {
122
 
140
 
123
		  public void onKeyDown(Widget arg0, char arg1, int arg2) {
141
		  public void onKeyDown(Widget arg0, char arg1, int arg2) {
124
			  
142
			  
125
			  
143
			  
126
			  if(arg1 == KEY_ENTER)
144
			  if(arg1 == KEY_ENTER)
127
			    {
145
			    {
128
				  loginFromService(login.getText(),password.getText());
146
				  loginFromService(login.getText(),password.getText());
129
			        hide();
147
			        hide();
130
			    }
148
			    }
131
 
149
 
132
		  }
150
		  }
133
		  
151
		  
134
		  public void onKeyUp(Widget arg0, char arg1, int arg2) {
152
		  public void onKeyUp(Widget arg0, char arg1, int arg2) {
135
		  }
153
		  }
136
 
154
 
137
		  public void onKeyPress(Widget arg0, char arg1, int arg2) {
155
		  public void onKeyPress(Widget arg0, char arg1, int arg2) {
138
		  }
156
		  }
139
		  
157
		  
140
		  }
158
		  }
141
  );
159
  );
142
	
160
	
143
	  inner.setWidget(0,0,textLogin);
161
	  inner.setWidget(0,0,textLogin);
144
	  inner.setWidget(0,1,login);
162
	  inner.setWidget(0,1,login);
145
	  inner.setWidget(1,0,textPassword);
163
	  inner.setWidget(1,0,textPassword);
146
	  inner.setWidget(1,1,password);
164
	  inner.setWidget(1,1,password);
147
	  inner.setWidget(2,0,okButton);
165
	  inner.setWidget(2,0,okButton);
148
	  inner.setWidget(2,1,cancelButton);
166
	  inner.setWidget(2,1,cancelButton);
149
	 
167
	 
150
	  inner.setCellPadding(10);
168
	  inner.setCellPadding(10);
151
	  outer.add(inner);
169
	  outer.add(inner);
152
	  
170
	  
153
	 setWidget(outer);
171
	 setWidget(outer);
154
	    
172
	    
155
  }
173
  }
156
  
174
  
157
  
175
  
158
	/**
176
	/**
159
	 * 
177
	 * 
160
	 */
178
	 */
161
	
179
	
162
	private void loginFromService(String login, String password) {
180
	private void loginFromService(String login, String password) {
163
 
181
 
164
 
182
 
165
		HTTPRequest.asyncGet(serviceBaseUrl + "/User/" + login + "/" + password ,
183
		HTTPRequest.asyncGet(serviceBaseUrl + "/User/" + login + "/" + password ,
166
				new ResponseTextHandler() {
184
				new ResponseTextHandler() {
167
 
185
 
168
					public void onCompletion(String str) {
186
					public void onCompletion(String str) {
169
					
187
					
170
						
188
						
171
						JSONValue jsonValue = JSONParser.parse(str);
189
						JSONValue jsonValue = JSONParser.parse(str);
172
						JSONArray jsonArray;
190
						JSONArray jsonArray;
173
						if ((jsonArray = jsonValue.isArray()) != null) {
191
						if ((jsonArray = jsonValue.isArray()) != null) {
174
								user = ((JSONString) jsonArray.get(0)).stringValue();
192
								user = ((JSONString) jsonArray.get(0)).stringValue();
175
								mediator.setConnected(((JSONBoolean) jsonArray.get(1)).booleanValue());
193
								mediator.setConnected(((JSONBoolean) jsonArray.get(1)).booleanValue());
176
						}
194
						}
177
					
195
					
178
						if (mediator.getConnected()) {
196
						if (mediator.getConnected()) {
179
							mediator.onLogin(user);
197
							mediator.onLogin(user);
180
						}
198
						}
181
					}
199
					}
182
				});
200
				});
183
 
201
 
184
	}
202
	}
185
  
203
  
186
  
204
  
187
  public boolean onKeyDownPreview(char key, int modifiers) {
205
  public boolean onKeyDownPreview(char key, int modifiers) {
188
	    // Use the popup's key preview hooks to close the dialog when either
206
	    // Use the popup's key preview hooks to close the dialog when either
189
	    //  escape is pressed.
207
	    //  escape is pressed.
190
	    switch (key) {
208
	    switch (key) {
191
	      case KeyboardListener.KEY_ESCAPE:
209
	      case KeyboardListener.KEY_ESCAPE:
192
	        hide();
210
	        hide();
193
	        break;
211
	        break;
194
	    }
212
	    }
195
 
213
 
196
	    return true;
214
	    return true;
197
  }
215
  }
198
 
216
 
199
  
217
  
200
 
218
 
201
}
219
}
-
 
220
 
-
 
221
/* +--Fin du code ---------------------------------------------------------------------------------------+
-
 
222
* CVS $Log: 
-
 
223
*/