Subversion Repositories eFlore/Archives.cel-v1

Rev

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