Subversion Repositories eFlore/Archives.cel-v1

Rev

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

Rev 8 Rev 9
Line 13... Line 13...
13
 * License for the specific language governing permissions and limitations under
13
 * License for the specific language governing permissions and limitations under
14
 * the License.
14
 * the License.
15
 */
15
 */
16
package org.tela_botanica.client;
16
package org.tela_botanica.client;
Line -... Line 17...
-
 
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;
Line 35... Line 38...
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;
-
 
Line 41... Line 43...
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
Line 87... Line 89...
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);
Line 89... Line -...
89
			
-
 
90
		
-
 
91
 
-
 
92
 
91
			
Line 93... Line 92...
93
 
92
		
Line 94... Line 93...
94
		
93
 
Line 104... Line 103...
104
			    		}
103
			    		}
105
			     	}
104
			     	}
106
			));		
105
			));		
Line 107... Line 106...
107
 
106
 
-
 
107
			*/
-
 
108
			
108
			*/
109
			
-
 
110
			HTML delButton=new HTML("Suppression");
-
 
111
			delButton.setStyleName("html_button");
109
			actionButton.add(new Button("Suppression",
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
			     	}
-
 
118
			);		
Line -... Line 119...
-
 
119
			actionButton.add(delButton);
-
 
120
		
-
 
121
			HTML exportButton=new HTML("<a href=\""+serviceBaseUrl+"/InventoryExport/" +user+"\">"+"Tout exporter</a>");
Line 115... Line 122...
115
			));		
122
			actionButton.add(exportButton);
116
		
-
 
117
 
-
 
118
			actionButton.add(new Button("Tout exporter",
-
 
119
			    	new ClickListener() {
-
 
120
			    		public void onClick(Widget sender) {
-
 
121
			    			exportAll();
-
 
Line 122... Line -...
122
			    		}
-
 
123
			     	}
123
			exportButton.setStyleName("html_button");
Line 124... Line 124...
124
			));		
124
 
Line 125... Line 125...
125
 
125
			actionButton.setSpacing(5);
Line 126... Line 126...
126
			
126
 
Line 127... Line 127...
127
			actions.add(actionButton);
127
			actions.add(actionButton);
Line 128... Line 128...
128
			
128
			
-
 
129
			HorizontalPanel selections = new HorizontalPanel();
129
			HorizontalPanel selections = new HorizontalPanel();
130
		
Line -... Line 131...
-
 
131
			selections.setSpacing(3);
-
 
132
			
-
 
133
			actions.add(selections);
130
		
134
 
131
			selections.setSpacing(3);
135
			selections.add(new HTML("S&eacute;lection : "));
132
			
136
			
133
			actions.add(selections);
137
			Label allLabel = new Label("Tous");
134
 
138
			Label separatorLabel = new Label(",");
135
			selections.add(new HTML("S&eacute;lection : "));
139
			Label noneLabel = new Label("Aucun");
136
			
140
			
137
			Label all = new Label("Tous,");
141
			allLabel.setStyleName("selection_label");
Line -... Line 142...
-
 
142
			noneLabel.setStyleName("selection_label");
-
 
143
			
138
			Label none = new Label("Aucun");
144
			selections.add(allLabel);
139
			
145
			allLabel.addClickListener(
140
			selections.add(all);
146
				    	new ClickListener() {
141
			all.addClickListener(
147
				    		public void onClick(Widget sender) {
142
				    	new ClickListener() {
148
				    			selectAll();
143
				    		public void onClick(Widget sender) {
149
				    		}
144
				    			selectAll();
150
				     	}
145
				    		}
151
			);		
-
 
152
			
146
				     	}
153
			selections.add(separatorLabel);
147
			);		
154
			
148
			
155
			selections.add(noneLabel);
Line 149... Line 156...
149
			selections.add(none);
156
			noneLabel.addClickListener(
Line 184... Line 191...
184
							startIndex = 0;
191
							startIndex = 0;
185
						}
192
						}
186
					}
193
					}
187
				}
194
				}
188
			}
195
			}
189
			update();
196
			update(true);
190
		}
197
		}
Line 191... Line 198...
191
 
198
 
Line 192... Line 199...
192
	}
