Subversion Repositories eFlore/Archives.cel-v1

Rev

Rev 5 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5 Rev 6
Line 13... Line 13...
13
 * License for the specific language governing permissions and limitations under
13
 * License for the specific language governing permissions and limitations under
14
 * the License.
14
 * the License.
15
 */
15
 */
16
package org.tela_botanica.client;
16
package org.tela_botanica.client;
Line 17... Line -...
17
 
-
 
18
 
17
 
19
import com.google.gwt.i18n.client.Dictionary;
18
import com.google.gwt.i18n.client.Dictionary;
20
import com.google.gwt.json.client.JSONArray;
19
import com.google.gwt.json.client.JSONArray;
21
import com.google.gwt.json.client.JSONNumber;
20
import com.google.gwt.json.client.JSONNumber;
22
import com.google.gwt.json.client.JSONParser;
21
import com.google.gwt.json.client.JSONParser;
Line 36... Line 35...
36
import com.google.gwt.user.client.ui.Widget;
35
import com.google.gwt.user.client.ui.Widget;
37
import com.google.gwt.user.client.ui.ClickListener;
36
import com.google.gwt.user.client.ui.ClickListener;
38
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
37
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
39
import com.google.gwt.user.client.ui.HasVerticalAlignment;
38
import com.google.gwt.user.client.ui.HasVerticalAlignment;
Line -... Line 39...
-
 
39
 
-
 
40
/*
40
 
41
 * Le retour de getUser appelle getCount qui appelle update pour veiller à une
-
 
42
 * initialisation correcte
-
 
43
 * 
Line 41... Line -...
41
import java.util.Vector;
-
 
42
 
44
 */
-
 
45
 
Line -... Line 46...
-
 
46
public class TaxonList extends Composite implements
-
 
