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