Subversion Repositories eFlore/Archives.cel-v1

Rev

Rev 25 | 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();
58
  private TextBox complementLocation = new TextBox();
59
  private TextBox comment = new TextBox();
60
  private Button dateSelector = new Button("...");
12 ddelon 61
  boolean visible=false;
22 ddelon 62
  private Mediator mediator=null;
13 ddelon 63
 
25 ddelon 64
 
13 ddelon 65
  private String user= null;
66
  private String ordre =null;
67
 
22 ddelon 68
  private CalendarWidget calendar = null; // Lazy instantiation
69
  private PopupPanel choicesPopup = null; // Lazy instantiation
25 ddelon 70
 
12 ddelon 71
 
72
  public EntryPanel(final Mediator med) {
73
 
74
 
25 ddelon 75
	  Grid inner = new Grid(3,4);
76
 
77
 
78
 
12 ddelon 79
   mediator=med;
22 ddelon 80
   user=mediator.getUser();
12 ddelon 81
 
82
   mediator.registerEntryPanel(this);
83
 
84
   mediator.registerDate(date);
85
   mediator.registerComment(comment);
86
   mediator.registerComplementLocation(complementLocation);
87
 
13 ddelon 88
 
12 ddelon 89
   VerticalPanel outer = new VerticalPanel();
90
 
91
 
22 ddelon 92
   outer.add(new HTML("<b>Saisir&nbsp;un&nbsp;relev&eacute;&nbsp;:</b>"));
12 ddelon 93
 
94
 
95
 
96
   for (int i=0; i<3;i++) {
97
	inner.getCellFormatter().setWidth(i, 0, "3%");
98
	inner.getCellFormatter().setWidth(i, 1, "47%");
99
	inner.getCellFormatter().setWidth(i, 2, "3%");
100
	inner.getCellFormatter().setWidth(i, 3, "47%");
25 ddelon 101
   }
12 ddelon 102
 
103
 
25 ddelon 104
 
105
 
12 ddelon 106
	nameAssistant = new NameAssistant(mediator);
107
	locationAssistant = new LocationAssistant(mediator);
108
 
14 ddelon 109
 
12 ddelon 110
	// Saisie Nom
111
 
22 ddelon 112
     inner.setHTML(0,0,"Esp&egrave;ce:&nbsp;");
12 ddelon 113
     inner.setWidget(0,1,nameAssistant);
114
 
115
     nameAssistant.setWidth("100%");
116
 
117
	 // Saisie lieu
118
 
22 ddelon 119
     inner.setHTML(1,0,"Commune:&nbsp;");
12 ddelon 120
     inner.setWidget(1,1,locationAssistant);
121
 
122
     locationAssistant.setWidth("100%");
123
 
124
     // Saisie Date
125
 
126
 
127
     dateSelector.addClickListener(new ClickListener () {
128
 
129
       public void onClick(Widget w) {
130
 
131
    	   if (visible) {
132
    		  visible=false;
133
    		  choicesPopup.hide();
134
    	   }
135
    	   else {
136
    		visible=true;
22 ddelon 137
    		if (calendar==null) {  // Lazy instantiation
138
    		  calendar = new CalendarWidget();
139
    		  choicesPopup = new PopupPanel(true);
140
    		  choicesPopup.add(calendar);
141
    		  calendar.addChangeListener(new ChangeListener() {
142
 
143
    			     public void onChange(Widget sender) {
144
 
145
    			       Date dateSelected=calendar.getDate();
146
    			       date.setText(dateSelected.getDate()+"/"+(dateSelected.getMonth()+1)+"/"+(dateSelected.getYear()+1900));
147
    			       visible=false;
148
    			       choicesPopup.hide();
149
    			     }
150
    			     });
151
 
152
    	   	}
153
 
12 ddelon 154
    	    choicesPopup.show();
155
	        choicesPopup.setPopupPosition(dateSelector.getAbsoluteLeft(),
13 ddelon 156
	        dateSelector.getAbsoluteTop()  - dateSelector.getOffsetHeight() - choicesPopup.getOffsetHeight());
12 ddelon 157
	        choicesPopup.setWidth(dateSelector.getOffsetWidth() + "px");
158
    	   }
159
       }
160
 
161
     });
162
 
22 ddelon 163
 
164
    inner.setHTML(2,0,"Date:&nbsp;");
12 ddelon 165
 
166
    HorizontalPanel datePanel = new HorizontalPanel();
167
    datePanel.add(date);
168
    datePanel.add(dateSelector);
169
    inner.setWidget(2,1,datePanel);
170
 
22 ddelon 171
    // Saisie date
172
 
12 ddelon 173
    date.addKeyboardListener( new KeyboardListener() {
174
 
175
    		  public void onKeyDown(Widget arg0, char arg1, int arg2) {
176
    			  if(arg1 == KEY_ENTER)
177
    			    {
24 ddelon 178
    				 if (ordre==null) {
179
       				     mediator.onAddInventoryItem();
180
       				     date.setText("");
181
    				 }
182
       				 else {
183
       				     mediator.onModifyInventoryItem(ordre);
184
       				     ordre=null;
185
       				 }
12 ddelon 186
    			    }
187
    		  }
188
 
22 ddelon 189
    		  public void onKeyUp(Widget arg0, char arg1, int arg2) { }
190
    		  public void onKeyPress(Widget arg0, char arg1, int arg2) { }
12 ddelon 191
 
192
    		  }
193
    );
194
 
195
 
196
 
22 ddelon 197
	 // Saisie Complement de lieu  (station)
12 ddelon 198
 
22 ddelon 199
    inner.setHTML(1,2,"Station:&nbsp;");
12 ddelon 200
    inner.setWidget(1,3,complementLocation);
201
 
202
    complementLocation.setWidth("100%");
203
 
204
 
205
    complementLocation.addKeyboardListener( new KeyboardListener() {
206
 
207
		  public void onKeyDown(Widget arg0, char arg1, int arg2) {
208
			  if(arg1 == KEY_ENTER)
209
			    {
24 ddelon 210
				  	if (ordre==null) {
211
   				     mediator.onAddInventoryItem();
212
   				     complementLocation.setText("");
213
   				  	}
214
   				  	else {
215
   				     mediator.onModifyInventoryItem(ordre);
216
   				     ordre=null;
217
   				 }
12 ddelon 218
			    }
219
 
220
		  }
221
 
22 ddelon 222
		  public void onKeyUp(Widget arg0, char arg1, int arg2) { }
12 ddelon 223
 
22 ddelon 224
		  public void onKeyPress(Widget arg0, char arg1, int arg2) { }
12 ddelon 225
 
226
		  }
227
    );
228
 
229
 
230
	 // Saisie Commentaire
231
 
22 ddelon 232
    inner.setHTML(2,2,"Notes:&nbsp;");
12 ddelon 233
    inner.setWidget(2,3,comment);
234
 
235
    comment.setWidth("100%");
236
 
237
 
238
    comment.addKeyboardListener( new KeyboardListener() {
239
 
240
		  public void onKeyDown(Widget arg0, char arg1, int arg2) {
241
			  if(arg1 == KEY_ENTER)
242
			    {
24 ddelon 243
				  	if (ordre==null) {
244
   				     mediator.onAddInventoryItem();
245
   				     comment.setText("");
246
   				  	}
247
   				  	else {
248
   				     mediator.onModifyInventoryItem(ordre);
249
   				     ordre=null;
250
   				  	}
12 ddelon 251
			    }
252
 
253
		  }
254
 
22 ddelon 255
		  public void onKeyUp(Widget arg0, char arg1, int arg2) { }
256
		  public void onKeyPress(Widget arg0, char arg1, int arg2) { }
12 ddelon 257
 
258
		  }
259
  );
25 ddelon 260
 
13 ddelon 261
 
22 ddelon 262
    Button validButton = new Button("Valider");
263
 
13 ddelon 264
 
22 ddelon 265
    validButton.addClickListener(
12 ddelon 266
 
13 ddelon 267
    		new ClickListener() {
268
 
269
    			  public void onClick(Widget w) {
22 ddelon 270
    				  	if (ordre==null) {
13 ddelon 271
    				     mediator.onAddInventoryItem();
22 ddelon 272
    				  	}
273
    				  	else {
13 ddelon 274
    				     mediator.onModifyInventoryItem(ordre);
22 ddelon 275
    				     ordre=null;
276
    				  	}
13 ddelon 277
    			  }
278
    		}
279
    );
280
 
281
 
22 ddelon 282
 
283
    HorizontalPanel actionPanel= new HorizontalPanel();
284
 
285
    actionPanel.add(validButton);
13 ddelon 286
 
12 ddelon 287
 
22 ddelon 288
	inner.setWidth("100%");
12 ddelon 289
 
22 ddelon 290
	outer.add(inner);
291
	outer.setCellWidth(inner, "100%");
292
	outer.setSpacing(10);
12 ddelon 293
 
13 ddelon 294
	outer.setHorizontalAlignment(HorizontalPanel.ALIGN_CENTER);
22 ddelon 295
    outer.add(actionPanel);
12 ddelon 296
 
297
 
14 ddelon 298
    // Initialisation si provenance d'un lien
299
 
300
    if (History.getToken().length()>0) {
12 ddelon 301
 
14 ddelon 302
    	final String anum=History.getToken();
303
 
22 ddelon 304
		HTTPRequest.asyncGet(mediator.getServiceBaseUrl() + "/Name/" + anum,
14 ddelon 305
				new ResponseTextHandler() {
306
 
307
					public void onCompletion(String strcomplete) {
308
 
309
						JSONValue jsonValue = JSONParser.parse(strcomplete);
310
						JSONArray jsonArray;
311
 
312
						if ((jsonArray = jsonValue.isArray()) != null) {
313
 
314
								String aname = ((JSONString) jsonArray.get(0)).stringValue();
315
 
316
								// Nom
317
 
318
								if (aname.compareTo("null")!=0) {
319
									nameAssistant.setText(((JSONString) jsonArray.get(0)).stringValue());
320
 
321
									// Numero nomenclatural
322
 
323
									nameAssistant.setValue(anum);
324
 
325
								}
326
 
327
						}
328
					}
329
 
330
				});
331
 
332
 
333
    }
334
 
335
 
12 ddelon 336
    initWidget(outer);
337
 
338
 
339
  }