47
		AutoCompleteAsyncTextBoxListener {
-
 
48
 
-
 
49
	// Barre de navigation
-
 
50
 
-
 
51
	private class NavBar extends Composite implements ClickListener {
-
 
52
 
-
 
53
		public final DockPanel bar = new DockPanel();
-
 
54
 
-
 
55
		public final Button gotoFirst = new Button("<<", this);
-
 
56
 
-
 
57
		public final Button gotoNext = new Button(">", this);
-
 
58
 
-
 
59
		public final Button gotoPrev = new Button("<", this);
-
 
60
 
-
 
61
		public final Button gotoEnd = new Button(">>", this);
-
 
62
 
-
 
63
		public final HTML status = new HTML();
-
 
64
 
-
 
65
		public NavBar() {
-
 
66
			initWidget(bar);
-
 
67
			bar.setStyleName("navbar");
-
 
68
			status.setStyleName("status");
-
 
69
 
-
 
70
			HorizontalPanel buttons = new HorizontalPanel();
-
 
71
			buttons.add(gotoFirst);
-
 
72
			buttons.add(gotoPrev);
-
 
73
			buttons.add(gotoNext);
-
 
74
			buttons.add(gotoEnd);
-
 
75
			bar.add(buttons, DockPanel.EAST);
-
 
76
			bar.setCellHorizontalAlignment(buttons, DockPanel.ALIGN_RIGHT);
-
 
77
			bar.add(status, DockPanel.CENTER);
-
 
78
			bar.setVerticalAlignment(DockPanel.ALIGN_MIDDLE);
-
 
79
			bar.setCellHorizontalAlignment(status,
-
 
80
					HasHorizontalAlignment.ALIGN_RIGHT);
-
 
81
			bar.setCellVerticalAlignment(status,
-
 
82
					HasVerticalAlignment.ALIGN_MIDDLE);
-
 
83
			bar.setCellWidth(status, "100%");
-
 
84
 
-
 
85
		}
-
 
86
 
-
 
87
		public void onClick(Widget sender) {
-
 
88
			if (sender == gotoNext) {
-
 
89
				// Move forward a page.
-
 
90
				startIndex += VISIBLE_TAXON_COUNT;
-
 
91
				if (startIndex >= count)
-
 
92
					startIndex -= VISIBLE_TAXON_COUNT;
-
 
93
			} else {
-
 
94
				if (sender == gotoPrev) {
-
 
95
					// Move back a page.
-
 
96
					startIndex -= VISIBLE_TAXON_COUNT;
-
 
97
					if (startIndex < 0)
-
 
98
						startIndex = 0;
-
 
99
				} else {
-
 
100
					if (sender == gotoEnd) {
-
 
101
						gotoEnd();
-
 
102
					} else {
-
 
103
						if (sender == gotoFirst) {
-
 
104
							startIndex = 0;
-
 
105
						}
-
 
106
					}
43
 
107
				}
-
 
108
			}
-
 
109
			update();
-
 
110
		}
-
 
111
 
-
 
112
	}
-
 
113
 
-
 
114
	private void setStatusText(String text) {
-
 
115
		navBar.status.setText(text);
-
 
116
	}
-
 
117
 
-
 
118
	private static final int VISIBLE_TAXON_COUNT = 15;
-
 
119
 
-
 
120
	private Grid header = new Grid(1, 6);
-
 
121
 
-
 
122
	private FlexTable table = new FlexTable();
-
 
123
 
-
 
124
	private VerticalPanel panel = new VerticalPanel();
-
 
125
 
-
 
126
	private int startIndex = 0;
-
 
127
 
-
 
128
	private String serviceBaseUrl = getServiceBaseUrl();
-
 
129
 
-
 
130
	private int count = 65000;
-
 
131
 
-
 
132
	private String user;
-
 
133
 
-
 
134
	private NavBar navBar = new NavBar();
-
 
135
 
-
 
136
	public TaxonList() {
-
 
137
 
-
 
138
		initAsync();
-
 
139
 
-
 
140
		// Information complementaire : un tableau associe au retour de
-
 
141
		// l'assistant de saisie
-
 
142
 
-
 
143
		// Mise en forme du header
-
 
144
 
-
 
145
		header.setCellSpacing(0);
-
 
146
		header.setCellPadding(2);
Line -... Line 147...
-
 
147
		header.setWidth("100%");
-
 
148
 
-
 
149
		header.setStyleName("taxon-ListHeader");
-
 
150
 
-
 
151
		header.setText(0, 0, "");
-
 
152
		header.setText(0, 1, "Nom saisi");
-
 
153
		header.setText(0, 2, "Nom retenu");
-
 
154
		header.setHTML(0, 3, "Code<br>Nomenclatural");
-
 
155
		header.setHTML(0, 4, "Code<br>Taxonomique");
-
 
156
		header.setText(0, 5, "Famille");
-
 
157
 
-
 
158
		header.getCellFormatter().setWidth(0, 0, "2%");
-
 
159
		header.getCellFormatter().setWidth(0, 1, "31%");
-
 
160
		header.getCellFormatter().setWidth(0, 2, "31%");
-
 
161
		header.getCellFormatter().setWidth(0, 3, "9%");
-
 
162
		header.getCellFormatter().setWidth(0, 4, "9%");
-
 
163
		header.getCellFormatter().setWidth(0, 5, "18%");
-
 
164
 
-
 
165
		// Mise en forme de la table.
-
 
166
 
-
 
167
		table.setCellSpacing(0);
-
 
168
		table.setBorderWidth(0);
-
 
169
		table.setCellPadding(2);
-
 
170
		table.setWidth("100%");
-
 
171
 
-
 
172
		// Mise en forme barre navigation
-
 
173
 
-
 
174
		navBar.setWidth("100%");
-
 
175
 
-
 
176
		table.setStyleName("taxon-List");
-
 
177
 
-
 
178
		panel.add(navBar);
-
 
179
		panel.add(header);
-
 
180
		panel.add(table);
-
 
181
 
-
 
182
		initWidget(panel);
-
 
183
 
-
 
184
	}
-
 
185
 
-
 
186
	/**
-
 
187
	 * Action lancee par la selection d'un nom dans l'assistant de saisie. Lance
-
 
188
	 * la recherche d'informations complémentaires (famille, numero
44
/* Le retour de getUser appelle getCount qui appelle update pour veiller à une initialisation correcte
189
	 * nomenclaturaux etc) et met a jour l'inventaire (addelement())
-
 
190
	 * 
-
 
191
	 * @return void
-
 
192
	 */
-
 
193
	public void onValidate(SourcesAutoCompleteAsyncTextBoxEvents sender,
-
 
194
			 final String str,final String value) {
-
 
195
 
-
 
196
		setStatusDisabled();
-
 
197
 
-
 
198
		// Saisie assistée
-
 
199
 
-
 
200
		if (value !=null) {
-
 
201
 
-
 
202
 
-
 
203
			HTTPRequest.asyncGet(serviceBaseUrl + "/NameValid/" + value,
-
 
204
					new ResponseTextHandler() {
-
 
205
 
-
 
206
						public void onCompletion(String strcomplete) {
-
 
207
 
-
 
208
							JSONValue jsonValue = JSONParser.parse(strcomplete);
-
 
209
							JSONArray jsonArray;
-
 
210
 
-
 
211
							if ((jsonArray = jsonValue.isArray()) != null) {
-
 
212
								// Nom retenu, Num Nomen nom retenu, Num Taxon,
-
 
213
								// Famille
-
 
214
								addElement(str, value,
-
 
215
										((JSONString) jsonArray.get(0))
-
 
216
												.stringValue(),
-
 
217
										((JSONString) jsonArray.get(1))
-
 
218
												.stringValue(),
-
 
219
										((JSONString) jsonArray.get(2))
-
 
220
												.stringValue(),
-
 
221
										((JSONString) jsonArray.get(3))
-
 
222
												.stringValue());
-
 
223
							}
-
 
224
						}
-
 
225
 
-
 
226
					});
-
 
227
		}
-
 
228
		// Saisie libre
-
 
229
		else {
-
 
230
			addElement(str, " ", " ", " ", " ", " ");
-
 
231
		}
-
 
232
	}
-
 
233
 
-
 
234
	/**
-
 
235
	 * Ajoute un element à l'inventaire
-
 
236
	 * 
-
 
237
	 * @param nom_sel :
-
 
238
	 *            nom selectionne
-
 
239
	 * @param num_nom_sel :
-
 
240
	 *            numero nomenclatural nom selectionne
-
 
241
	 * @param nom_ret :
-
 
242
	 *            nom retenu
-
 
243
	 * @param num_nom_ret :
-
 
244
	 *            numero nomenclaturel nom retenu
-
 
245
	 * @param num_taxon :
-
 
246
	 *            numero taxonomique
-
 
247
	 * @param famille :
-
 
248
	 *            famille
-
 
249
	 */
-
 
250
 
-
 
251
	public void addElement(String nom_sel, String num_nom_sel, String nom_ret,
-
 
252
			String num_nom_ret, String num_taxon, String famille) {
-
 
253
 
-
 
254
		// Calcul du nouveau numéro d'ordre
-
 
255
 
-
 
256
		/*
-
 
257
		 * int order=1; if (table.getRowCount()>0) { order=new
-
 
258
		 * Integer(table.getText(table.getRowCount()-1,6)).intValue()+1; }
-
 
259
		 */
-
 
260
 
-
 
261
		count++;
-
 
262
		HTTPRequest.asyncPost(serviceBaseUrl + "/Inventory/", "identifiant="
-
 
263
				+ user + "&nom_sel=" + nom_sel + "&num_nom_sel=" + num_nom_sel
-
 
264
				+ "&nom_ret=" + nom_ret + "&num_nom_ret=" + num_nom_ret
-
 
265
				+ "&num_taxon=" + num_taxon + "&famille=" + famille,
-
 
266
 
-
 
267
		new ResponseTextHandler() {
-
 
268
 
-
 
269
			public void onCompletion(String str) {
-
 
270
				gotoEnd();
-
 
271
				update();
-
 
272
			}
-
 
273
		});
-
 
274
	}
-
 
275
 
Line -... Line 276...
-
 
276
	/**
-
 
277
	 * Suppression d'un element lde l'inventaire, a partir de son numero d'ordre
-
 
278
	 * 
-
 
279
	 */
-
 
280
 
-
 
281
	public void deleteElement() {
-
 
282
 
-
 
283
		setStatusDisabled();
-
 
284
		boolean checked = false;
-
 
285
 
-
 
286
		// Lifo ...
-
 
287
		for (int i = table.getRowCount() - 1; i >= 0; i--) {
-
 
288
			if (((CheckBox) table.getWidget(i, 0)).isChecked()) {
-
 
289
				checked = true;
-
 
290
				String str = table.getText(i, 6);
-
 
291
				count--;
-
 
292
				HTTPRequest.asyncPost(serviceBaseUrl + "/Inventory/" + user
-
 
293
						+ "/" + str, "action=DELETE",
-
 
294
						new ResponseTextHandler() {
-
 
295
 
-
 
296
							public void onCompletion(String str) {
-
 
297
								gotoEnd();
-
 
298
								update();
-
 
299
							}
-
 
300
						});
-
 
301
 
-
 
302
			}
-
 
303
		}
-
 
304
		if (!checked) {
-
 
305
			setStatusEnabled();
-
 
306
		}
-
 
307
	}
-
 
308
 
-
 
309
	/**
-
 
310
	 * 
-
 
311
	 * Lancement des initialisations dependantes de réponses asynchrones : le
-
 
312
	 * retour d'une demande d'initialisation declanche la demande
-
 
313
	 * d'initialisation suivantes user : resultat recherche nom d'utilisateur
-
 
314
	 * count : resultat nombre d'enregistrements d'inventaires affichage
-
 
315
	 * enregistrements trouvés
-
 
316
	 * 
-
 
317
	 */
-
 
318
	private void initAsync() {
-
 
319
 
-
 
320
		getUser();
-
 
321
		// getCount()
-
 
322
		// update()
-
 
323
 
-
 
324
	}
-
 
325
 
-
 
326
	/**
-
 
327
	 * Recherche utilisateur en cours
-
 
328
	 * 
-
 
329
	 */
-
 
330
	private void getUser() {
-
 
331
 
-
 
332
		setStatusDisabled();
-
 
333
 
-
 
334
		HTTPRequest.asyncGet(serviceBaseUrl + "/User/",
-
 
335
				new ResponseTextHandler() {
-
 
336
 
-
 
337
					public void onCompletion(String str) {
-
 
338
						JSONValue jsonValue = JSONParser.parse(str);
-
 
339
						JSONString jsonString;
-
 
340
						if ((jsonString = jsonValue.isString()) != null) {
-
 
341
							user = jsonString.stringValue();
-
 
342
						}
-
 
343
						getCount();
-
 
344
					}
-
 
345
				});
-
 
346
 
-
 
347
	}
-
 
348
 
-
 
349
	/**
-
 
350
	 * Recherche nombre d'enregistrement pour l'utilisateur en cours
-
 
351
	 * 
-
 
352
	 */
-
 
353
	private void getCount() {
-
 
354
 
-
 
355
		HTTPRequest.asyncGet(serviceBaseUrl + "/InventoryList/" + user + "/",
-
 
356
				new ResponseTextHandler() {
-
 
357
 
-
 
358
					public void onCompletion(String str) {
-
 
359
 
-
 
360
						JSONValue jsonValue = JSONParser.parse(str);
-
 
361
						JSONNumber jsonNumber;
-
 
362
						if ((jsonNumber = jsonValue.isNumber()) != null) {
-
 
363
							count = (int) jsonNumber.getValue();
-
 
364
							gotoEnd(); // Derniere page
-
 
365
							update();
-
 
366
						}
-
 
367
					}
-
 
368
				});
-
 
369
 
-
 
370
	}
-
 
371
 
-
 
372
	/**
-
 
373
	 * Mise a jour de l'affichage, à partir des données d'inventaire deja
-
 
374
	 * saisies. La valeur de this.startIndex permet de determiner quelles
-
 
375
	 * données seront affichées
-
 
376
	 * 
-
 
377
	 */
-
 
378
 
-
 
379
	private void update() {
-
 
380
 
-
 
381
		setStatusDisabled();
-
 
382
 
-
 
383
		// TODO : optimisation : ne supprimer que les lignes qui ne seront pas
-
 
384
		// alimentes .
-
 
385
 
-
 
386
		HTTPRequest.asyncGet(serviceBaseUrl + "/InventoryList/" + user + "/"
-
 
387
				+ startIndex + "/" + VISIBLE_TAXON_COUNT,
-
 
388
 
-
 
389
		new ResponseTextHandler() {
-
 
390
 
-
 
391
			public void onCompletion(String str) {
-
 
392
 
-
 
393
				JSONValue jsonValue = JSONParser.parse(str);
-
 
394
				JSONArray jsonArray;
-
 
395
				JSONArray jsonArrayNested;
-
 
396
 
-
 
397
				// Lifo ...
-
 
398
				for (int i = table.getRowCount() - 1; i >= 0; i--) {
-
 
399
					table.removeRow(i);
-
 
400
				}
-
 
401
 
-
 
402
				int j = 0;
-
 
403
				if ((jsonArray = jsonValue.isArray()) != null) {
-
 
404
					for (int i = 0; i < jsonArray.size(); ++i) {
-
 
405
						if ((jsonArrayNested = jsonArray.get(i).isArray()) != null) {
-
 
406
							int row = table.insertRow(table.getRowCount());
-
 
407
							// Case a cocher
-
 
408
							table.setWidget(row, 0, new CheckBox());
-
 
409
							// Nom saisi
-
 
410
							table.setText(row, 1, ((JSONString) jsonArrayNested
-
 
411
									.get(0)).stringValue());
-
 
412
							// Nom retenu
-
 
413
							table.setText(row, 2, ((JSONString) jsonArrayNested
-
 
414
									.get(2)).stringValue());
-
 
415
							// Num nomenclatural
-
 
416
							table.setText(row, 3, ((JSONString) jsonArrayNested
-
 
417
									.get(1)).stringValue());
-
 
418
							// Num Taxonomique
-
 
419
							table.setText(row, 4, ((JSONString) jsonArrayNested
-
 
420
									.get(4)).stringValue());
-
 
421
							// Famille
-
 
422
							table.setText(row, 5, ((JSONString) jsonArrayNested
-
 
423
									.get(5)).stringValue());
-
 
424
							// Numero d'ordre
-
 
425
							table.setText(row, 6, ((JSONString) jsonArrayNested
-
 
426
									.get(6)).stringValue());
-
 
427
 
-
 
428
							table.getCellFormatter().setVisible(row, 6, false);
-
 
429
 
-
 
430
							table.getFlexCellFormatter().setWidth(row, 0, "2%");
-
 
431
							table.getFlexCellFormatter()
-
 
432
									.setWidth(row, 1, "31%");
-
 
433
							table.getFlexCellFormatter()
-
 
434
									.setWidth(row, 2, "31%");
-
 
435
							table.getFlexCellFormatter().setWidth(row, 3, "9%");
-
 
436
							table.getFlexCellFormatter().setWidth(row, 4, "9%");
-
 
437
							table.getFlexCellFormatter()
-
 
438
									.setWidth(row, 5, "18%");
-
 
439
							j++;
-
 
440
						}
-
 
441
 
-
 
442
					}
-
 
443
				}
-
 
444
				setStatusEnabled();
-
 
445
 
-
 
446
			}
-
 
447
		});
-
 
448
 
Line 45... Line -...
45
 
-
 
46
 */
-
 
47
 
-
 
48
public class TaxonList extends Composite implements AutoCompleteAsyncTextBoxListener  {
-
 
49
 
-
 
50
 
-
 
51
	
-
 
52
// Barre de navigation 
-
 
53
	
-
 
54
	  private class NavBar extends Composite implements ClickListener {
-
 
55
		  
-
 
56
	    public final DockPanel bar = new DockPanel();
-
 
57
	    public final Button gotoFirst = new Button("&lt;&lt;", this);
-
 
58
	    public final Button gotoNext = new Button("&gt;", this);
-
 
59
	    public final Button gotoPrev = new Button("&lt;", this);
-
 
60
	    public final Button gotoEnd = new Button("&gt;&gt;", this);
-
 
61
	    public final HTML status = new HTML();
-
 
62
  
-
 
63
 
-
 
64
	    public NavBar() {
-
 
65
	      initWidget(bar);
-
 
66
	      bar.setStyleName("navbar");
-
 
67
	      status.setStyleName("status");
-
 
68
 
-
 
69
	      HorizontalPanel buttons = new HorizontalPanel();
-
 
70
	      buttons.add(gotoFirst);
-
 
71
	      buttons.add(gotoPrev);
-
 
72
	      buttons.add(gotoNext);
-
 
73
	      buttons.add(gotoEnd);
-
 
74
	      bar.add(buttons, DockPanel.EAST);
-
 
75
	      bar.setCellHorizontalAlignment(buttons, DockPanel.ALIGN_RIGHT);
-
 
76
	      bar.add(status, DockPanel.CENTER);
-
 
77
	      bar.setVerticalAlignment(DockPanel.ALIGN_MIDDLE);
-
 
78
	      bar.setCellHorizontalAlignment(status, HasHorizontalAlignment.ALIGN_RIGHT);
-
 
79
	      bar.setCellVerticalAlignment(status, HasVerticalAlignment.ALIGN_MIDDLE);
-
 
80
	      bar.setCellWidth(status, "100%");
-
 
81
 
-
 
82
	    }
-
 
83
 
-
 
84
	    
-
 
85
	    public void onClick(Widget sender) {
-
 
86
	  	    if (sender == gotoNext) {
-
 
87
	  	      // Move forward a page.
-
 
88
	  	      startIndex += VISIBLE_TAXON_COUNT;
-
 
89
	  	      if (startIndex >= count)
-
 
90
	  	          startIndex -= VISIBLE_TAXON_COUNT;
-
 
91
	  	    } 
-
 
92
	  	    else {
-
 
93
	  	     if (sender == gotoPrev) {
-
 
94
	  	      // Move back a page.
-
 
95
	  	      startIndex -= VISIBLE_TAXON_COUNT;
-
 
96
	  	      if (startIndex < 0)
-
 
97
	  	        startIndex = 0;
-
 
98
	  	      }
-
 
99
	  	     else {
-
 
100
	  	    	 if (sender==gotoEnd) {
-
 
101
	  	    		gotoEnd();
-
 
102
	  	    	 }
-
 
103
	  	    	 else {
-
 
104
	  	    		 if (sender== gotoFirst) {
-
 
105
	  	    			 startIndex = 0;
-
 
106
	  	    		 }
-
 
107
	  	    	 }
-
 
108
	  	     }
-
 
109
	  	   }
-
 
110
	  	   update();
-
 
111
	    }
-
 
112
 
-
 
113
	  }
-
 
114
 
-
 
115
  private void setStatusText(String text) {
-
 
116
	    navBar.status.setText(text);
-
 
117
  }
-
 
118
 
-
 
119
 
-
 
120
  private static final int VISIBLE_TAXON_COUNT = 15;
-
 
121
	
-
 
122
  private Grid header = new Grid(1,6);
-
 
123
  private FlexTable table = new FlexTable();
-
 
124
  private VerticalPanel panel = new VerticalPanel();
-
 
125
 
-
 
126
  private int startIndex=0;
-
 
127
  private String serviceBaseUrl=getServiceBaseUrl();
-
 
128
  private int count=65000;
-
 
129
  
-
 
130
  private Vector complements=null;
-
 
131
  private String element=null;
-
 
132
  private String complement=null;
-
 
133
  
-
 
134
  private String user;
-
 
135
  
-
 
136
  private NavBar navBar = new NavBar();
-
 
137
  
-
 
138
  public TaxonList(Vector comps) {
-
 
139
 
-
 
140
	 
-
 
141
     initAsync();
-
 
142
	
-
 
143
	// Information complementaire : un tableau associe au retour de l'assistant de saisie
-
 
144
	
-
 
145
	complements=comps;
-
 
146
	
-
 
147
    // Mise en forme du header 
-
 
148
	  
-
 
149
    header.setCellSpacing(0);
-
 
150
    header.setCellPadding(2);
-
 
151
    header.setWidth("100%");
-
 
152
 
-
 
153
    header.setStyleName("taxon-ListHeader");
-
 
154
    
-
 
155
    header.setText(0, 0, "");
-
 
156
    header.setText(0, 1, "Nom saisi");
-
 
157
    header.setText(0, 2, "Nom retenu");
-
 
158
    header.setHTML(0, 3, "Code<br>Nomenclatural");
-
 
159
    header.setHTML(0, 4, "Code<br>Taxonomique");
-
 
160
    header.setText(0, 5, "Famille");
-
 
161
  
-
 
162
	header.getCellFormatter().setWidth(0,0,"2%");
-
 
163
	header.getCellFormatter().setWidth(0,1,"31%");
-
 
164
	header.getCellFormatter().setWidth(0,2,"31%");
-
 
165
	header.getCellFormatter().setWidth(0,3,"9%");
-
 
166
	header.getCellFormatter().setWidth(0,4,"9%");
-
 
167
	header.getCellFormatter().setWidth(0,5,"18%");
-
 
168
 
-
 
169
    // Mise en forme de la table.
-
 
170
	  
-
 
171
    table.setCellSpacing(0);
-
 
172
    table.setBorderWidth(0);
-
 
173
    table.setCellPadding(2);
-
 
174
    table.setWidth("100%");
-
 
175
 
-
 
176
    // Mise en forme barre navigation
-
 
177
    
-
 
178
    navBar.setWidth("100%");
-
 
179
 
-
 
180
   
-
 
181
    table.setStyleName("taxon-List");
-
 
182
 
-
 
183
    panel.add(navBar);
-
 
184
    panel.add(header);
-
 
185
    panel.add(table);
-
 
186
    
-
 
187
    initWidget(panel);
-
 
188
    
-
 
189
 
-
 
190
  }
-
 
191
 
-
 
192
  /**
-
 
193
   * Action lancee par la selection d'un nom dans l'assistant de saisie. Lance la recherche d'informations
-
 
194
   * complémentaires (famille, numero nomenclaturaux etc) et met a jour l'inventaire (addelement())
-
 
195
   * @return void
-
 
196
   */
-
 
197
  public void onValidate(SourcesAutoCompleteAsyncTextBoxEvents sender,int pos, String str) {
-
 
198
	
-
 
199
	  	setStatusDisabled();
-
 
200
	  	
-
 
201
	    // Il y a surement une meilleure facon de faire que de passer par une variable de classe 
-
 
202
	    // pour atteindre une inner classe
-
 
203
	  
-
 
204
	    element=str;
-
 
205
	
-
 
206
	    // Saisie assistée
-
 
207
	  
-
 
208
	    if (pos>=0) {
-
 
209
	 
-
 
210
	    // Le vecteur complements contient les informations complémentaires associées à un nom.
-
 
211
	    	
-
 
212
	    complement=(String) complements.get(pos);
-
 
213
	 
-
 
214
		 HTTPRequest.asyncGet(serviceBaseUrl+"/NameValid/"+complement, 
-
 
215
				    new ResponseTextHandler(){
-
 
216
 
-
 
217
				    	public void onCompletion(String str) {
-
 
218
		    
-
 
219
							JSONValue jsonValue= JSONParser.parse(str);
-
 
220
				  			JSONArray jsonArray;
-
 
221
				
-
 
222
				  			complements.clear();
-
 
223
				  			
-
 
224
				  			if ((jsonArray = jsonValue.isArray()) != null) {
-
 
225
				  					  // Nom retenu, Num Nomen nom retenu, Num Taxon, Famille
-
 
226
								      addElement(element,complement,((JSONString) jsonArray.get(0)).stringValue(),
-
 
227
								    		  ((JSONString) jsonArray.get(1)).stringValue(),((JSONString) jsonArray.get(2)).stringValue(),
-
 
228
								    		  ((JSONString) jsonArray.get(3)).stringValue());
-
 
229
				  			}
-
 
230
				    	} 
-
 
231
 
-
 
232
				   	});
-
 
233
	    }
-
 
234
	    // Saisie libre
-
 
235
	    else {
-
 
236
 			complements.clear();
-
 
237
 
-
 
238
			addElement(element," "," "," "," "," ");
-
 
239
	    }
-
 
240
  }
-
 
241
 
-
 
242
  /**
-
 
243
   * Ajoute un element à l'inventaire 
-
 
244
   * @param nom_sel : nom selectionne
-
 
245
   * @param num_nom_sel : numero nomenclatural nom selectionne
-
 
246
   * @param nom_ret : nom retenu
-
 
247
   * @param num_nom_ret : numero nomenclaturel nom retenu
-
 
248
   * @param num_taxon : numero taxonomique
-
 
249
   * @param famille : famille
-
 
250
   */
-
 
251
 
-
 
252
  public void addElement(String nom_sel, String num_nom_sel, String nom_ret, String num_nom_ret, String num_taxon, String famille) {
-
 
253
	 
-
 
254
	  // Calcul du nouveau numéro d'ordre 
-
 
255
	  
-
 
256
	 /* int order=1;
-
 
257
	  if (table.getRowCount()>0) {
-
 
258
		  order=new Integer(table.getText(table.getRowCount()-1,6)).intValue()+1;
-
 
259
	  }*/
-
 
260
		  
-
 
261
	  count++;
-
 
262
	  HTTPRequest.asyncPost(serviceBaseUrl+"/Inventory/", "identifiant="+user+"&nom_sel="+nom_sel+"&num_nom_sel="+num_nom_sel
-
 
263
			  +"&nom_ret="+nom_ret+"&num_nom_ret="+num_nom_ret+"&num_taxon="+num_taxon+"&famille="+famille,
-
 
264
			  
-
 
265
	  new ResponseTextHandler(){
-
 
266
	
-
 
267
	  	public void onCompletion(String str) {
-
 
268
	  			gotoEnd();
-
 
269
		    	update();
-
 
270
	  	}
-
 
271
	  });
-
 
272
  }
-
 
273
 
-
 
274
  /**
-
 
275
   * Suppression d'un element lde l'inventaire, a partir de son numero d'ordre
-
 
276
   *
-
 
277
   */
-
 
278
 
-
 
279
  
-
 
280
  public void deleteElement() {
-
 
281
 
-
 
282
	  
-
 
283
	  setStatusDisabled();
-
 
284
	  boolean checked=false;
-
 
285
 
-
 
286
	    // Lifo ...
-
 
287
      for (int i=table.getRowCount()-1; i>=0;i--){
-
 
288
		 if (((CheckBox) table.getWidget(i,0)).isChecked())  {
-
 
289
			checked=true;
-
 
290
			String str=table.getText(i,6);
-
 
291
			count--;
-
 
292
			 HTTPRequest.asyncPost(serviceBaseUrl+"/Inventory/"+user+"/"+str, "action=DELETE", 
-
 
293
			   new ResponseTextHandler(){
-
 
294
 
-
 
295
			   	public void onCompletion(String str) {
-
 
296
			   		gotoEnd();
-
 
297
			    	update();
-
 
298
			   	}
-
 
299
			  });
-
 
300
 
-
 
301
	  	 }
-
 
302
	  }
-
 
303
      if (!checked) {
-
 
304
    	  setStatusEnabled(); 
-
 
305
      }
-
 
306
  }
-
 
307
 
-
 
308
  /** 
-
 
309
   * 
-
 
310
   * Lancement des initialisations dependantes de réponses asynchrones : le retour d'une demande d'initialisation declanche 
-
 
311
   * la demande d'initialisation suivantes
-
 
312
   * user : resultat recherche nom d'utilisateur
-
 
313
   * count : resultat nombre d'enregistrements d'inventaires
-
 
314
   * affichage enregistrements trouvés 
-
 
315
   *
-
 
316
   */
-
 
317
  private void initAsync() {
-
 
318
	 
-
 
319
	  getUser();
-
 
320
	  // getCount()
-
 
321
	  // update()
-
 
322
	  
-
 
323
  }
-
 
324
  
-
 
325
  /**
-
 
326
   * Recherche utilisateur en cours 
-
 
327
   *
-
 
328
   */
-
 
329
  private void getUser() {
-
 
330
	  
-
 
331
	  
-
 
332
    	 setStatusDisabled();
-
 
333
 
-
 
334
		 HTTPRequest.asyncGet(serviceBaseUrl+"/User/", 
-
 
335
				    new ResponseTextHandler(){
-
 
336
 
-
 
337
				    	public void onCompletion(String str) {
-
 
338
				    		JSONValue jsonValue= JSONParser.parse(str);
-
 
339
				    		JSONString jsonString;
-
 
340
				    		    if ((jsonString = jsonValue.isString()) != null) {
-
 
341
				    		    	user = jsonString.stringValue();
-
 
342
				    		    }
-
 
343
				    		    getCount();
-
 
344
				    	}
-
 
345
			 	});
-
 
346
		    
-
 
347
		  
-
 
348
 
-
 
349
		}  
-
 
350
 
-
 
351
 /**
-
 
352
  * Recherche nombre d'enregistrement pour l'utilisateur en cours
-
 
353
  *
-
 
354
  */ 
-
 
355
  private void getCount() {
-
 
356
 
-
 
357
	 HTTPRequest.asyncGet(serviceBaseUrl+"/InventoryList/"+user+"/", 
-
 
358
		    new ResponseTextHandler(){
-
 
359
 
-
 
360
		    	public void onCompletion(String str) {
-
 
361
 
-
 
362
		    		JSONValue jsonValue= JSONParser.parse(str);
-
 
363
		    		JSONNumber jsonNumber;
-
 
364
		    		    if ((jsonNumber = jsonValue.isNumber()) != null) {
-
 
365
		    		    	count=(int) jsonNumber.getValue();
-
 
366
		    		    	gotoEnd(); // Derniere page
-
 
367
		    		    	update();
-
 
368
		    		    }
-
 
369
		    	}
-
 
370
	 	});
-
 
371
 
-
 
372
  }
-
 
373
 
-
 
374
  /**
-
 
375
   * Mise a jour de l'affichage, à partir des données d'inventaire deja saisies.
-
 
376
   * La valeur de this.startIndex permet de determiner quelles données seront affichées 
-
 
377
   *
-
 
378
   */
-
 
379
  
-
 
380
  private void update() {
-
 
381
	  
-
 
382
 
-
 
383
	 setStatusDisabled();
-
 
384
	 
-
 
385
	 // TODO : optimisation : ne supprimer que les lignes qui ne seront pas alimentes .
-
 
386
 
-
 
387
	 HTTPRequest.asyncGet(serviceBaseUrl+"/InventoryList/"+user+"/"+startIndex+"/"+VISIBLE_TAXON_COUNT, 
-
 
388
			 
-
 
389
		    new ResponseTextHandler(){
-
 
390
 
-
 
391
		    	public void onCompletion(String str) {
-
 
392
 
-
 
393
		    		    JSONValue jsonValue= JSONParser.parse(str);
-
 
394
		    		    JSONArray jsonArray;
-
 
395
		    		    JSONArray jsonArrayNested;
-
 
396
		    		 
-
 
397
		    		    // Lifo ...
-
 
398
		    	        for (int i=table.getRowCount()-1; i>=0;i--){
-
 
399
		                        table.removeRow(i);
-
 
400
		                }
-
 
401
 
-
 
402
 
-
 
403
		    		    int j=0;
-
 
404
		    		    if ((jsonArray = jsonValue.isArray()) != null) {
-
 
405
		    		      for (int i = 0; i < jsonArray.size(); ++i) {
-
 
406
		    		    	  if ((jsonArrayNested = jsonArray.get(i).isArray()) != null) {
-
 
407
		    		    		  int row=table.insertRow(table.getRowCount());
-
 
408
		    		    		  // Case a cocher
-
 
409
		    		    		  table.setWidget(row,0,new CheckBox());
-
 
410
		    		    		  // Nom saisi
-
 
411
		    		    		  table.setText(row,1,((JSONString) jsonArrayNested.get(0)).stringValue());
-
 
412
		    		    		  // Nom retenu
-
 
413
		    		    		  table.setText(row,2,((JSONString) jsonArrayNested.get(2)).stringValue());
-
 
414
		    		    		  // Num nomenclatural
-
 
415
		    		    		  table.setText(row,3,((JSONString) jsonArrayNested.get(1)).stringValue());
-
 
416
		    		    		  // Num Taxonomique
-
 
417
		    		    		  table.setText(row,4,((JSONString) jsonArrayNested.get(4)).stringValue());
-
 
418
		    		    		  // Famille
-
 
419
		    		    		  table.setText(row,5,((JSONString) jsonArrayNested.get(5)).stringValue());
-
 
420
		    		    		  // Numero d'ordre
-
 
421
		    		    		  table.setText(row,6,((JSONString) jsonArrayNested.get(6)).stringValue());
-
 
422
		    		    		  
-
 
423
		    		    		  table.getCellFormatter().setVisible(row,6,false);
-
 
424
		    		     		  
-
 
425
		    		    		  table.getFlexCellFormatter().setWidth(row,0,"2%");
-
 
426
		    		    		  table.getFlexCellFormatter().setWidth(row,1,"31%");
-
 
427
		    		    		  table.getFlexCellFormatter().setWidth(row,2,"31%");
-
 
428
		    		    		  table.getFlexCellFormatter().setWidth(row,3,"9%");
-
 
429
		    		    		  table.getFlexCellFormatter().setWidth(row,4,"9%");
-
 
430
		    		    		  table.getFlexCellFormatter().setWidth(row,5,"18%");
-
 
431
		    		    		  j++;
-
 
432
		    		    	  }
-
 
433
		    		    	  
-
 
434
		    		      }
-
 
435
		    		    } 
-
 
436
		    		    setStatusEnabled();
-
 
437
		    		    
-
 
438
		    	}
-
 
439
		    });
-
 
440
 
-
 
441
  }
449
	}
442
 
450
 
443
  /**
451
	/**
444
   * Recuperation du prefixe d'appel des services  
452
	 * Recuperation du prefixe d'appel des services
445
   */
-
 
446
  
453
	 */
447
	private String getServiceBaseUrl() {
454
 
448
		  
-
 
449
		  Dictionary theme = Dictionary.getDictionary("Parameters");
455
	private String getServiceBaseUrl() {
450
		  return theme.get("serviceBaseUrl");
456
 
451
		  
457
		Dictionary theme = Dictionary.getDictionary("Parameters");
-
 
458
		return theme.get("serviceBaseUrl");
452
	
459
 
453
		}  
460
	}
454
	
461
 
455
	
462
	/**
456
	/**
463
	 * Affichage message d'attente et désactivation navigation
457
	 * Affichage message d'attente et désactivation navigation
464
	 * 
458
	 * @param 
465
	 * @param
459
	 * @return void  
466
	 * @return void
460
	 */
467
	 */
461
	
468
 
462
	private void setStatusDisabled() {
469
	private void setStatusDisabled() {
463
		
470
 
464
		navBar.gotoFirst.setEnabled(false);
471
		navBar.gotoFirst.setEnabled(false);
465
		navBar.gotoPrev.setEnabled(false);
-
 
Line 466... Line 472...
466
		navBar.gotoNext.setEnabled(false);
472
		navBar.gotoPrev.setEnabled(false);
467
		navBar.gotoEnd.setEnabled(false);
473
		navBar.gotoNext.setEnabled(false);
468
	
474
		navBar.gotoEnd.setEnabled(false);
469
		setStatusText("Patientez ...");
475
 
470
	}
476
		setStatusText("Patientez ...");
471
	
477
	}
472
 
478
 
473
	/**
479
	/**
474
	 * Affichage numero de page et gestion de la navigation
480
	 * Affichage numero de page et gestion de la navigation
475
	 *
481
	 * 
476
	 */
482
	 */
477
	
483
 
-
 
484
	private void setStatusEnabled() {
478
	private void setStatusEnabled() {
485
 
479
	
486
		// Il y a forcemment un disabled avant d'arriver ici
480
		// Il y a forcemment un disabled avant d'arriver ici
487
 
-
 
488
		if (count > 0) {
-
 
489
 
481
		
490
			if (startIndex >= VISIBLE_TAXON_COUNT) { // Au dela de la
482
		if (count > 0 ) {	
491
														// premiere page
483
				
492
				navBar.gotoPrev.setEnabled(true);
484
			if (startIndex >= VISIBLE_TAXON_COUNT) { // Au dela de la premiere page
493
				navBar.gotoFirst.setEnabled(true);
485
				navBar.gotoPrev.setEnabled(true);
494
				if (startIndex < (count - VISIBLE_TAXON_COUNT)) { // Pas la
486
				navBar.gotoFirst.setEnabled(true);
495
																	// derniere
487
				if (startIndex<(count-VISIBLE_TAXON_COUNT)) {  // Pas la derniere page
496
																	// page
488
					navBar.gotoNext.setEnabled(true);
-
 
489
					navBar.gotoEnd.setEnabled(true);
497
					navBar.gotoNext.setEnabled(true);
490
					setStatusText((startIndex + 1) + " - " + (startIndex + VISIBLE_TAXON_COUNT));
498
					navBar.gotoEnd.setEnabled(true);
491
				}
499
					setStatusText((startIndex + 1) + " - "
492
				else { // Derniere page
500
							+ (startIndex + VISIBLE_TAXON_COUNT));
493
					setStatusText((startIndex + 1) + " - " + count);
501
				} else { // Derniere page
494
				}
502
					setStatusText((startIndex + 1) + " - " + count);
495
			}
503
				}
496
			else {  // Premiere page
504
			} else { // Premiere page
497
				if (count > VISIBLE_TAXON_COUNT) { // Des pages derrieres
505
				if (count > VISIBLE_TAXON_COUNT) { // Des pages derrieres
498
					navBar.gotoNext.setEnabled(true);
506
					navBar.gotoNext.setEnabled(true);
499
					navBar.gotoEnd.setEnabled(true);
507
					navBar.gotoEnd.setEnabled(true);
500
					setStatusText((startIndex + 1) + " - " + (startIndex + VISIBLE_TAXON_COUNT));
-
 
501
				}
508
					setStatusText((startIndex + 1) + " - "
502
				else {
509
							+ (startIndex + VISIBLE_TAXON_COUNT));
503
					setStatusText((startIndex + 1) + " - " + count);
510
				} else {
504
				}
511
					setStatusText((startIndex + 1) + " - " + count);
505
			}
512
				}
506
		}
-
 
507
		
513
			}
508
		
514
		}
509
		else { // Pas d'inventaire, pas de navigation
515
 
-
 
516
		else { // Pas d'inventaire, pas de navigation
-
 
517
			setStatusText(0 + " - " + 0);
510
			 setStatusText(0 + " - " + 0);
518
		}
511
		}
519
	}
512
	}
520
 
513
	
521
	/**
514
	
522
	 * Positionnement index de parcours (this.startIndex) pour affichage de la
515
	/**
523
	 * dernière page
516
	 * Positionnement index de parcours (this.startIndex) pour affichage de la dernière page
524
	 * 
517
	 * @param 
525
	 * @param
518
	 * @return void  
-
 
519
	 */
526
	 * @return void
520
	
527
	 */
521
	private void gotoEnd() {
528
 
522
		
529
	private void gotoEnd() {
523
		  	if ( (count==0) || (count%VISIBLE_TAXON_COUNT)>0) {
530
 
524
	    		startIndex=count-(count%VISIBLE_TAXON_COUNT); 
531
		if ((count == 0) || (count % VISIBLE_TAXON_COUNT) > 0) {
525
	    	}
532
			startIndex = count - (count % VISIBLE_TAXON_COUNT);