| 22 |
ddelon |
1 |
/**
|
|
|
2 |
David Delon david.delon@clapas.net 2007
|
|
|
3 |
|
|
|
4 |
Ce logiciel est régi par la licence CeCILL soumise au droit français et
|
|
|
5 |
respectant les principes de diffusion des logiciels libres. Vous pouvez
|
|
|
6 |
utiliser, modifier et/ou redistribuer ce programme sous les conditions
|
|
|
7 |
de la licence CeCILL telle que diffusée par le CEA, le CNRS et l'INRIA
|
|
|
8 |
sur le site "http://www.cecill.info".
|
|
|
9 |
En contrepartie de l'accessibilité au code source et des droits de copie,
|
|
|
10 |
de modification et de redistribution accordés par cette licence, il n'est
|
|
|
11 |
offert aux utilisateurs qu'une garantie limitée. Pour les mêmes raisons,
|
|
|
12 |
seule une responsabilité restreinte pèse sur l'auteur du programme, le
|
|
|
13 |
titulaire des droits patrimoniaux et les concédants successifs.
|
|
|
14 |
|
|
|
15 |
A cet égard l'attention de l'utilisateur est attirée sur les risques
|
|
|
16 |
associés au chargement, à l'utilisation, à la modification et/ou au
|
|
|
17 |
développement et à la reproduction du logiciel par l'utilisateur étant
|
|
|
18 |
donné sa spécificité de logiciel libre, qui peut le rendre complexe à
|
|
|
19 |
manipuler et qui le réserve donc à des développeurs et des professionnels
|
|
|
20 |
avertis possédant des connaissances informatiques approfondies. Les
|
|
|
21 |
utilisateurs sont donc invités à charger et tester l'adéquation du
|
|
|
22 |
logiciel à leurs besoins dans des conditions permettant d'assurer la
|
|
|
23 |
sécurité de leurs systèmes et ou de leurs données et, plus généralement,
|
|
|
24 |
à l'utiliser et l'exploiter dans les mêmes conditions de sécurité.
|
|
|
25 |
|
|
|
26 |
Le fait que vous puissiez accéder à cet en-tête signifie que vous avez
|
|
|
27 |
pris connaissance de la licence CeCILL, et que vous en avez accepté les
|
|
|
28 |
termes.
|
|
|
29 |
|
|
|
30 |
*/
|
|
|
31 |
|
| 12 |
ddelon |
32 |
/*
|
| 22 |
ddelon |
33 |
* EntryPanel.java (Composite de Panel)
|
| 12 |
ddelon |
34 |
*
|
| 22 |
ddelon |
35 |
* Cas d'utilisation :
|
|
|
36 |
* Saisie assistee (completion nom et completion commune) de releves.
|
|
|
37 |
* L'identification n'est pas obligatoire
|
|
|
38 |
*
|
|
|
39 |
* 1 : L'utilisateur saisit a minima un nom de plante
|
|
|
40 |
* 1: Le nom de plante provient d'une application externe : il est deduit du nuremo nomenclatural transmis en historique
|
|
|
41 |
* 2 : Le programme assiste la saisie de nom de plante ou de localite par interrogation du systeme distant
|
|
|
42 |
* 3 : L'utilisateur choisi le type de mise (ajout ou modification)
|
|
|
43 |
* 3 : L'utilisateur valide sa saisie
|
|
|
44 |
* 4 : Le programme transmet au systeme distant la nouvelle saisie pour l'identifiant en cours
|
|
|
45 |
* 5 : Le programme transmet au systeme local un evenement annoncant une nouvelle saisie
|
| 12 |
ddelon |
46 |
*
|
|
|
47 |
*
|
| 22 |
ddelon |
48 |
* Affichage detail d'un observation
|
|
|
49 |
* 1 : Le programme affiche les donnees d'inventaire pour l'identifiant enregistre et pour le numero d'ordre transmis
|
|
|
50 |
*
|
| 12 |
ddelon |
51 |
*/
|
| 22 |
ddelon |
52 |
|
|
|
53 |
|
| 12 |
ddelon |
54 |
package org.tela_botanica.client;
|
|
|
55 |
|
|
|
56 |
import java.util.Date;
|
|
|
57 |
|
| 13 |
ddelon |
58 |
import com.google.gwt.json.client.JSONArray;
|
|
|
59 |
import com.google.gwt.json.client.JSONParser;
|
|
|
60 |
import com.google.gwt.json.client.JSONString;
|
|
|
61 |
import com.google.gwt.json.client.JSONValue;
|
|
|
62 |
import com.google.gwt.user.client.HTTPRequest;
|
| 14 |
ddelon |
63 |
import com.google.gwt.user.client.History;
|
| 13 |
ddelon |
64 |
import com.google.gwt.user.client.ResponseTextHandler;
|
| 12 |
ddelon |
65 |
import com.google.gwt.user.client.ui.Button;
|
|
|
66 |
import com.google.gwt.user.client.ui.ChangeListener;
|
| 13 |
ddelon |
67 |
import com.google.gwt.user.client.ui.CheckBox;
|
| 12 |
ddelon |
68 |
import com.google.gwt.user.client.ui.ClickListener;
|
|
|
69 |
import com.google.gwt.user.client.ui.Composite;
|
|
|
70 |
import com.google.gwt.user.client.ui.Grid;
|
|
|
71 |
import com.google.gwt.user.client.ui.HTML;
|
|
|
72 |
import com.google.gwt.user.client.ui.HorizontalPanel;
|
|
|
73 |
import com.google.gwt.user.client.ui.KeyboardListener;
|
|
|
74 |
import com.google.gwt.user.client.ui.PopupPanel;
|
|
|
75 |
import com.google.gwt.user.client.ui.TextBox;
|
|
|
76 |
import com.google.gwt.user.client.ui.VerticalPanel;
|
|
|
77 |
import com.google.gwt.user.client.ui.Widget;
|
|
|
78 |
|
|
|
79 |
|
| 13 |
ddelon |
80 |
public class EntryPanel extends Composite {
|
| 12 |
ddelon |
81 |
|
|
|
82 |
private NameAssistant nameAssistant = null;
|
|
|
83 |
private LocationAssistant locationAssistant = null;
|
| 22 |
ddelon |
84 |
private TextBox date = new TextBox();
|
|
|
85 |
private TextBox complementLocation = new TextBox();
|
|
|
86 |
private TextBox comment = new TextBox();
|
|
|
87 |
private Button dateSelector = new Button("...");
|
| 12 |
ddelon |
88 |
boolean visible=false;
|
| 22 |
ddelon |
89 |
private Mediator mediator=null;
|
| 12 |
ddelon |
90 |
|
| 13 |
ddelon |
91 |
|
|
|
92 |
private String user= null;
|
|
|
93 |
private String ordre =null;
|
|
|
94 |
|
| 22 |
ddelon |
95 |
private CalendarWidget calendar = null; // Lazy instantiation
|
|
|
96 |
private PopupPanel choicesPopup = null; // Lazy instantiation
|
| 12 |
ddelon |
97 |
|
|
|
98 |
public EntryPanel(final Mediator med) {
|
|
|
99 |
|
|
|
100 |
|
|
|
101 |
mediator=med;
|
| 22 |
ddelon |
102 |
user=mediator.getUser();
|
| 12 |
ddelon |
103 |
|
|
|
104 |
mediator.registerEntryPanel(this);
|
|
|
105 |
|
|
|
106 |
mediator.registerDate(date);
|
|
|
107 |
mediator.registerComment(comment);
|
|
|
108 |
mediator.registerComplementLocation(complementLocation);
|
|
|
109 |
|
| 13 |
ddelon |
110 |
|
| 12 |
ddelon |
111 |
VerticalPanel outer = new VerticalPanel();
|
|
|
112 |
|
|
|
113 |
|
| 22 |
ddelon |
114 |
outer.add(new HTML("<b>Saisir un relevé :</b>"));
|
| 12 |
ddelon |
115 |
|
|
|
116 |
|
|
|
117 |
Grid inner = new Grid(3,4);
|
|
|
118 |
|
|
|
119 |
for (int i=0; i<3;i++) {
|
|
|
120 |
inner.getCellFormatter().setWidth(i, 0, "3%");
|
|
|
121 |
inner.getCellFormatter().setWidth(i, 1, "47%");
|
|
|
122 |
inner.getCellFormatter().setWidth(i, 2, "3%");
|
|
|
123 |
inner.getCellFormatter().setWidth(i, 3, "47%");
|
|
|
124 |
}
|
|
|
125 |
|
|
|
126 |
|
|
|
127 |
nameAssistant = new NameAssistant(mediator);
|
|
|
128 |
locationAssistant = new LocationAssistant(mediator);
|
|
|
129 |
|
| 14 |
ddelon |
130 |
|
| 12 |
ddelon |
131 |
// Saisie Nom
|
|
|
132 |
|
| 22 |
ddelon |
133 |
inner.setHTML(0,0,"Espèce: ");
|
| 12 |
ddelon |
134 |
inner.setWidget(0,1,nameAssistant);
|
|
|
135 |
|
|
|
136 |
nameAssistant.setWidth("100%");
|
|
|
137 |
|
|
|
138 |
// Saisie lieu
|
|
|
139 |
|
| 22 |
ddelon |
140 |
inner.setHTML(1,0,"Commune: ");
|
| 12 |
ddelon |
141 |
inner.setWidget(1,1,locationAssistant);
|
|
|
142 |
|
|
|
143 |
locationAssistant.setWidth("100%");
|
|
|
144 |
|
|
|
145 |
// Saisie Date
|
|
|
146 |
|
|
|
147 |
|
|
|
148 |
dateSelector.addClickListener(new ClickListener () {
|
|
|
149 |
|
|
|
150 |
public void onClick(Widget w) {
|
|
|
151 |
|
|
|
152 |
if (visible) {
|
|
|
153 |
visible=false;
|
|
|
154 |
choicesPopup.hide();
|
|
|
155 |
}
|
|
|
156 |
else {
|
|
|
157 |
visible=true;
|
| 22 |
ddelon |
158 |
if (calendar==null) { // Lazy instantiation
|
|
|
159 |
calendar = new CalendarWidget();
|
|
|
160 |
choicesPopup = new PopupPanel(true);
|
|
|
161 |
choicesPopup.add(calendar);
|
|
|
162 |
calendar.addChangeListener(new ChangeListener() {
|
|
|
163 |
|
|
|
164 |
public void onChange(Widget sender) {
|
|
|
165 |
|
|
|
166 |
Date dateSelected=calendar.getDate();
|
|
|
167 |
date.setText(dateSelected.getDate()+"/"+(dateSelected.getMonth()+1)+"/"+(dateSelected.getYear()+1900));
|
|
|
168 |
visible=false;
|
|
|
169 |
choicesPopup.hide();
|
|
|
170 |
}
|
|
|
171 |
});
|
|
|
172 |
|
|
|
173 |
}
|
|
|
174 |
|
| 12 |
ddelon |
175 |
choicesPopup.show();
|
|
|
176 |
choicesPopup.setPopupPosition(dateSelector.getAbsoluteLeft(),
|
| 13 |
ddelon |
177 |
dateSelector.getAbsoluteTop() - dateSelector.getOffsetHeight() - choicesPopup.getOffsetHeight());
|
| 12 |
ddelon |
178 |
choicesPopup.setWidth(dateSelector.getOffsetWidth() + "px");
|
|
|
179 |
}
|
|
|
180 |
}
|
|
|
181 |
|
|
|
182 |
});
|
|
|
183 |
|
| 22 |
ddelon |
184 |
|
|
|
185 |
inner.setHTML(2,0,"Date: ");
|
| 12 |
ddelon |
186 |
|
|
|
187 |
HorizontalPanel datePanel = new HorizontalPanel();
|
|
|
188 |
datePanel.add(date);
|
|
|
189 |
datePanel.add(dateSelector);
|
|
|
190 |
inner.setWidget(2,1,datePanel);
|
|
|
191 |
|
| 22 |
ddelon |
192 |
// Saisie date
|
|
|
193 |
|
| 12 |
ddelon |
194 |
date.addKeyboardListener( new KeyboardListener() {
|
|
|
195 |
|
|
|
196 |
public void onKeyDown(Widget arg0, char arg1, int arg2) {
|
|
|
197 |
if(arg1 == KEY_ENTER)
|
|
|
198 |
{
|
|
|
199 |
mediator.onAddInventoryItem();
|
|
|
200 |
date.setText("");
|
|
|
201 |
}
|
|
|
202 |
}
|
|
|
203 |
|
| 22 |
ddelon |
204 |
public void onKeyUp(Widget arg0, char arg1, int arg2) { }
|
|
|
205 |
public void onKeyPress(Widget arg0, char arg1, int arg2) { }
|
| 12 |
ddelon |
206 |
|
|
|
207 |
}
|
|
|
208 |
);
|
|
|
209 |
|
|
|
210 |
|
|
|
211 |
|
| 22 |
ddelon |
212 |
// Saisie Complement de lieu (station)
|
| 12 |
ddelon |
213 |
|
| 22 |
ddelon |
214 |
inner.setHTML(1,2,"Station: ");
|
| 12 |
ddelon |
215 |
inner.setWidget(1,3,complementLocation);
|
|
|
216 |
|
|
|
217 |
complementLocation.setWidth("100%");
|
|
|
218 |
|
|
|
219 |
|
|
|
220 |
complementLocation.addKeyboardListener( new KeyboardListener() {
|
|
|
221 |
|
|
|
222 |
public void onKeyDown(Widget arg0, char arg1, int arg2) {
|
|
|
223 |
if(arg1 == KEY_ENTER)
|
|
|
224 |
{
|
|
|
225 |
mediator.onAddInventoryItem();
|
|
|
226 |
complementLocation.setText("");
|
|
|
227 |
}
|
|
|
228 |
|
|
|
229 |
}
|
|
|
230 |
|
| 22 |
ddelon |
231 |
public void onKeyUp(Widget arg0, char arg1, int arg2) { }
|
| 12 |
ddelon |
232 |
|
| 22 |
ddelon |
233 |
public void onKeyPress(Widget arg0, char arg1, int arg2) { }
|
| 12 |
ddelon |
234 |
|
|
|
235 |
}
|
|
|
236 |
);
|
|
|
237 |
|
|
|
238 |
|
|
|
239 |
// Saisie Commentaire
|
|
|
240 |
|
| 22 |
ddelon |
241 |
inner.setHTML(2,2,"Notes: ");
|
| 12 |
ddelon |
242 |
inner.setWidget(2,3,comment);
|
|
|
243 |
|
|
|
244 |
comment.setWidth("100%");
|
|
|
245 |
|
|
|
246 |
|
|
|
247 |
comment.addKeyboardListener( new KeyboardListener() {
|
|
|
248 |
|
|
|
249 |
public void onKeyDown(Widget arg0, char arg1, int arg2) {
|
|
|
250 |
if(arg1 == KEY_ENTER)
|
|
|
251 |
{
|
|
|
252 |
mediator.onAddInventoryItem();
|
|
|
253 |
comment.setText("");
|
|
|
254 |
}
|
|
|
255 |
|
|
|
256 |
}
|
|
|
257 |
|
| 22 |
ddelon |
258 |
public void onKeyUp(Widget arg0, char arg1, int arg2) { }
|
|
|
259 |
public void onKeyPress(Widget arg0, char arg1, int arg2) { }
|
| 12 |
ddelon |
260 |
|
|
|
261 |
}
|
|
|
262 |
);
|
|
|
263 |
|
| 13 |
ddelon |
264 |
|
| 22 |
ddelon |
265 |
Button validButton = new Button("Valider");
|
|
|
266 |
|
| 13 |
ddelon |
267 |
|
| 22 |
ddelon |
268 |
validButton.addClickListener(
|
| 12 |
ddelon |
269 |
|
| 13 |
ddelon |
270 |
new ClickListener() {
|
|
|
271 |
|
|
|
272 |
public void onClick(Widget w) {
|
| 22 |
ddelon |
273 |
if (ordre==null) {
|
| 13 |
ddelon |
274 |
mediator.onAddInventoryItem();
|
| 22 |
ddelon |
275 |
}
|
|
|
276 |
else {
|
| 13 |
ddelon |
277 |
mediator.onModifyInventoryItem(ordre);
|
| 22 |
ddelon |
278 |
ordre=null;
|
|
|
279 |
}
|
| 13 |
ddelon |
280 |
}
|
|
|
281 |
}
|
|
|
282 |
);
|
|
|
283 |
|
|
|
284 |
|
| 22 |
ddelon |
285 |
|
|
|
286 |
HorizontalPanel actionPanel= new HorizontalPanel();
|
|
|
287 |
|
|
|
288 |
actionPanel.add(validButton);
|
| 13 |
ddelon |
289 |
|
| 12 |
ddelon |
290 |
|
| 22 |
ddelon |
291 |
inner.setWidth("100%");
|
| 12 |
ddelon |
292 |
|
| 22 |
ddelon |
293 |
outer.add(inner);
|
|
|
294 |
outer.setCellWidth(inner, "100%");
|
|
|
295 |
outer.setSpacing(10);
|
| 12 |
ddelon |
296 |
|
| 13 |
ddelon |
297 |
outer.setHorizontalAlignment(HorizontalPanel.ALIGN_CENTER);
|
| 22 |
ddelon |
298 |
outer.add(actionPanel);
|
| 12 |
ddelon |
299 |
|
|
|
300 |
|
| 14 |
ddelon |
301 |
// Initialisation si provenance d'un lien
|
|
|
302 |
|
|
|
303 |
if (History.getToken().length()>0) {
|
| 12 |
ddelon |
304 |
|
| 14 |
ddelon |
305 |
final String anum=History.getToken();
|
|
|
306 |
|
| 22 |
ddelon |
307 |
HTTPRequest.asyncGet(mediator.getServiceBaseUrl() + "/Name/" + anum,
|
| 14 |
ddelon |
308 |
new ResponseTextHandler() {
|
|
|
309 |
|
|
|
310 |
public void onCompletion(String strcomplete) {
|
|
|
311 |
|
|
|
312 |
JSONValue jsonValue = JSONParser.parse(strcomplete);
|
|
|
313 |
JSONArray jsonArray;
|
|
|
314 |
|
|
|
315 |
if ((jsonArray = jsonValue.isArray()) != null) {
|
|
|
316 |
|
|
|
317 |
String aname = ((JSONString) jsonArray.get(0)).stringValue();
|
|
|
318 |
|
|
|
319 |
// Nom
|
|
|
320 |
|
|
|
321 |
if (aname.compareTo("null")!=0) {
|
|
|
322 |
nameAssistant.setText(((JSONString) jsonArray.get(0)).stringValue());
|
|
|
323 |
|
|
|
324 |
// Numero nomenclatural
|
|
|
325 |
|
|
|
326 |
nameAssistant.setValue(anum);
|
|
|
327 |
|
|
|
328 |
}
|
|
|
329 |
|
|
|
330 |
}
|
|
|
331 |
}
|
|
|
332 |
|
|
|
333 |
});
|
|
|
334 |
|
|
|
335 |
|
|
|
336 |
}
|
| 12 |
ddelon |
337 |
|
| 14 |
ddelon |
338 |
|
|
|
339 |
|
| 12 |
ddelon |
340 |
initWidget(outer);
|
|
|
341 |
|
|
|
342 |
|
|
|
343 |
}
|
| 13 |
ddelon |
344 |
|
|
|
345 |
/*
|
|
|
346 |
* Numero d'ordre du relevé affiché
|
|
|
347 |
*
|
|
|
348 |
*/
|
| 12 |
ddelon |
349 |
|
| 13 |
ddelon |
350 |
public void setOrdre(String ordre) {
|
|
|
351 |
this.ordre = ordre;
|
| 12 |
ddelon |
352 |
}
|
|
|
353 |
|
| 13 |
ddelon |
354 |
|
|
|
355 |
/*
|
|
|
356 |
* Numero d'ordre du relevé affiché
|
|
|
357 |
*
|
|
|
358 |
*/
|
| 12 |
ddelon |
359 |
|
| 13 |
ddelon |
360 |
public String getOrdre() {
|
|
|
361 |
return this.ordre;
|
| 12 |
ddelon |
362 |
}
|
| 13 |
ddelon |
363 |
|
|
|
364 |
|
|
|
365 |
|
|
|
366 |
/**
|
|
|
367 |
* Mise a jour de l'affichage a partir de données deja saisie
|
|
|
368 |
*
|
|
|
369 |
*/
|
|
|
370 |
|
|
|
371 |
public void update() {
|
|
|
372 |
|
| 22 |
ddelon |
373 |
HTTPRequest.asyncGet(mediator.getServiceBaseUrl() + "/Inventory/" + user + "/" + ordre,
|
| 13 |
ddelon |
374 |
|
|
|
375 |
new ResponseTextHandler() {
|
|
|
376 |
|
|
|
377 |
public void onCompletion(String str) {
|
|
|
378 |
|
|
|
379 |
JSONValue jsonValue = JSONParser.parse(str);
|
|
|
380 |
JSONArray jsonArray;
|
|
|
381 |
|
|
|
382 |
|
|
|
383 |
if ((jsonArray = jsonValue.isArray()) != null) {
|
|
|
384 |
// Nom saisi
|
|
|
385 |
nameAssistant.setText(((JSONString) jsonArray.get(0)).stringValue());
|
|
|
386 |
|
|
|
387 |
// Numero nomenclatural
|
|
|
388 |
|
|
|
389 |
String ann=((JSONString) jsonArray .get(3)).stringValue();
|
|
|
390 |
|
|
|
391 |
if (ann.compareTo("0")!=0) {
|
|
|
392 |
nameAssistant.setValue(ann);
|
|
|
393 |
}
|
|
|
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 |
}
|
| 13 |
ddelon |
447 |
|
| 12 |
ddelon |
448 |
}
|
| 22 |
ddelon |
449 |
|
|
|
450 |
/* +--Fin du code ---------------------------------------------------------------------------------------+
|
|
|
451 |
* $Log$
|
|
|
452 |
*
|
|
|
453 |
*/
|