13 ddelon 340
 
341
	/*
26 ddelon 342
	 * Numero d'ordre du relev� affich�
13 ddelon 343
	 *
344
	 */
12 ddelon 345
 
13 ddelon 346
	public void setOrdre(String ordre) {
347
		this.ordre = ordre;
12 ddelon 348
	}
349
 
13 ddelon 350
 
351
	/*
26 ddelon 352
	 * Numero d'ordre du relev� affich�
13 ddelon 353
	 *
354
	 */
12 ddelon 355
 
13 ddelon 356
	public String getOrdre() {
357
		return this.ordre;
12 ddelon 358
	}
13 ddelon 359
 
360
 
361
 
362
  /**
26 ddelon 363
	 * Mise a jour de l'affichage a partir de donn�es deja saisie
13 ddelon 364
	 *
365
	 */
366
 
367
	public void update() {
368
 
22 ddelon 369
		HTTPRequest.asyncGet(mediator.getServiceBaseUrl() + "/Inventory/" + user + "/" + ordre,
13 ddelon 370
 
371
		new ResponseTextHandler() {
372
 
373
			public void onCompletion(String str) {
374
 
375
				JSONValue jsonValue = JSONParser.parse(str);
376
				JSONArray jsonArray;
377
 
378
 
379
				if ((jsonArray = jsonValue.isArray()) != null) {
380
							// Nom saisi
381
							nameAssistant.setText(((JSONString) jsonArray.get(0)).stringValue());
382
 
383
							// Numero nomenclatural
384
 
385
							String ann=((JSONString) jsonArray .get(3)).stringValue();
386
 
387
							if (ann.compareTo("0")!=0) {
25 ddelon 388
								nameAssistant.setValue(ann);
389
								mediator.getInfoPopup().setImageUrl(ann);
13 ddelon 390
							}
24 ddelon 391
							else {
392
								nameAssistant.setValue(null);
393
							}
13 ddelon 394
 
395
							// Commune
396
							String aloc=((JSONString) jsonArray .get(6)).stringValue();
397
 
398
							if (aloc.compareTo("000null")!=0) {
399
								locationAssistant.setText(aloc);
400
							}
401
							else {
402
								locationAssistant.setText("");
403
							}
404
 
405
							String adate=((JSONString) jsonArray .get(8)).stringValue();
406
 
407
//							Date
408
							if (adate.compareTo("0000-00-00 00:00:00")!=0) {
409
								date.setText(adate);
410
							}
411
							else {
412
								date.setText("");
413
							}
414
 
415
 
416
							String astation=((JSONString) jsonArray .get(9)).stringValue();
417
 
418
//							Station
14 ddelon 419
							if (astation.compareTo("000null")!=0) {
13 ddelon 420
								complementLocation.setText(astation);
421
							}
422
							else {
423
								complementLocation.setText("");
424
							}
425
 
426
 
427
							String acomment=((JSONString) jsonArray .get(10)).stringValue();
428
//							Notes
429
							if (acomment.compareTo("null")!=0) {
430
								comment.setText(acomment);
431
							}
432
							else {
433
								comment.setText("");
434
							}
435
 
436
				}
437
 
438
 
439
			}
440
		});
441
 
442
	}
443
 
14 ddelon 444
	public void setUser(String user) {
445
		this.user = user;
446
	}
25 ddelon 447
 
13 ddelon 448
 
12 ddelon 449
}
22 ddelon 450
 
451
/* +--Fin du code ---------------------------------------------------------------------------------------+
24 ddelon 452
* $Log$
26 ddelon 453
* Revision 1.6  2007-06-06 13:29:30  ddelon
454
* v0.09
455
*
25 ddelon 456
* Revision 1.5  2007-05-22 14:27:08  ddelon
457
* reglage modification
458
*
24 ddelon 459
* Revision 1.4  2007-05-21 21:01:35  ddelon
460
* Modification comportement boutons
461
*
22 ddelon 462
*
463
*/