Subversion Repositories eFlore/Archives.cel-v1

Rev

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

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