Subversion Repositories eFlore/Archives.cel-v1

Rev

Rev 29 | Go to most recent revision | Details | Last modification | View Log | RSS feed

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