Subversion Repositories eFlore/Archives.cel-v1

Rev

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

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