Subversion Repositories eFlore/Archives.cel-v1

Rev

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

Rev 6 Rev 8
1
/*
1
/*
2
 * Copyright 2006 Google Inc.
2
 * Copyright 2006 Google Inc.
3
 * 
3
 * 
4
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
4
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5
 * use this file except in compliance with the License. You may obtain a copy of
5
 * use this file except in compliance with the License. You may obtain a copy of
6
 * the License at
6
 * the License at
7
 * 
7
 * 
8
 * http://www.apache.org/licenses/LICENSE-2.0
8
 * http://www.apache.org/licenses/LICENSE-2.0
9
 * 
9
 * 
10
 * Unless required by applicable law or agreed to in writing, software
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
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;
17
 
17
 
18
import com.google.gwt.i18n.client.Dictionary;
18
import com.google.gwt.i18n.client.Dictionary;
19
import com.google.gwt.json.client.JSONArray;
19
import com.google.gwt.json.client.JSONArray;
20
import com.google.gwt.json.client.JSONNumber;
20
import com.google.gwt.json.client.JSONNumber;
21
import com.google.gwt.json.client.JSONParser;
21
import com.google.gwt.json.client.JSONParser;
22
import com.google.gwt.json.client.JSONString;
22
import com.google.gwt.json.client.JSONString;
23
import com.google.gwt.json.client.JSONValue;
23
import com.google.gwt.json.client.JSONValue;
24
import com.google.gwt.user.client.HTTPRequest;
24
import com.google.gwt.user.client.HTTPRequest;
25
import com.google.gwt.user.client.ResponseTextHandler;
25
import com.google.gwt.user.client.ResponseTextHandler;
26
import com.google.gwt.user.client.ui.Composite;
26
import com.google.gwt.user.client.ui.Composite;
27
import com.google.gwt.user.client.ui.FlexTable;
27
import com.google.gwt.user.client.ui.FlexTable;
28
import com.google.gwt.user.client.ui.Grid;
28
import com.google.gwt.user.client.ui.Grid;
29
import com.google.gwt.user.client.ui.HTML;
29
import com.google.gwt.user.client.ui.HTML;
30
import com.google.gwt.user.client.ui.HorizontalPanel;
30
import com.google.gwt.user.client.ui.HorizontalPanel;
31
import com.google.gwt.user.client.ui.VerticalPanel;
31
import com.google.gwt.user.client.ui.VerticalPanel;
32
import com.google.gwt.user.client.ui.DockPanel;
32
import com.google.gwt.user.client.ui.DockPanel;
33
import com.google.gwt.user.client.ui.Button;
33
import com.google.gwt.user.client.ui.Button;
34
import com.google.gwt.user.client.ui.CheckBox;
34
import com.google.gwt.user.client.ui.CheckBox;
35
import com.google.gwt.user.client.ui.Widget;
35
import com.google.gwt.user.client.ui.Widget;
36
import com.google.gwt.user.client.ui.ClickListener;
36
import com.google.gwt.user.client.ui.ClickListener;
37
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
37
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
38
import com.google.gwt.user.client.ui.HasVerticalAlignment;
38
import com.google.gwt.user.client.ui.HasVerticalAlignment;
-
 
39
import com.google.gwt.user.client.ui.Label;
-
 
40
import com.google.gwt.user.client.Window;
39
 
41
 
40
/*
42
/*
41
 * Le retour de getUser appelle getCount qui appelle update pour veiller à une
43
 * Le retour de getUser appelle getCount qui appelle update pour veiller à une
42
 * initialisation correcte
44
 * initialisation correcte
43
 * 
45
 * 
44
 */
46
 */
45
 
47
 
