Subversion Repositories eFlore/Archives.cel-v1

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
12 ddelon 1
/*
2
 * Copyright 2006 Google Inc.
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5
 * use this file except in compliance with the License. You may obtain a copy of
6
 * the License at
7
 *
8
 * http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
 * License for the specific language governing permissions and limitations under
14
 * the License.
15
 */
16
package org.tela_botanica.client;
17
 
18
import java.util.Date;
19
 
13 ddelon 20
import com.google.gwt.json.client.JSONArray;
21
import com.google.gwt.json.client.JSONParser;
22
import com.google.gwt.json.client.JSONString;
23
import com.google.gwt.json.client.JSONValue;
24
import com.google.gwt.user.client.HTTPRequest;
25
import com.google.gwt.user.client.ResponseTextHandler;
12 ddelon 26
import com.google.gwt.user.client.ui.Button;
27
import com.google.gwt.user.client.ui.ChangeListener;
13 ddelon 28
import com.google.gwt.user.client.ui.CheckBox;
12 ddelon 29
import com.google.gwt.user.client.ui.ClickListener;
30
import com.google.gwt.user.client.ui.Composite;
31
import com.google.gwt.user.client.ui.Grid;
32
import com.google.gwt.user.client.ui.HTML;
33
import com.google.gwt.user.client.ui.HorizontalPanel;
34
import com.google.gwt.user.client.ui.KeyboardListener;
35
import com.google.gwt.user.client.ui.PopupPanel;
36
import com.google.gwt.user.client.ui.TextBox;
37
import com.google.gwt.user.client.ui.VerticalPanel;
38
import com.google.gwt.user.client.ui.Widget;
39
 
40
/**
41
 * Composite permet de wrapper des Widget pour creer un nouveau Widget cf methode initWidget()
42
 */
43
 