199
	}
Line 209... Line 216...
209
 
216
 
Line 210... Line 217...
210
	private int count = 65000;
217
	private int count = 65000;
Line 211... Line 218...
211
 
218
 
Line -... Line 219...
-
 
219
	private String user;
-
 
220
 
-
 
221
	private NavBar navBar=null;
212
	private String user;
222
 
Line 213... Line -...
213
 
-
 
214
	private NavBar navBar = new NavBar();
-
 
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);
223
	int sizeChecked=0;
248
		table.setBorderWidth(0);
-
 
249
		table.setCellPadding(2);
-
 
250
		table.setWidth("100%");
-
 
251
 
-
 
252
		// Mise en forme barre navigation
-
 
253
 
-
 
254
		navBar.setWidth("100%");
-
 
255
 
-
 
256
		table.setStyleName("taxon-List");
224
	int itemDeleted=0;
257
 
225
	
Line -... Line 226...
-
 
226
	public TaxonList() {
258
		panel.add(navBar);
227
 
Line 259... Line 228...
259
		panel.add(header);
228
		getUser(); // Appelle le reste des initialisations
260
		panel.add(table);
229
		
261
 
230
		initWidget(panel);
Line 273... Line 242...
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) {
Line 275... Line 244...
275
 
244
 
Line -... Line 245...
-
 
245
		setStatusDisabled();
-
 
246
 
-
 
247
		// On met a jour rapidement l'affichage puis on lance la requete  ....
276
		setStatusDisabled();
248
		
-
 
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%");
Line 277... Line 258...
277
 
258
		
Line 278... Line 259...
278
		// Saisie assistée
259
		// Recherche complement d'information
Line 307... Line 288...
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
	}
Line 313... Line 297...
313
 
297
 
314
	/**
298
	/**
315
	 * Ajoute un element à l'inventaire
299
	 * Ajoute un element à l'inventaire
Line 345... Line 329...
345
				+ "&num_taxon=" + num_taxon + "&famille=" + famille,
329
				+ "&num_taxon=" + num_taxon + "&famille=" + famille,
Line 346... Line 330...
346
 
330
 
Line 347... Line 331...
347
		new ResponseTextHandler() {
331
		new ResponseTextHandler() {
-
 
332
 
-
 
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);
348
 
337
				}
349
			public void onCompletion(String str) {
338
				else { 
-
 
339
					gotoEnd();
350
				gotoEnd();
340
					update(true);
351
				update();
341
				}
352
			}
342
			}
Line 353... Line 343...
353
		});
343
		});
Line 360... Line 350...
360
 
350
 
Line 361... Line 351...
361
	public void deleteElement() {
351
	public void deleteElement() {
362
 
352
 
-
 
353
		setStatusDisabled();
Line 363... Line 354...
363
		setStatusDisabled();
354
		boolean checked = false;
364
		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()) {
-
 
360
				checked = true;
-
 
361
				parseChecked.add(table.getText(i, 6));
-
 
362
				count--;
-
 
363
				
-
 
364
			}
-
 
365
		}
-
 
366
		sizeChecked=parseChecked.size();
369
				checked = true;
367
		itemDeleted=0;
370
				String str = table.getText(i, 6);
368
		for (Iterator it = parseChecked.iterator(); it.hasNext();) {
-
 
369
			itemDeleted++;
371
				count--;
370
			HTTPRequest.asyncPost(serviceBaseUrl + "/Inventory/" + user
372
				HTTPRequest.asyncPost(serviceBaseUrl + "/Inventory/" + user
-
 
373
						+ "/" + str, "action=DELETE",
371
						+ "/" + (String) it.next(), "action=DELETE",
-
 
372
						
-
 
373
						new ResponseTextHandler() {
374
						new ResponseTextHandler() {
374
							public void onCompletion(String str) {
375
 
375
								// On ne lance la suppression qu'a la fin
-
 
376
								    if (itemDeleted==sizeChecked) { 
376
							public void onCompletion(String str) {
377
										gotoEnd();
377
								gotoEnd();
378
										update(true);
Line 378... Line -...
378
								update();
-
 
379
							}
379
								    }
380
						});
380
							}
381
 
381
						});
382
			}
382
 
383
		}
383
		}
Line 415... Line 415...
415
	 * enregistrements trouvés
415
	 * enregistrements trouvés
416
	 * 
416
	 * 
417
	 */
