Subversion Repositories eFlore/Archives.cel-v1

Rev

Rev 26 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
22 ddelon 1
/**
2
 David Delon david.delon@clapas.net 2007
3
 
4
 */
5
 
12 ddelon 6
/*
22 ddelon 7
 * EntryPanel.java  (Composite de Panel)
12 ddelon 8
 *
22 ddelon 9
 * Cas d'utilisation :
10
 * Saisie assistee (completion nom et completion commune) de releves.
11
 * L'identification n'est pas obligatoire
12
 *
13
 * 1 : L'utilisateur saisit a minima un nom de plante
14
 * 		1: Le nom de plante provient d'une application externe : il est deduit du nuremo nomenclatural transmis en historique
15
 * 2 : Le programme assiste la saisie de nom de plante ou de localite par interrogation du systeme distant
16
 * 3 : L'utilisateur choisi le type de mise (ajout ou modification)
17
 * 3 : L'utilisateur valide sa saisie
18
 * 4 : Le programme transmet au systeme distant la nouvelle saisie pour l'identifiant en cours
19
 * 5 : Le programme transmet au systeme local un evenement annoncant une nouvelle saisie
12 ddelon 20
 *
21
 *
22 ddelon 22
 * Affichage detail d'un observation
23
 * 1 : Le programme affiche les donnees d'inventaire pour l'identifiant enregistre et pour le numero d'ordre transmis
24
 *
12 ddelon 25
 */
22 ddelon 26
 
27
 
12 ddelon 28
package org.tela_botanica.client;
29
 
30
import java.util.Date;
31
 
13 ddelon 32
import com.google.gwt.json.client.JSONArray;
33
import com.google.gwt.json.client.JSONParser;
34
import com.google.gwt.json.client.JSONString;
35
import com.google.gwt.json.client.JSONValue;
36
import com.google.gwt.user.client.HTTPRequest;
14 ddelon 37
import com.google.gwt.user.client.History;
13 ddelon 38
import com.google.gwt.user.client.ResponseTextHandler;
12 ddelon 39
import com.google.gwt.user.client.ui.Button;
40
import com.google.gwt.user.client.ui.ChangeListener;
41
import com.google.gwt.user.client.ui.ClickListener;
42
import com.google.gwt.user.client.ui.Composite;
43
import com.google.gwt.user.client.ui.Grid;
44
import com.google.gwt.user.client.ui.HTML;
45
import com.google.gwt.user.client.ui.HorizontalPanel;
46
import com.google.gwt.user.client.ui.KeyboardListener;
47
import com.google.gwt.user.client.ui.PopupPanel;
48
import com.google.gwt.user.client.ui.TextBox;
49
import com.google.gwt.user.client.ui.VerticalPanel;
50
import com.google.gwt.user.client.ui.Widget;
51
 
52
 