13 ddelon 44
public class EntryPanel extends Composite   {
12 ddelon 45
 
46
  private NameAssistant nameAssistant = null;
47
  private LocationAssistant locationAssistant = null;
48
  TextBox date = new TextBox();
49
  TextBox complementLocation = new TextBox();
50
  TextBox comment = new TextBox();
51
  Button dateSelector = new Button("...");
52
  boolean visible=false;
53
  Mediator mediator=null;
54
 
13 ddelon 55
  private String serviceBaseUrl = null;
56
 
57
  private String user= null;
58
  private String ordre =null;
59
 
12 ddelon 60
  final CalendarWidget calendar = new CalendarWidget();
61
 
62
  private PopupPanel choicesPopup = new PopupPanel(true);
63
 
64
  public EntryPanel(final Mediator med) {
65
 
66
 
67
   mediator=med;
68
 
69
 
70
 
71
   mediator.registerEntryPanel(this);
72
 
73
   mediator.registerDate(date);
74
   mediator.registerComment(comment);
75
   mediator.registerComplementLocation(complementLocation);
76
 
77
 
13 ddelon 78
   user=mediator.getUser();
79
   serviceBaseUrl = mediator.getServiceBaseUrl();
80
 
12 ddelon 81
 
13 ddelon 82
 
12 ddelon 83
   VerticalPanel outer = new VerticalPanel();
84
 
85
 
13 ddelon 86
//	outer.add(new HTML("<b>Nouvelle observation:</b>"));
12 ddelon 87
 
88
 
89
 
90
   Grid inner = new Grid(3,4);
91
 
92
   for (int i=0; i<3;i++) {
93
	inner.getCellFormatter().setWidth(i, 0, "3%");
94
	inner.getCellFormatter().setWidth(i, 1, "47%");
95
	inner.getCellFormatter().setWidth(i, 2, "3%");
96
	inner.getCellFormatter().setWidth(i, 3, "47%");
97
   }
98
 
99
 
100
	nameAssistant = new NameAssistant(mediator);
101
	locationAssistant = new LocationAssistant(mediator);
102
 
103
 
104
	// Saisie Nom
105
 
106
     HTML labelNameAssistant = new HTML("Esp&egrave;ce:&nbsp;");
107
     inner.setWidget(0,0,labelNameAssistant);
108
     inner.setWidget(0,1,nameAssistant);
109
 
110
     nameAssistant.setWidth("100%");
111
 
112
	 // Saisie lieu
113
 
114
     HTML labelLocationAssistant= new HTML("Commune:&nbsp;");
115
     inner.setWidget(1,0,labelLocationAssistant);
116
     inner.setWidget(1,1,locationAssistant);
117
 
118
     locationAssistant.setWidth("100%");
119
 
120
     // Saisie Date
121
 
122
     choicesPopup.add(calendar);
123
 
124
     dateSelector.addClickListener(new ClickListener () {
125
 
126
       public void onClick(Widget w) {
127
 
128
    	   if (visible) {
129
    		  visible=false;
130
    		  choicesPopup.hide();
131
    	   }
132
    	   else {
133
    		visible=true;
134
    	    choicesPopup.show();
135
	        choicesPopup.setPopupPosition(dateSelector.getAbsoluteLeft(),
13 ddelon 136
	        dateSelector.getAbsoluteTop()  - dateSelector.getOffsetHeight() - choicesPopup.getOffsetHeight());
12 ddelon 137
	        choicesPopup.setWidth(dateSelector.getOffsetWidth() + "px");
138
    	   }
139
       }
140
 
141
     });
142
 
143
     calendar.addChangeListener(new ChangeListener() {
144
 
145
     public void onChange(Widget sender) {
146
 
147
       Date dateSelected=calendar.getDate();
148
       date.setText(dateSelected.getDate()+"/"+(dateSelected.getMonth()+1)+"/"+(dateSelected.getYear()+1900));
149
 
150
       visible=false;
151
       choicesPopup.hide();
152
     }
153
     });
154
 
155
    HTML labelDate= new HTML("Date:&nbsp;");
156
    inner.setWidget(2,0,labelDate);
157
 
158
    HorizontalPanel datePanel = new HorizontalPanel();
159
    datePanel.add(date);
160
    datePanel.add(dateSelector);
161
    inner.setWidget(2,1,datePanel);
162
 
163
 
164
 
165
 
166
    date.addKeyboardListener( new KeyboardListener() {
167
 
168
    		  public void onKeyDown(Widget arg0, char arg1, int arg2) {
169
 
170
 
171
    			  if(arg1 == KEY_ENTER)
172
    			    {
173
    			     mediator.onAddInventoryItem();
174
    			     date.setText("");
175
    			    }
176
 
177
    		  }
178
 
179
    		  public void onKeyUp(Widget arg0, char arg1, int arg2) {
180
    		  }
181
 
182
    		  public void onKeyPress(Widget arg0, char arg1, int arg2) {
183
    		  }
184
 
185
    		  }
186
    );
187
 
188
 
189
 
190
	 // Saisie Complement lieu
191
 
192
    HTML labelComplementLocation= new HTML("Station:&nbsp;");
193
    inner.setWidget(1,2,labelComplementLocation);
194
    inner.setWidget(1,3,complementLocation);
195
 
196
    complementLocation.setWidth("100%");
197
 
198
 
199
    complementLocation.addKeyboardListener( new KeyboardListener() {
200
 
201
		  public void onKeyDown(Widget arg0, char arg1, int arg2) {
202
 
203
 
204
			  if(arg1 == KEY_ENTER)
205
			    {
206
			     mediator.onAddInventoryItem();
207
			     complementLocation.setText("");
208
			    }
209
 
210
		  }
211
 
212
		  public void onKeyUp(Widget arg0, char arg1, int arg2) {
213
		  }
214
 
215
		  public void onKeyPress(Widget arg0, char arg1, int arg2) {
216
		  }
217
 
218
		  }
219
    );
220
 
221
 
222
	 // Saisie Commentaire
223
 
224
    HTML labelComment= new HTML("Notes:&nbsp;");
225
    inner.setWidget(2,2,labelComment);
226
    inner.setWidget(2,3,comment);
227
 
228
    comment.setWidth("100%");
229
 
230
 
231
    comment.addKeyboardListener( new KeyboardListener() {
232
 
233
		  public void onKeyDown(Widget arg0, char arg1, int arg2) {
234
 
235
 
236
			  if(arg1 == KEY_ENTER)
237
			    {
238
			     mediator.onAddInventoryItem();
239
			     comment.setText("");
240
			    }
241
 
242
		  }
243
 
244
		  public void onKeyUp(Widget arg0, char arg1, int arg2) {
245
		  }
246
 
247
		  public void onKeyPress(Widget arg0, char arg1, int arg2) {
248
		  }
249
 
250
		  }
251
  );
252
 
13 ddelon 253
 
254
    Button addButton = new Button("Ajout");
255
    Button updateButton = new Button("Modification");
256
 
257
    addButton.addClickListener(
12 ddelon 258
 
13 ddelon 259
    		new ClickListener() {
260
 
261
    			  public void onClick(Widget w) {
262
    				     mediator.onAddInventoryItem();
263
    			  }
264
    		}
265
    );
266
 
267
    HorizontalPanel buttonPanel = new HorizontalPanel();
268
 
269
 
270
    updateButton.addClickListener(
271
 
272
    		new ClickListener() {
273
 
274
    			  public void onClick(Widget w) {
275
    				     mediator.onModifyInventoryItem(ordre);
276
    			  }
277
    		}
278
    );
279
 
280
 
281
    buttonPanel.add(addButton);
282
    buttonPanel.add(updateButton);
283
 
12 ddelon 284
 
285
	 inner.setWidth("100%");
286
 
287
	 outer.add(inner);
288
	 outer.setCellWidth(inner, "100%");
13 ddelon 289
	 outer.setSpacing(20);
12 ddelon 290
 
13 ddelon 291
	outer.setHorizontalAlignment(HorizontalPanel.ALIGN_CENTER);
292
    outer.add(buttonPanel);
12 ddelon 293
 
294
 
295
 
296
 
297
    initWidget(outer);
298
 
299
 
300
  }
13 ddelon 301
 
302
	/*
303
	 * Numero d'ordre du relevé affiché
304
	 *
305
	 */
12 ddelon 306
 
13 ddelon 307
	public void setOrdre(String ordre) {
308
		this.ordre = ordre;
12 ddelon 309
	}
310
 
13 ddelon 311
 
312
	/*
313
	 * Numero d'ordre du relevé affiché
314
	 *
315
	 */
12 ddelon 316
 
13 ddelon 317
	public String getOrdre() {
318
		return this.ordre;
12 ddelon 319
	}
13 ddelon 320
 
321
 
322
 
323
  /**
324
	 * Mise a jour de l'affichage a partir de données deja saisie
325
	 *
326
	 */
327
 
328
	public void update() {
329
 
330
		HTTPRequest.asyncGet(serviceBaseUrl + "/Inventory/" + user + "/" + ordre,
331
 
332
		new ResponseTextHandler() {
333
 
334
			public void onCompletion(String str) {
335
 
336
				JSONValue jsonValue = JSONParser.parse(str);
337
				JSONArray jsonArray;
338
 
339
 
340
				if ((jsonArray = jsonValue.isArray()) != null) {
341
							// Nom saisi
342
							nameAssistant.setText(((JSONString) jsonArray.get(0)).stringValue());
343
 
344
							// Numero nomenclatural
345
 
346
							String ann=((JSONString) jsonArray .get(3)).stringValue();
347
 
348
							if (ann.compareTo("0")!=0) {
349
								nameAssistant.setValue(ann);
350
							}
351
 
352
							// Commune
353
							String aloc=((JSONString) jsonArray .get(6)).stringValue();
354
 
355
							if (aloc.compareTo("000null")!=0) {
356
								locationAssistant.setText(aloc);
357
							}
358
							else {
359
								locationAssistant.setText("");
360
							}
361
 
362
							String adate=((JSONString) jsonArray .get(8)).stringValue();
363
 
364
//							Date
365
							if (adate.compareTo("0000-00-00 00:00:00")!=0) {
366
								date.setText(adate);
367
							}
368
							else {
369
								date.setText("");
370
							}
371
 
372
 
373
							String astation=((JSONString) jsonArray .get(9)).stringValue();
374
 
375
//							Station
376
							if (astation.compareTo("null")!=0) {
377
								complementLocation.setText(astation);
378
							}
379
							else {
380
								complementLocation.setText("");
381
							}
382
 
383
 
384
							String acomment=((JSONString) jsonArray .get(10)).stringValue();
385
//							Notes
386
							if (acomment.compareTo("null")!=0) {
387
								comment.setText(acomment);
388
							}
389
							else {
390
								comment.setText("");
391
							}
392
 
393
				}
394
 
395
 
396
 
397
			}
398
		});
399
 
400
	}
401
 
402
 
12 ddelon 403
}