417
	 */
418
	private void initAsync() {
418
	private void initAsync() {
Line -... Line 419...
-
 
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();
Line 422... Line 466...
422
		// update()
466
		// update()
Line 423... Line 467...
423
 
467
 
424
	}
468
	}
425
 
469
 
426
	/**
470
	/**
427
	 * Recherche utilisateur en cours
471
	 * Recherche utilisateur en cours
Line 428... Line -...
428
	 * 
-
 
Line 429... Line 472...
429
	 */
472
	 * 
430
	private void getUser() {
473
	 */
Line 431... Line 474...
431
 
474
	private void getUser() {
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;
Line 440... Line 483...
440
						if ((jsonString = jsonValue.isString()) != null) {
483
						if ((jsonString = jsonValue.isString()) != null) {
Line 441... Line 484...
441
							user = jsonString.stringValue();
484
							user = jsonString.stringValue();
442
						}
485
						}
443
						getCount();
486
						initAsync();
444
					}
487
					}
445
				});
488
				});
-
 
489
 
-
 
490
	}
Line 446... Line 491...
446
 
491
 
447
	}
492
	/**
Line 448... Line 493...
448
 
493
	 * Recherche nombre d'enregistrement pour l'utilisateur en cours
Line 460... Line 505...
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
				});
Line 469... Line 514...
469
 
514
 
Line 474... Line 519...
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
	 */
Line 478... Line 523...
478
 
523
 
Line 479... Line 524...
479
	private void update() {
524
	private void update(final boolean deep) {
Line 480... Line 525...
480
 
525
 
481
		setStatusDisabled();
526
		setStatusDisabled();
-
 
527
 
-
 
528
		// TODO : optimisation : ne supprimer que les lignes qui ne seront pas
-
 
529
		// alimentes .
Line -... Line 530...
-
 
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.
482
 
533
 
483
		// TODO : optimisation : ne supprimer que les lignes qui ne seront pas
534
		// TODO : ou alors prevoir un update pour les ajouts (forcemment à la fin) et un update pour les suppressions ...
Line 484... Line 535...
484
		// alimentes .
535
		// Sauf qu'il y a les chgts de pages ... : oui, la un fait un update normal ...
Line 493... Line 544...
493
				JSONValue jsonValue = JSONParser.parse(str);
544
				JSONValue jsonValue = JSONParser.parse(str);
494
				JSONArray jsonArray;
545
				JSONArray jsonArray;
495
				JSONArray jsonArrayNested;
546
				JSONArray jsonArrayNested;
Line 496... Line 547...
496
 
547
 
-
 
548
				// Lifo ...
497
				// Lifo ...
549
				if (deep) {
498
				for (int i = table.getRowCount() - 1; i >= 0; i--) {
550
					for (int i = table.getRowCount() - 1; i >= 0; i--) {
-
 
551
						table.removeRow(i);
499
					table.removeRow(i);
552
					}
-
 
553
				}
-
 
554
				else {
-
 
555
					table.removeRow(table.getRowCount());
500
				}
556
				}
501
 
-
 
502
				int j = 0;
557
					
-
 
558
				if ((jsonArray = jsonValue.isArray()) != null) {
503
				if ((jsonArray = jsonValue.isArray()) != null) {
559
					int arraySize = jsonArray.size();
-
 
560
					for (int i = 0; i < arraySize; ++i) {
-
 
561
						if (!deep && i != arraySize -1) {
-
 
562
							continue;
504
					for (int i = 0; i < jsonArray.size(); ++i) {
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());
Line 534... Line 593...
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
						}
Line 541... Line 599...
541
 
599
 
542
					}
600
					}
543
				}
601
				}
Line 634... Line 692...
634
			startIndex = count - VISIBLE_TAXON_COUNT;
692
			startIndex = count - VISIBLE_TAXON_COUNT;
635
		}
693
		}
Line 636... Line 694...
636
 
694
 
Line 637... Line -...
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","");
-
 
Line 649... Line 695...
649
		
695
	}