13 ddelon 53
public class EntryPanel extends Composite   {
12 ddelon 54
 
55
  private NameAssistant nameAssistant = null;
56
  private LocationAssistant locationAssistant = null;
22 ddelon 57
  private TextBox date = new TextBox();
27 ddelon 58
  private TextBox lieudit = new TextBox();
59
  private TextBox milieu = new TextBox();
22 ddelon 60
  private TextBox comment = new TextBox();
61
  private Button dateSelector = new Button("...");
27 ddelon 62
  private Button validButton = new Button("Ajouter");
63
 
12 ddelon 64
  boolean visible=false;
22 ddelon 65
  private Mediator mediator=null;
13 ddelon 66
 
25 ddelon 67
 
13 ddelon 68
  private String user= null;
69
  private String ordre =null;
70
 
22 ddelon 71
  private CalendarWidget calendar = null; // Lazy instantiation
72
  private PopupPanel choicesPopup = null; // Lazy instantiation
25 ddelon 73
 
12 ddelon 74
 
75
  public EntryPanel(final Mediator med) {
76
 
77
 
27 ddelon 78
  Grid observation = new Grid(4,4);
79
 
80
 
81
  // Formatage affichage
82
 
83
  for (int i=0; i<4;i++) {
84
	observation.getCellFormatter().setWidth(i, 0, "3%");
85
	observation.getCellFormatter().setWidth(i, 1, "47%");
86
	observation.getCellFormatter().setWidth(i, 2, "3%");
87
	observation.getCellFormatter().setWidth(i, 3, "47%");
88
  }
89
 
25 ddelon 90
 
12 ddelon 91
   mediator=med;
22 ddelon 92
   user=mediator.getUser();
12 ddelon 93
 
27 ddelon 94
 
95
   // Declaration des elements du dialogue de saisie aupres du mediator
96
 
12 ddelon 97
   mediator.registerEntryPanel(this);
98
   mediator.registerDate(date);
99
   mediator.registerComment(comment);
27 ddelon 100
   mediator.registerMilieu(milieu);
101
   mediator.registerLieudit(lieudit);
12 ddelon 102
 
13 ddelon 103
 
12 ddelon 104
   VerticalPanel outer = new VerticalPanel();
27 ddelon 105
 
106
// Name assistant et location assistant : widget auto-completion sur nom scientifique ou commune
12 ddelon 107
 
27 ddelon 108
	nameAssistant = new NameAssistant(mediator);
109
	locationAssistant = new LocationAssistant(mediator);
12 ddelon 110
 
27 ddelon 111
 
12 ddelon 112
 
27 ddelon 113
	 // Saisie Commune
114
 
115
     observation.setHTML(2,0,"Commune:&nbsp;");
116
     observation.setWidget(2,1,locationAssistant);
117
 
118
     locationAssistant.setWidth("100%");
12 ddelon 119
 
120
 
27 ddelon 121
	 // Saisie lieu-dit
122
 
123
     observation.setHTML(2,2,"Lieu-dit:&nbsp;");
124
     observation.setWidget(2,3,lieudit);
125
 
126
     lieudit.setWidth("100%");
25 ddelon 127
 
12 ddelon 128
 
27 ddelon 129
 
130
     lieudit.addKeyboardListener( new KeyboardListener() {
12 ddelon 131
 
27 ddelon 132
 		  public void onKeyDown(Widget arg0, char arg1, int arg2) {
133
 			  if(arg1 == KEY_ENTER)
134
 			    {
135
 				 onValidateTextBox(lieudit);
136
 			    }
137
 
138
 		  }
139
 
140
 		  public void onKeyUp(Widget arg0, char arg1, int arg2) { }
141
 
142
 		  public void onKeyPress(Widget arg0, char arg1, int arg2) { }
143
 
144
 		  }
145
     );
146
 
147
 
148
 
149
	 // Saisie (milieu)
12 ddelon 150
 
27 ddelon 151
     observation.setHTML(3,0,"Milieu:&nbsp;");
152
     observation.setWidget(3,1,milieu);
12 ddelon 153
 
27 ddelon 154
     milieu.setWidth("100%");
155
 
12 ddelon 156
 
27 ddelon 157
     // Validation par entree sur cette zone de texte
158
 
159
     milieu.addKeyboardListener( new KeyboardListener() {
160
 
161
 		  public void onKeyDown(Widget arg0, char arg1, int arg2) {
162
 			  if(arg1 == KEY_ENTER)
163
 			    {
164
 				 onValidateTextBox(milieu);
165
 			    }
166
 
167
 		  }
168
 
169
 		  public void onKeyUp(Widget arg0, char arg1, int arg2) { }
170
 
171
 		  public void onKeyPress(Widget arg0, char arg1, int arg2) { }
172
 
173
 		  }
174
     );
175
 
176
 
177
     // Selecteur de Date
178
     // Releve
179
 
180
 
12 ddelon 181
     dateSelector.addClickListener(new ClickListener () {
182
 
183
       public void onClick(Widget w) {
184
 
185
    	   if (visible) {
186
    		  visible=false;
187
    		  choicesPopup.hide();
188
    	   }
189
    	   else {
190
    		visible=true;
22 ddelon 191
    		if (calendar==null) {  // Lazy instantiation
192
    		  calendar = new CalendarWidget();
193
    		  choicesPopup = new PopupPanel(true);
194
    		  choicesPopup.add(calendar);
195
    		  calendar.addChangeListener(new ChangeListener() {
196
 
197
    			     public void onChange(Widget sender) {
198
 
199
    			       Date dateSelected=calendar.getDate();
200
    			       date.setText(dateSelected.getDate()+"/"+(dateSelected.getMonth()+1)+"/"+(dateSelected.getYear()+1900));
201
    			       visible=false;
202
    			       choicesPopup.hide();
203
    			     }
204
    			     });
205
 
206
    	   	}
207
 
12 ddelon 208
    	    choicesPopup.show();
209
	        choicesPopup.setPopupPosition(dateSelector.getAbsoluteLeft(),
13 ddelon 210
	        dateSelector.getAbsoluteTop()  - dateSelector.getOffsetHeight() - choicesPopup.getOffsetHeight());
12 ddelon 211
	        choicesPopup.setWidth(dateSelector.getOffsetWidth() + "px");
212
    	   }
213
       }
214
 
215
     });
27 ddelon 216
 
12 ddelon 217
 
27 ddelon 218
 	// Saisie Espece
219
 
220
   observation.setHTML(0,0,"Esp&egrave;ce:&nbsp;");
221
   observation.setWidget(0,1,nameAssistant);
222
 
223
   nameAssistant.setWidth("100%");
224
 
225
   observation.setHTML(0,2,"Date:&nbsp;");
12 ddelon 226
 
227
    HorizontalPanel datePanel = new HorizontalPanel();
228
    datePanel.add(date);
229
    datePanel.add(dateSelector);
27 ddelon 230
    observation.setWidget(0,3,datePanel);
12 ddelon 231
 
22 ddelon 232
    // Saisie date
27 ddelon 233
    // Validation par entree sur cette zone de texte
234
 
22 ddelon 235
 
12 ddelon 236
    date.addKeyboardListener( new KeyboardListener() {
237
 
238
    		  public void onKeyDown(Widget arg0, char arg1, int arg2) {
239
    			  if(arg1 == KEY_ENTER)
240
    			    {
27 ddelon 241
    				  onValidateTextBox(date);
12 ddelon 242
    			    }
243
    		  }
244
 
22 ddelon 245
    		  public void onKeyUp(Widget arg0, char arg1, int arg2) { }
246
    		  public void onKeyPress(Widget arg0, char arg1, int arg2) { }
12 ddelon 247
 
248
    		  }
249
    );
250
 
251
 
252
 
253
 
254
	 // Saisie Commentaire
255
 
27 ddelon 256
    observation.setHTML(1,0,"Notes:&nbsp;");
257
    observation.setWidget(1,1,comment);
12 ddelon 258
 
259
    comment.setWidth("100%");
260
 
27 ddelon 261
 
262
    // Validation par entree sur cette zone de texte
263
 
12 ddelon 264
    comment.addKeyboardListener( new KeyboardListener() {
265
 
266
		  public void onKeyDown(Widget arg0, char arg1, int arg2) {
267
			  if(arg1 == KEY_ENTER)
268
			    {
27 ddelon 269
    				  onValidateTextBox(comment);
12 ddelon 270
			    }
271
 
272
		  }
273
 
22 ddelon 274
		  public void onKeyUp(Widget arg0, char arg1, int arg2) { }
275
		  public void onKeyPress(Widget arg0, char arg1, int arg2) { }
12 ddelon 276
 
277
		  }
278
  );
25 ddelon 279
 
27 ddelon 280
 
281
    // Validation par click sur bouton valider
282
 
22 ddelon 283
 
284
    validButton.addClickListener(
12 ddelon 285
 
13 ddelon 286
    		new ClickListener() {
287
 
288
    			  public void onClick(Widget w) {
27 ddelon 289
    				  // Numero ordre vide : ajout d'une observation
22 ddelon 290
    				  	if (ordre==null) {
13 ddelon 291
    				     mediator.onAddInventoryItem();
22 ddelon 292
    				  	}
293
    				  	else {
13 ddelon 294
    				     mediator.onModifyInventoryItem(ordre);
22 ddelon 295
    				     ordre=null;
296
    				  	}
13 ddelon 297
    			  }
298
    		}
299
    );
300
 
301
 
22 ddelon 302
 
303
    HorizontalPanel actionPanel= new HorizontalPanel();
304
 
305
    actionPanel.add(validButton);
13 ddelon 306
 
12 ddelon 307
 
27 ddelon 308
	observation.setWidth("100%");
12 ddelon 309
 
27 ddelon 310
	outer.add(observation);
311
	outer.setCellWidth(observation, "100%");
22 ddelon 312
	outer.setSpacing(10);
12 ddelon 313
 
13 ddelon 314
	outer.setHorizontalAlignment(HorizontalPanel.ALIGN_CENTER);
22 ddelon 315
    outer.add(actionPanel);
12 ddelon 316
 
317
 
14 ddelon 318
    // Initialisation si provenance d'un lien
319
 
320
    if (History.getToken().length()>0) {
12 ddelon 321
 
14 ddelon 322
    	final String anum=History.getToken();
323
 
22 ddelon 324
		HTTPRequest.asyncGet(mediator.getServiceBaseUrl() + "/Name/" + anum,
14 ddelon 325
				new ResponseTextHandler() {
326
 
327
					public void onCompletion(String strcomplete) {
328
 
329
						JSONValue jsonValue = JSONParser.parse(strcomplete);
330
						JSONArray jsonArray;
331
 
332
						if ((jsonArray = jsonValue.isArray()) != null) {
333
 
27 ddelon 334
								String aname = Util.toCelString(((JSONString) jsonArray.get(0)).toString());
14 ddelon 335
 
336
								// Nom
337
								if (aname.compareTo("null")!=0) {
27 ddelon 338
									nameAssistant.setText(aname);
14 ddelon 339
									// Numero nomenclatural
340
									nameAssistant.setValue(anum);
341
								}
342
 
343
						}
344
					}
345
 
346
				});
347
 
348
 
349
    }
350
 
351
 
12 ddelon 352
    initWidget(outer);
353
 
354
 
355
  }
13 ddelon 356
 
357
	/*
27 ddelon 358
	 * Numero d'ordre du releve affiche + mise à jour bouton
13 ddelon 359
	 *
360
	 */
12 ddelon 361
 
13 ddelon 362
	public void setOrdre(String ordre) {
363
		this.ordre = ordre;
27 ddelon 364
		if (ordre==null) {
365
			this.validButton.setText("Ajouter");
366
		}
367
		else {
368
			this.validButton.setText("Modifier");
369
		}
12 ddelon 370
	}
371
 
13 ddelon 372
 
373
	/*
27 ddelon 374
	 * Numero d'ordre du releve affiche
13 ddelon 375
	 *
376
	 */
12 ddelon 377
 
13 ddelon 378
	public String getOrdre() {
379
		return this.ordre;
12 ddelon 380
	}
13 ddelon 381
 
382
 
27 ddelon 383
    // Validation par entree sur cette zone de texte
384
 
385
    private void onValidateTextBox(TextBox textbox) {
386
 
387
		  	if (ordre==null) {
388
			  // Numero ordre vide : ajout d'une observation
389
			     mediator.onAddInventoryItem();
390
			     textbox.setText("");
391
			  	}
392
			  	else {
393
			     mediator.onModifyInventoryItem(ordre);
394
			     ordre=null;
395
			 }
396
 
397
    }
398
 
399
 
13 ddelon 400
 
401
  /**
27 ddelon 402
	 * Mise a jour de l'affichage a partir de donnees deja saisie
13 ddelon 403
	 *
404
	 */
405
 
406
	public void update() {
407
 
22 ddelon 408
		HTTPRequest.asyncGet(mediator.getServiceBaseUrl() + "/Inventory/" + user + "/" + ordre,
13 ddelon 409
 
410
		new ResponseTextHandler() {
411
 
412
			public void onCompletion(String str) {
413
 
414
				JSONValue jsonValue = JSONParser.parse(str);
415
				JSONArray jsonArray;
416
 
417
 
418
				if ((jsonArray = jsonValue.isArray()) != null) {
27 ddelon 419
 
13 ddelon 420
							// Nom saisi
27 ddelon 421
							nameAssistant.setText(Util.toCelString(((JSONString) jsonArray.get(0)).toString()));
13 ddelon 422
 
27 ddelon 423
 
13 ddelon 424
							// Numero nomenclatural
425
 
426
							String ann=((JSONString) jsonArray .get(3)).stringValue();
427
 
428
							if (ann.compareTo("0")!=0) {
25 ddelon 429
								nameAssistant.setValue(ann);
430
								mediator.getInfoPopup().setImageUrl(ann);
13 ddelon 431
							}
24 ddelon 432
							else {
433
								nameAssistant.setValue(null);
434
							}
13 ddelon 435
 
436
							// Commune
27 ddelon 437
							String aloc=Util.toCelString(((JSONString) jsonArray .get(6)).toString());
13 ddelon 438
 
439
							if (aloc.compareTo("000null")!=0) {
440
								locationAssistant.setText(aloc);
441
							}
442
							else {
443
								locationAssistant.setText("");
444
							}
445
 
446
							String adate=((JSONString) jsonArray .get(8)).stringValue();
447
 
448
//							Date
449
							if (adate.compareTo("0000-00-00 00:00:00")!=0) {
450
								date.setText(adate);
451
							}
452
							else {
453
								date.setText("");
454
							}
455
 
456
 
27 ddelon 457
							String astation=Util.toCelString(((JSONString) jsonArray .get(9)).toString());
13 ddelon 458
 
459
//							Station
14 ddelon 460
							if (astation.compareTo("000null")!=0) {
27 ddelon 461
								milieu.setText(astation);
13 ddelon 462
							}
463
							else {
27 ddelon 464
								milieu.setText("");
13 ddelon 465
							}
466
 
467
 
27 ddelon 468
							String acomment=Util.toCelString(((JSONString) jsonArray .get(10)).toString());
13 ddelon 469
//							Notes
470
							if (acomment.compareTo("null")!=0) {
471
								comment.setText(acomment);
472
							}
473
							else {
474
								comment.setText("");
475
							}
476
 
477
				}
478
 
479
 
480
			}
481
		});
482
 
483
	}
484
 
14 ddelon 485
	public void setUser(String user) {
486
		this.user = user;
487
	}
25 ddelon 488
 
13 ddelon 489
 
12 ddelon 490
}
22 ddelon 491
 
492
/* +--Fin du code ---------------------------------------------------------------------------------------+
24 ddelon 493
* $Log$
27 ddelon 494
* Revision 1.7  2007-09-17 19:25:34  ddelon
495
* Documentation
496
*
26 ddelon 497
* Revision 1.6  2007-06-06 13:29:30  ddelon
498
* v0.09
499
*
25 ddelon 500
* Revision 1.5  2007-05-22 14:27:08  ddelon
501
* reglage modification
502
*
24 ddelon 503
* Revision 1.4  2007-05-21 21:01:35  ddelon
504
* Modification comportement boutons
505
*
22 ddelon 506
*
507
*/