46
public class TaxonList extends Composite implements
48
public class TaxonList extends Composite implements
47
		AutoCompleteAsyncTextBoxListener {
49
		AutoCompleteAsyncTextBoxListener {
48
 
50
 
49
	// Barre de navigation
51
	// Barre de navigation
50
 
52
 
51
	private class NavBar extends Composite implements ClickListener {
53
	private class NavBar extends Composite implements ClickListener {
52
 
54
 
53
		public final DockPanel bar = new DockPanel();
55
		public final DockPanel bar = new DockPanel();
54
 
56
 
55
		public final Button gotoFirst = new Button("<<", this);
57
		public final Button gotoFirst = new Button("<<", this);
56
 
58
 
57
		public final Button gotoNext = new Button(">", this);
59
		public final Button gotoNext = new Button(">", this);
58
 
60
 
59
		public final Button gotoPrev = new Button("<", this);
61
		public final Button gotoPrev = new Button("<", this);
60
 
62
 
61
		public final Button gotoEnd = new Button(">>", this);
63
		public final Button gotoEnd = new Button(">>", this);
62
 
64
 
63
		public final HTML status = new HTML();
65
		public final HTML status = new HTML();
-
 
66
		
64
 
67
 
65
		public NavBar() {
68
		public NavBar() {
66
			initWidget(bar);
69
			initWidget(bar);
67
			bar.setStyleName("navbar");
70
			bar.setStyleName("navbar");
68
			status.setStyleName("status");
71
			status.setStyleName("status");
69
 
72
			
70
			HorizontalPanel buttons = new HorizontalPanel();
73
			HorizontalPanel buttons = new HorizontalPanel();
-
 
74
			
-
 
75
			buttons.add(status);
-
 
76
			buttons.setCellHorizontalAlignment(status,
-
 
77
					HasHorizontalAlignment.ALIGN_RIGHT);
-
 
78
			buttons.setCellVerticalAlignment(status,
-
 
79
					HasVerticalAlignment.ALIGN_MIDDLE);
-
 
80
			buttons.setCellWidth(status, "100%");
-
 
81
 
-
 
82
 
71
			buttons.add(gotoFirst);
83
			buttons.add(gotoFirst);
72
			buttons.add(gotoPrev);
84
			buttons.add(gotoPrev);
73
			buttons.add(gotoNext);
85
			buttons.add(gotoNext);
74
			buttons.add(gotoEnd);
86
			buttons.add(gotoEnd);
75
			bar.add(buttons, DockPanel.EAST);
87
			bar.add(buttons, DockPanel.EAST);
76
			bar.setCellHorizontalAlignment(buttons, DockPanel.ALIGN_RIGHT);
88
			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%");
-
 
-
 
89
			
-
 
90
		
-
 
91
 
-
 
92
 
-
 
93
 
-
 
94
		
-
 
95
			VerticalPanel actions = new VerticalPanel();
-
 
96
			
-
 
97
			HorizontalPanel actionButton = new HorizontalPanel();
-
 
98
			
-
 
99
		/*	
-
 
100
			actionButton.add(new Button("Ajout",
-
 
101
			    	new ClickListener() {
-
 
102
			    		public void onClick(Widget sender) {
-
 
103
			    			deleteElement();
-
 
104
			    		}
-
 
105
			     	}
-
 
106
			));		
-
 
107
 
-
 
108
			*/
-
 
109
			actionButton.add(new Button("Suppression",
-
 
110
			    	new ClickListener() {
-
 
111
			    		public void onClick(Widget sender) {
-
 
112
			    			deleteElement();
-
 
113
			    		}
-
 
114
			     	}
-
 
115
			));		
-
 
116
		
-
 
117
 
-
 
118
			actionButton.add(new Button("Tout exporter",
-
 
119
			    	new ClickListener() {
-
 
120
			    		public void onClick(Widget sender) {
-
 
121
			    			exportAll();
-
 
122
			    		}
-
 
123
			     	}
-
 
124
			));		
-
 
125
 
-
 
126
			
-
 
127
			actions.add(actionButton);
-
 
128
			
-
 
129
			HorizontalPanel selections = new HorizontalPanel();
-
 
130
		
-
 
131
			selections.setSpacing(3);
-
 
132
			
-
 
133
			actions.add(selections);
-
 
134
 
-
 
135
			selections.add(new HTML("Sélection : "));
-
 
136
			
-
 
137
			Label all = new Label("Tous,");
-
 
138
			Label none = new Label("Aucun");
-
 
139
			
-
 
140
			selections.add(all);
-
 
141
			all.addClickListener(
-
 
142
				    	new ClickListener() {
-
 
143
				    		public void onClick(Widget sender) {
-
 
144
				    			selectAll();
-
 
145
				    		}
-
 
146
				     	}
-
 
147
			);		
-
 
148
			
-
 
149
			selections.add(none);
-
 
150
			none.addClickListener(
-
 
151
				    	new ClickListener() {
-
 
152
				    		public void onClick(Widget sender) {
-
 
153
				    			deselectAll();
-
 
154
				    		}
-
 
155
				     	}
-
 
156
			);		
-
 
157
		
-
 
158
			bar.add(actions, DockPanel.WEST);
-
 
159
			bar.setCellHorizontalAlignment(buttons, DockPanel.ALIGN_LEFT);
-
 
160
 
-
 
161
			
-
 
162
			bar.setVerticalAlignment(DockPanel.ALIGN_MIDDLE);
-
 
163
			
84
 
164
			
85
		}
165
		}
86
 
166
 
87
		public void onClick(Widget sender) {
167
		public void onClick(Widget sender) {
88
			if (sender == gotoNext) {
168
			if (sender == gotoNext) {
89
				// Move forward a page.
169
				// Move forward a page.
90
				startIndex += VISIBLE_TAXON_COUNT;
170
				startIndex += VISIBLE_TAXON_COUNT;
91
				if (startIndex >= count)
171
				if (startIndex >= count)
92
					startIndex -= VISIBLE_TAXON_COUNT;
172
					startIndex -= VISIBLE_TAXON_COUNT;
93
			} else {
173
			} else {
94
				if (sender == gotoPrev) {
174
				if (sender == gotoPrev) {
95
					// Move back a page.
175
					// Move back a page.
96
					startIndex -= VISIBLE_TAXON_COUNT;
176
					startIndex -= VISIBLE_TAXON_COUNT;
97
					if (startIndex < 0)
177
					if (startIndex < 0)
98
						startIndex = 0;
178
						startIndex = 0;
99
				} else {
179
				} else {
100
					if (sender == gotoEnd) {
180
					if (sender == gotoEnd) {
101
						gotoEnd();
181
						gotoEnd();
102
					} else {
182
					} else {
103
						if (sender == gotoFirst) {
183
						if (sender == gotoFirst) {
104
							startIndex = 0;
184
							startIndex = 0;
105
						}
185
						}
106
					}
186
					}
107
				}
187
				}
108
			}
188
			}
109
			update();
189
			update();
110
		}
190
		}
111
 
191
 
112
	}
192
	}
113
 
193
 
114
	private void setStatusText(String text) {
194
	private void setStatusText(String text) {
115
		navBar.status.setText(text);
195
		navBar.status.setText(text);
116
	}
196
	}
117
 
197
 
118
	private static final int VISIBLE_TAXON_COUNT = 15;
198
	private static final int VISIBLE_TAXON_COUNT = 15;
119
 
199
 
120
	private Grid header = new Grid(1, 6);
200
	private Grid header = new Grid(1, 6);
121
 
201
 
122
	private FlexTable table = new FlexTable();
202
	private FlexTable table = new FlexTable();
123
 
203
 
124
	private VerticalPanel panel = new VerticalPanel();
204
	private VerticalPanel panel = new VerticalPanel();
125
 
205
 
126
	private int startIndex = 0;
206
	private int startIndex = 0;
127
 
207
 
128
	private String serviceBaseUrl = getServiceBaseUrl();
208
	private String serviceBaseUrl = getServiceBaseUrl();
129
 
209
 
130
	private int count = 65000;
210
	private int count = 65000;
131
 
211
 
132
	private String user;
212
	private String user;
133
 
213
 
134
	private NavBar navBar = new NavBar();
214
	private NavBar navBar = new NavBar();
135
 
215
 
136
	public TaxonList() {
216
	public TaxonList() {
137
 
217
 
138
		initAsync();
218
		initAsync();
139
 
219
 
140
		// Information complementaire : un tableau associe au retour de
220
		// Information complementaire : un tableau associe au retour de
141
		// l'assistant de saisie
221
		// l'assistant de saisie
142
 
222
 
143
		// Mise en forme du header
223
		// Mise en forme du header
144
 
224
 
145
		header.setCellSpacing(0);
225
		header.setCellSpacing(0);
146
		header.setCellPadding(2);
226
		header.setCellPadding(2);
147
		header.setWidth("100%");
227
		header.setWidth("100%");
148
 
228
 
149
		header.setStyleName("taxon-ListHeader");
229
		header.setStyleName("taxon-ListHeader");
150
 
230
 
151
		header.setText(0, 0, "");
231
		header.setText(0, 0, "");
152
		header.setText(0, 1, "Nom saisi");
232
		header.setText(0, 1, "Nom saisi");
153
		header.setText(0, 2, "Nom retenu");
233
		header.setText(0, 2, "Nom retenu");
154
		header.setHTML(0, 3, "Code<br>Nomenclatural");
234
		header.setHTML(0, 3, "Code<br>Nomenclatural");
155
		header.setHTML(0, 4, "Code<br>Taxonomique");
235
		header.setHTML(0, 4, "Code<br>Taxonomique");
156
		header.setText(0, 5, "Famille");
236
		header.setText(0, 5, "Famille");
157
 
237
 
158
		header.getCellFormatter().setWidth(0, 0, "2%");
238
		header.getCellFormatter().setWidth(0, 0, "2%");
159
		header.getCellFormatter().setWidth(0, 1, "31%");
239
		header.getCellFormatter().setWidth(0, 1, "31%");
160
		header.getCellFormatter().setWidth(0, 2, "31%");
240
		header.getCellFormatter().setWidth(0, 2, "31%");
161
		header.getCellFormatter().setWidth(0, 3, "9%");
241
		header.getCellFormatter().setWidth(0, 3, "9%");
162
		header.getCellFormatter().setWidth(0, 4, "9%");
242
		header.getCellFormatter().setWidth(0, 4, "9%");
163
		header.getCellFormatter().setWidth(0, 5, "18%");
243
		header.getCellFormatter().setWidth(0, 5, "18%");
164
 
244
 
165
		// Mise en forme de la table.
245
		// Mise en forme de la table.
166
 
246
 
167
		table.setCellSpacing(0);
247
		table.setCellSpacing(0);
168
		table.setBorderWidth(0);
248
		table.setBorderWidth(0);
169
		table.setCellPadding(2);
249
		table.setCellPadding(2);
170
		table.setWidth("100%");
250
		table.setWidth("100%");
171
 
251
 
172
		// Mise en forme barre navigation
252
		// Mise en forme barre navigation
173
 
253
 
174
		navBar.setWidth("100%");
254
		navBar.setWidth("100%");
175
 
255
 
176
		table.setStyleName("taxon-List");
256
		table.setStyleName("taxon-List");
177
 
257
 
178
		panel.add(navBar);
258
		panel.add(navBar);
179
		panel.add(header);
259
		panel.add(header);
180
		panel.add(table);
260
		panel.add(table);
181
 
261
 
182
		initWidget(panel);
262
		initWidget(panel);
183
 
263
 
184
	}
264
	}
185
 
265
 
186
	/**
266
	/**
187
	 * Action lancee par la selection d'un nom dans l'assistant de saisie. Lance
267
	 * Action lancee par la selection d'un nom dans l'assistant de saisie. Lance
188
	 * la recherche d'informations complémentaires (famille, numero
268
	 * la recherche d'informations complémentaires (famille, numero
189
	 * nomenclaturaux etc) et met a jour l'inventaire (addelement())
269
	 * nomenclaturaux etc) et met a jour l'inventaire (addelement())
190
	 * 
270
	 * 
191
	 * @return void
271
	 * @return void
192
	 */
272
	 */
193
	public void onValidate(SourcesAutoCompleteAsyncTextBoxEvents sender,
273
	public void onValidate(SourcesAutoCompleteAsyncTextBoxEvents sender,
194
			 final String str,final String value) {
274
			 final String str,final String value) {
195
 
275
 
196
		setStatusDisabled();
276
		setStatusDisabled();
197
 
277
 
198
		// Saisie assistée
278
		// Saisie assistée
199
 
279
 
200
		if (value !=null) {
280
		if (value !=null) {
201
 
281
 
202
 
282
 
203
			HTTPRequest.asyncGet(serviceBaseUrl + "/NameValid/" + value,
283
			HTTPRequest.asyncGet(serviceBaseUrl + "/NameValid/" + value,
204
					new ResponseTextHandler() {
284
					new ResponseTextHandler() {
205
 
285
 
206
						public void onCompletion(String strcomplete) {
286
						public void onCompletion(String strcomplete) {
207
 
287
 
208
							JSONValue jsonValue = JSONParser.parse(strcomplete);
288
							JSONValue jsonValue = JSONParser.parse(strcomplete);
209
							JSONArray jsonArray;
289
							JSONArray jsonArray;
210
 
290
 
211
							if ((jsonArray = jsonValue.isArray()) != null) {
291
							if ((jsonArray = jsonValue.isArray()) != null) {
212
								// Nom retenu, Num Nomen nom retenu, Num Taxon,
292
								// Nom retenu, Num Nomen nom retenu, Num Taxon,
213
								// Famille
293
								// Famille
214
								addElement(str, value,
294
								addElement(str, value,
215
										((JSONString) jsonArray.get(0))
295
										((JSONString) jsonArray.get(0))
216
												.stringValue(),
296
												.stringValue(),
217
										((JSONString) jsonArray.get(1))
297
										((JSONString) jsonArray.get(1))
218
												.stringValue(),
298
												.stringValue(),
219
										((JSONString) jsonArray.get(2))
299
										((JSONString) jsonArray.get(2))
220
												.stringValue(),
300
												.stringValue(),
221
										((JSONString) jsonArray.get(3))
301
										((JSONString) jsonArray.get(3))
222
												.stringValue());
302
												.stringValue());
223
							}
303
							}
224
						}
304
						}
225
 
305
 
226
					});
306
					});
227
		}
307
		}
228
		// Saisie libre
308
		// Saisie libre
229
		else {
309
		else {
230
			addElement(str, " ", " ", " ", " ", " ");
310
			addElement(str, " ", " ", " ", " ", " ");
231
		}
311
		}
232
	}
312
	}
233
 
313
 
234
	/**
314
	/**
235
	 * Ajoute un element à l'inventaire
315
	 * Ajoute un element à l'inventaire
236
	 * 
316
	 * 
237
	 * @param nom_sel :
317
	 * @param nom_sel :
238
	 *            nom selectionne
318
	 *            nom selectionne
239
	 * @param num_nom_sel :
319
	 * @param num_nom_sel :
240
	 *            numero nomenclatural nom selectionne
320
	 *            numero nomenclatural nom selectionne
241
	 * @param nom_ret :
321
	 * @param nom_ret :
242
	 *            nom retenu
322
	 *            nom retenu
243
	 * @param num_nom_ret :
323
	 * @param num_nom_ret :
244
	 *            numero nomenclaturel nom retenu
324
	 *            numero nomenclaturel nom retenu
245
	 * @param num_taxon :
325
	 * @param num_taxon :
246
	 *            numero taxonomique
326
	 *            numero taxonomique
247
	 * @param famille :
327
	 * @param famille :
248
	 *            famille
328
	 *            famille
249
	 */
329
	 */
250
 
330
 
251
	public void addElement(String nom_sel, String num_nom_sel, String nom_ret,
331
	public void addElement(String nom_sel, String num_nom_sel, String nom_ret,
252
			String num_nom_ret, String num_taxon, String famille) {
332
			String num_nom_ret, String num_taxon, String famille) {
253
 
333
 
254
		// Calcul du nouveau numéro d'ordre
334
		// Calcul du nouveau numéro d'ordre
255
 
335
 
256
		/*
336
		/*
257
		 * int order=1; if (table.getRowCount()>0) { order=new
337
		 * int order=1; if (table.getRowCount()>0) { order=new
258
		 * Integer(table.getText(table.getRowCount()-1,6)).intValue()+1; }
338
		 * Integer(table.getText(table.getRowCount()-1,6)).intValue()+1; }
259
		 */
339
		 */
260
 
340
 
261
		count++;
341
		count++;
262
		HTTPRequest.asyncPost(serviceBaseUrl + "/Inventory/", "identifiant="
342
		HTTPRequest.asyncPost(serviceBaseUrl + "/Inventory/", "identifiant="
263
				+ user + "&nom_sel=" + nom_sel + "&num_nom_sel=" + num_nom_sel
343
				+ user + "&nom_sel=" + nom_sel + "&num_nom_sel=" + num_nom_sel
264
				+ "&nom_ret=" + nom_ret + "&num_nom_ret=" + num_nom_ret
344
				+ "&nom_ret=" + nom_ret + "&num_nom_ret=" + num_nom_ret
265
				+ "&num_taxon=" + num_taxon + "&famille=" + famille,
345
				+ "&num_taxon=" + num_taxon + "&famille=" + famille,
266
 
346
 
267
		new ResponseTextHandler() {
347
		new ResponseTextHandler() {
268
 
348
 
269
			public void onCompletion(String str) {
349
			public void onCompletion(String str) {
270
				gotoEnd();
350
				gotoEnd();
271
				update();
351
				update();
272
			}
352
			}
273
		});
353
		});
274
	}
354
	}
275
 
355
 
276
	/**
356
	/**
277
	 * Suppression d'un element lde l'inventaire, a partir de son numero d'ordre
357
	 * Suppression d'un element lde l'inventaire, a partir de son numero d'ordre
278
	 * 
358
	 * 
279
	 */
359
	 */
280
 
360
 
281
	public void deleteElement() {
361
	public void deleteElement() {
282
 
362
 
283
		setStatusDisabled();
363
		setStatusDisabled();
284
		boolean checked = false;
364
		boolean checked = false;
285
 
365
 
286
		// Lifo ...
366
		// Lifo ...
287
		for (int i = table.getRowCount() - 1; i >= 0; i--) {
367
		for (int i = table.getRowCount() - 1; i >= 0; i--) {
288
			if (((CheckBox) table.getWidget(i, 0)).isChecked()) {
368
			if (((CheckBox) table.getWidget(i, 0)).isChecked()) {
289
				checked = true;
369
				checked = true;
290
				String str = table.getText(i, 6);
370
				String str = table.getText(i, 6);
291
				count--;
371
				count--;
292
				HTTPRequest.asyncPost(serviceBaseUrl + "/Inventory/" + user
372
				HTTPRequest.asyncPost(serviceBaseUrl + "/Inventory/" + user
293
						+ "/" + str, "action=DELETE",
373
						+ "/" + str, "action=DELETE",
294
						new ResponseTextHandler() {
374
						new ResponseTextHandler() {
295
 
375
 
296
							public void onCompletion(String str) {
376
							public void onCompletion(String str) {
297
								gotoEnd();
377
								gotoEnd();
298
								update();
378
								update();
299
							}
379
							}
300
						});
380
						});
301
 
381
 
302
			}
382
			}
303
		}
383
		}
304
		if (!checked) {
384
		if (!checked) {
305
			setStatusEnabled();
385
			setStatusEnabled();
306
		}
386
		}
307
	}
387
	}
-
 
388
	
-
 
389
	/**
-
 
390
	 * Selection de l'ensemble des elements affichés
-
 
391
	 * 
-
 
392
	 */
-
 
393
 
-
 
394
	public void selectAll() {
-
 
395
 
-
 
396
		for (int i = table.getRowCount() - 1; i >= 0; i--) {
-
 
397
			 ((CheckBox) table.getWidget(i, 0)).setChecked(true); 
-
 
398
		}
-
 
399
	}
-
 
400
 
-
 
401
	public void deselectAll() {
-
 
402
	
-
 
403
		for (int i = table.getRowCount() - 1; i >= 0; i--) {
-
 
404
			((CheckBox) table.getWidget(i, 0)).setChecked(false); 
-
 
405
		}
-
 
406
	}
-
 
407
 
308
 
408
 
309
	/**
409
	/**
310
	 * 
410
	 * 
311
	 * Lancement des initialisations dependantes de réponses asynchrones : le
411
	 * Lancement des initialisations dependantes de réponses asynchrones : le
312
	 * retour d'une demande d'initialisation declanche la demande
412
	 * retour d'une demande d'initialisation declanche la demande
313
	 * d'initialisation suivantes user : resultat recherche nom d'utilisateur
413
	 * d'initialisation suivantes user : resultat recherche nom d'utilisateur
314
	 * count : resultat nombre d'enregistrements d'inventaires affichage
414
	 * count : resultat nombre d'enregistrements d'inventaires affichage
315
	 * enregistrements trouvés
415
	 * enregistrements trouvés
316
	 * 
416
	 * 
317
	 */
417
	 */
318
	private void initAsync() {
418
	private void initAsync() {
319
 
419
 
320
		getUser();
420
		getUser();
321
		// getCount()
421
		// getCount()
322
		// update()
422
		// update()
323
 
423
 
324
	}
424
	}
325
 
425
 
326
	/**
426
	/**
327
	 * Recherche utilisateur en cours
427
	 * Recherche utilisateur en cours
328
	 * 
428
	 * 
329
	 */
429
	 */
330
	private void getUser() {
430
	private void getUser() {
331
 
431
 
332
		setStatusDisabled();
432
		setStatusDisabled();
333
 
433
 
334
		HTTPRequest.asyncGet(serviceBaseUrl + "/User/",
434
		HTTPRequest.asyncGet(serviceBaseUrl + "/User/",
335
				new ResponseTextHandler() {
435
				new ResponseTextHandler() {
336
 
436
 
337
					public void onCompletion(String str) {
437
					public void onCompletion(String str) {
338
						JSONValue jsonValue = JSONParser.parse(str);
438
						JSONValue jsonValue = JSONParser.parse(str);
339
						JSONString jsonString;
439
						JSONString jsonString;
340
						if ((jsonString = jsonValue.isString()) != null) {
440
						if ((jsonString = jsonValue.isString()) != null) {
341
							user = jsonString.stringValue();
441
							user = jsonString.stringValue();
342
						}
442
						}
343
						getCount();
443
						getCount();
344
					}
444
					}
345
				});
445
				});
346
 
446
 
347
	}
447
	}
348
 
448
 
349
	/**
449
	/**
350
	 * Recherche nombre d'enregistrement pour l'utilisateur en cours
450
	 * Recherche nombre d'enregistrement pour l'utilisateur en cours
351
	 * 
451
	 * 
352
	 */
452
	 */
353
	private void getCount() {
453
	private void getCount() {
354
 
454
 
355
		HTTPRequest.asyncGet(serviceBaseUrl + "/InventoryList/" + user + "/",
455
		HTTPRequest.asyncGet(serviceBaseUrl + "/InventoryList/" + user + "/",
356
				new ResponseTextHandler() {
456
				new ResponseTextHandler() {
357
 
457
 
358
					public void onCompletion(String str) {
458
					public void onCompletion(String str) {
359
 
459
 
360
						JSONValue jsonValue = JSONParser.parse(str);
460
						JSONValue jsonValue = JSONParser.parse(str);
361
						JSONNumber jsonNumber;
461
						JSONNumber jsonNumber;
362
						if ((jsonNumber = jsonValue.isNumber()) != null) {
462
						if ((jsonNumber = jsonValue.isNumber()) != null) {
363
							count = (int) jsonNumber.getValue();
463
							count = (int) jsonNumber.getValue();
364
							gotoEnd(); // Derniere page
464
							gotoEnd(); // Derniere page
365
							update();
465
							update();
366
						}
466
						}
367
					}
467
					}
368
				});
468
				});
369
 
469
 
370
	}
470
	}
371
 
471
 
372
	/**
472
	/**
373
	 * Mise a jour de l'affichage, à partir des données d'inventaire deja
473
	 * Mise a jour de l'affichage, à partir des données d'inventaire deja
374
	 * saisies. La valeur de this.startIndex permet de determiner quelles
474
	 * saisies. La valeur de this.startIndex permet de determiner quelles
375
	 * données seront affichées
475
	 * données seront affichées
376
	 * 
476
	 * 
377
	 */
477
	 */
378
 
478
 
379
	private void update() {
479
	private void update() {
380
 
480
 
381
		setStatusDisabled();
481
		setStatusDisabled();
382
 
482
 
383
		// TODO : optimisation : ne supprimer que les lignes qui ne seront pas
483
		// TODO : optimisation : ne supprimer que les lignes qui ne seront pas
384
		// alimentes .
484
		// alimentes .
385
 
485
 
386
		HTTPRequest.asyncGet(serviceBaseUrl + "/InventoryList/" + user + "/"
486
		HTTPRequest.asyncGet(serviceBaseUrl + "/InventoryList/" + user + "/"
387
				+ startIndex + "/" + VISIBLE_TAXON_COUNT,
487
				+ startIndex + "/" + VISIBLE_TAXON_COUNT,
388
 
488
 
389
		new ResponseTextHandler() {
489
		new ResponseTextHandler() {
390
 
490
 
391
			public void onCompletion(String str) {
491
			public void onCompletion(String str) {
392
 
492
 
393
				JSONValue jsonValue = JSONParser.parse(str);
493
				JSONValue jsonValue = JSONParser.parse(str);
394
				JSONArray jsonArray;
494
				JSONArray jsonArray;
395
				JSONArray jsonArrayNested;
495
				JSONArray jsonArrayNested;
396
 
496
 
397
				// Lifo ...
497
				// Lifo ...
398
				for (int i = table.getRowCount() - 1; i >= 0; i--) {
498
				for (int i = table.getRowCount() - 1; i >= 0; i--) {
399
					table.removeRow(i);
499
					table.removeRow(i);
400
				}
500
				}
401
 
501
 
402
				int j = 0;
502
				int j = 0;
403
				if ((jsonArray = jsonValue.isArray()) != null) {
503
				if ((jsonArray = jsonValue.isArray()) != null) {
404
					for (int i = 0; i < jsonArray.size(); ++i) {
504
					for (int i = 0; i < jsonArray.size(); ++i) {
405
						if ((jsonArrayNested = jsonArray.get(i).isArray()) != null) {
505
						if ((jsonArrayNested = jsonArray.get(i).isArray()) != null) {
406
							int row = table.insertRow(table.getRowCount());
506
							int row = table.insertRow(table.getRowCount());
407
							// Case a cocher
507
							// Case a cocher
408
							table.setWidget(row, 0, new CheckBox());
508
							table.setWidget(row, 0, new CheckBox());
409
							// Nom saisi
509
							// Nom saisi
410
							table.setText(row, 1, ((JSONString) jsonArrayNested
510
							table.setText(row, 1, ((JSONString) jsonArrayNested
411
									.get(0)).stringValue());
511
									.get(0)).stringValue());
412
							// Nom retenu
512
							// Nom retenu
413
							table.setText(row, 2, ((JSONString) jsonArrayNested
513
							table.setText(row, 2, ((JSONString) jsonArrayNested
414
									.get(2)).stringValue());
514
									.get(2)).stringValue());
415
							// Num nomenclatural
515
							// Num nomenclatural
416
							table.setText(row, 3, ((JSONString) jsonArrayNested
516
							table.setText(row, 3, ((JSONString) jsonArrayNested
417
									.get(1)).stringValue());
517
									.get(1)).stringValue());
418
							// Num Taxonomique
518
							// Num Taxonomique
419
							table.setText(row, 4, ((JSONString) jsonArrayNested
519
							table.setText(row, 4, ((JSONString) jsonArrayNested
420
									.get(4)).stringValue());
520
									.get(4)).stringValue());
421
							// Famille
521
							// Famille
422
							table.setText(row, 5, ((JSONString) jsonArrayNested
522
							table.setText(row, 5, ((JSONString) jsonArrayNested
423
									.get(5)).stringValue());
523
									.get(5)).stringValue());
424
							// Numero d'ordre
524
							// Numero d'ordre
425
							table.setText(row, 6, ((JSONString) jsonArrayNested
525
							table.setText(row, 6, ((JSONString) jsonArrayNested
426
									.get(6)).stringValue());
526
									.get(6)).stringValue());
427
 
527
 
428
							table.getCellFormatter().setVisible(row, 6, false);
528
							table.getCellFormatter().setVisible(row, 6, false);
429
 
529
 
430
							table.getFlexCellFormatter().setWidth(row, 0, "2%");
530
							table.getFlexCellFormatter().setWidth(row, 0, "2%");
431
							table.getFlexCellFormatter()
531
							table.getFlexCellFormatter()
432
									.setWidth(row, 1, "31%");
532
									.setWidth(row, 1, "31%");
433
							table.getFlexCellFormatter()
533
							table.getFlexCellFormatter()
434
									.setWidth(row, 2, "31%");
534
									.setWidth(row, 2, "31%");
435
							table.getFlexCellFormatter().setWidth(row, 3, "9%");
535
							table.getFlexCellFormatter().setWidth(row, 3, "9%");
436
							table.getFlexCellFormatter().setWidth(row, 4, "9%");
536
							table.getFlexCellFormatter().setWidth(row, 4, "9%");
437
							table.getFlexCellFormatter()
537
							table.getFlexCellFormatter()
438
									.setWidth(row, 5, "18%");
538
									.setWidth(row, 5, "18%");
439
							j++;
539
							j++;
440
						}
540
						}
441
 
541
 
442
					}
542
					}
443
				}
543
				}
444
				setStatusEnabled();
544
				setStatusEnabled();
445
 
545
 
446
			}
546
			}
447
		});
547
		});
448
 
548
 
449
	}
549
	}
450
 
550
 
451
	/**
551
	/**
452
	 * Recuperation du prefixe d'appel des services
552
	 * Recuperation du prefixe d'appel des services
453
	 */
553
	 */
454
 
554
 
455
	private String getServiceBaseUrl() {
555
	private String getServiceBaseUrl() {
456
 
556
 
457
		Dictionary theme = Dictionary.getDictionary("Parameters");
557
		Dictionary theme = Dictionary.getDictionary("Parameters");
458
		return theme.get("serviceBaseUrl");
558
		return theme.get("serviceBaseUrl");
459
 
559
 
460
	}
560
	}
461
 
561
 
462
	/**
562
	/**
463
	 * Affichage message d'attente et désactivation navigation
563
	 * Affichage message d'attente et désactivation navigation
464
	 * 
564
	 * 
465
	 * @param
565
	 * @param
466
	 * @return void
566
	 * @return void
467
	 */
567
	 */
468
 
568
 
469
	private void setStatusDisabled() {
569
	private void setStatusDisabled() {
470
 
570
 
471
		navBar.gotoFirst.setEnabled(false);
571
		navBar.gotoFirst.setEnabled(false);
472
		navBar.gotoPrev.setEnabled(false);
572
		navBar.gotoPrev.setEnabled(false);
473
		navBar.gotoNext.setEnabled(false);
573
		navBar.gotoNext.setEnabled(false);
474
		navBar.gotoEnd.setEnabled(false);
574
		navBar.gotoEnd.setEnabled(false);
475
 
575
 
476
		setStatusText("Patientez ...");
576
		setStatusText("Patientez ...");
477
	}
577
	}
478
 
578
 
479
	/**
579
	/**
480
	 * Affichage numero de page et gestion de la navigation
580
	 * Affichage numero de page et gestion de la navigation
481
	 * 
581
	 * 
482
	 */
582
	 */
483
 
583
 
484
	private void setStatusEnabled() {
584
	private void setStatusEnabled() {
485
 
585
 
486
		// Il y a forcemment un disabled avant d'arriver ici
586
		// Il y a forcemment un disabled avant d'arriver ici
487
 
587
 
488
		if (count > 0) {
588
		if (count > 0) {
489
 
589
 
490
			if (startIndex >= VISIBLE_TAXON_COUNT) { // Au dela de la
590
			if (startIndex >= VISIBLE_TAXON_COUNT) { // Au dela de la
491
														// premiere page
591
														// premiere page
492
				navBar.gotoPrev.setEnabled(true);
592
				navBar.gotoPrev.setEnabled(true);
493
				navBar.gotoFirst.setEnabled(true);
593
				navBar.gotoFirst.setEnabled(true);
494
				if (startIndex < (count - VISIBLE_TAXON_COUNT)) { // Pas la
594
				if (startIndex < (count - VISIBLE_TAXON_COUNT)) { // Pas la
495
																	// derniere
595
																	// derniere
496
																	// page
596
																	// page
497
					navBar.gotoNext.setEnabled(true);
597
					navBar.gotoNext.setEnabled(true);
498
					navBar.gotoEnd.setEnabled(true);
598
					navBar.gotoEnd.setEnabled(true);
499
					setStatusText((startIndex + 1) + " - "
599
					setStatusText((startIndex + 1) + " - "
500
							+ (startIndex + VISIBLE_TAXON_COUNT));
600
							+ (startIndex + VISIBLE_TAXON_COUNT) + " sur " + count );
501
				} else { // Derniere page
601
				} else { // Derniere page
502
					setStatusText((startIndex + 1) + " - " + count);
602
					setStatusText((startIndex + 1) + " - " + count + " sur " + count );
503
				}
603
				}
504
			} else { // Premiere page
604
			} else { // Premiere page
505
				if (count > VISIBLE_TAXON_COUNT) { // Des pages derrieres
605
				if (count > VISIBLE_TAXON_COUNT) { // Des pages derrieres
506
					navBar.gotoNext.setEnabled(true);
606
					navBar.gotoNext.setEnabled(true);
507
					navBar.gotoEnd.setEnabled(true);
607
					navBar.gotoEnd.setEnabled(true);
508
					setStatusText((startIndex + 1) + " - "
608
					setStatusText((startIndex + 1) + " - "
509
							+ (startIndex + VISIBLE_TAXON_COUNT));
609
							+ (startIndex + VISIBLE_TAXON_COUNT) + " sur " + count);
510
				} else {
610
				} else {
511
					setStatusText((startIndex + 1) + " - " + count);
611
					setStatusText((startIndex + 1) + " - " + count + " sur " + count);
512
				}
612
				}
513
			}
613
			}
514
		}
614
		}
515
 
615
 
516
		else { // Pas d'inventaire, pas de navigation
616
		else { // Pas d'inventaire, pas de navigation
517
			setStatusText(0 + " - " + 0);
617
			setStatusText("0 - 0 sur 0");
518
		}
618
		}
519
	}
619
	}
520
 
620
 
521
	/**
621
	/*
522
	 * Positionnement index de parcours (this.startIndex) pour affichage de la
622
	 * Positionnement index de parcours (this.startIndex) pour affichage de la
523
	 * dernière page
623
	 * dernière page
524
	 * 
624
	 * 
525
	 * @param
625
	 * @param
526
	 * @return void
626
	 * @return void
527
	 */
627
	 */
528
 
628
 
529
	private void gotoEnd() {
629
	private void gotoEnd() {
530
 
630
 
531
		if ((count == 0) || (count % VISIBLE_TAXON_COUNT) > 0) {
631
		if ((count == 0) || (count % VISIBLE_TAXON_COUNT) > 0) {
532
			startIndex = count - (count % VISIBLE_TAXON_COUNT);
632
			startIndex = count - (count % VISIBLE_TAXON_COUNT);
533
		} else {
633
		} else {
534
			startIndex = count - VISIBLE_TAXON_COUNT;
634
			startIndex = count - VISIBLE_TAXON_COUNT;
535
		}
635
		}
536
 
636
 
537
	}
637
	}
-
 
638
 
-
 
639
	/*
-
 
640
	 * Export du releve affiche  dans un format tableur
-
 
641
	 * 
-
 
642
	 * @param
-
 
643
	 * @return void
-
 
644
	 */
-
 
645
 
-
 
646
	private void exportAll() {
-
 
647
		
-
 
648
		Window.open(serviceBaseUrl+"/InventoryExport/" +user + "/","_self","");
-
 
649
		
-
 
650
	}
538
 
651
 
539
}
652
}