Subversion Repositories eFlore/Archives.cel-v1

Rev

Rev 12 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 12 Rev 13
1
/*
1
/*
2
 * Copyright 2006 Google Inc.
2
 * Copyright 2006 Google Inc.
3
 * 
3
 * 
4
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
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
5
 * use this file except in compliance with the License. You may obtain a copy of
6
 * the License at
6
 * the License at
7
 * 
7
 * 
8
 * http://www.apache.org/licenses/LICENSE-2.0
8
 * http://www.apache.org/licenses/LICENSE-2.0
9
 * 
9
 * 
10
 * Unless required by applicable law or agreed to in writing, software
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
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
12
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
 * License for the specific language governing permissions and limitations under
13
 * License for the specific language governing permissions and limitations under
14
 * the License.
14
 * the License.
15
 */
15
 */
16
package org.tela_botanica.client;
16
package org.tela_botanica.client;
17
 
17
 
18
import java.util.Date;
18
import java.util.Date;
-
 
19
 
-
 
20
import com.google.gwt.json.client.JSONArray;
-
 
21
import com.google.gwt.json.client.JSONParser;
19
 
22
import com.google.gwt.json.client.JSONString;
20
import com.google.gwt.user.client.DOM;
23
import com.google.gwt.json.client.JSONValue;
-
 
24
import com.google.gwt.user.client.HTTPRequest;
21
import com.google.gwt.user.client.Element;
25
import com.google.gwt.user.client.ResponseTextHandler;
22
import com.google.gwt.user.client.ui.Button;
26
import com.google.gwt.user.client.ui.Button;
-
 
27
import com.google.gwt.user.client.ui.ChangeListener;
23
import com.google.gwt.user.client.ui.ChangeListener;
28
import com.google.gwt.user.client.ui.CheckBox;
24
import com.google.gwt.user.client.ui.ClickListener;
29
import com.google.gwt.user.client.ui.ClickListener;
25
import com.google.gwt.user.client.ui.Composite;
30
import com.google.gwt.user.client.ui.Composite;
26
import com.google.gwt.user.client.ui.Grid;
31
import com.google.gwt.user.client.ui.Grid;
27
import com.google.gwt.user.client.ui.HTML;
32
import com.google.gwt.user.client.ui.HTML;
28
import com.google.gwt.user.client.ui.HorizontalPanel;
33
import com.google.gwt.user.client.ui.HorizontalPanel;
29
import com.google.gwt.user.client.ui.KeyboardListener;
34
import com.google.gwt.user.client.ui.KeyboardListener;
30
import com.google.gwt.user.client.ui.PopupPanel;
35
import com.google.gwt.user.client.ui.PopupPanel;
31
import com.google.gwt.user.client.ui.RootPanel;
-
 
32
import com.google.gwt.user.client.ui.TextBox;
36
import com.google.gwt.user.client.ui.TextBox;
33
import com.google.gwt.user.client.ui.UIObject;
-
 
34
import com.google.gwt.user.client.ui.VerticalPanel;
37
import com.google.gwt.user.client.ui.VerticalPanel;
35
import com.google.gwt.user.client.ui.Widget;
38
import com.google.gwt.user.client.ui.Widget;
36
 
39
 
37
/**
40
/**
38
 * Composite permet de wrapper des Widget pour creer un nouveau Widget cf methode initWidget()
41
 * Composite permet de wrapper des Widget pour creer un nouveau Widget cf methode initWidget()
39
 */
42
 */
40
 
43
 
41
public class EntryPanel extends Composite  implements ClickListener {
44
public class EntryPanel extends Composite   {
42
	
45
	
43
  private NameAssistant nameAssistant = null;
46
  private NameAssistant nameAssistant = null;
44
  private LocationAssistant locationAssistant = null;
47
  private LocationAssistant locationAssistant = null;
45
  TextBox date = new TextBox();
48
  TextBox date = new TextBox();
46
  TextBox complementLocation = new TextBox();
49
  TextBox complementLocation = new TextBox();
47
  TextBox comment = new TextBox();
50
  TextBox comment = new TextBox();
48
  Button dateSelector = new Button("...");
51
  Button dateSelector = new Button("...");
49
  boolean visible=false;
52
  boolean visible=false;
50
  Mediator mediator=null;
53
  Mediator mediator=null;
-
 
54
 
-
 
55
  private String serviceBaseUrl = null;
-
 
56
  
-
 
57
  private String user= null;
-
 
58
  private String ordre =null;
51
 
59
  
52
  final CalendarWidget calendar = new CalendarWidget();
60
  final CalendarWidget calendar = new CalendarWidget();
53
  
61
  
54
  private PopupPanel choicesPopup = new PopupPanel(true);
62
  private PopupPanel choicesPopup = new PopupPanel(true);
55
 
63
 
56
  public EntryPanel(final Mediator med) {
64
  public EntryPanel(final Mediator med) {
57
	 
65
	 
58
	  
66
	  
59
   mediator=med;
67
   mediator=med;
60
 
68
 
61
   
69
   
62
   
70
   
63
   mediator.registerEntryPanel(this);
71
   mediator.registerEntryPanel(this);
64
   
72
   
65
   mediator.registerDate(date);
73
   mediator.registerDate(date);
66
   mediator.registerComment(comment);
74
   mediator.registerComment(comment);
67
   mediator.registerComplementLocation(complementLocation);
75
   mediator.registerComplementLocation(complementLocation);
68
   
76
   
-
 
77
   
-
 
78
   user=mediator.getUser();
-
 
79
   serviceBaseUrl = mediator.getServiceBaseUrl();
-
 
80
 
69
   
81
   
70
   
82
   
71
   VerticalPanel outer = new VerticalPanel();
83
   VerticalPanel outer = new VerticalPanel();
72
   
84
   
73
 
85
 
74
	outer.add(new HTML("<b>Nouvelle observation:</b>"));
86
//	outer.add(new HTML("<b>Nouvelle observation:</b>"));
75
 
87
 
76
   
88
   
77
   
89
   
78
   Grid inner = new Grid(3,4);
90
   Grid inner = new Grid(3,4);
79
 
91
 
80
   for (int i=0; i<3;i++) {
92
   for (int i=0; i<3;i++) {
81
	inner.getCellFormatter().setWidth(i, 0, "3%");
93
	inner.getCellFormatter().setWidth(i, 0, "3%");
82
	inner.getCellFormatter().setWidth(i, 1, "47%");
94
	inner.getCellFormatter().setWidth(i, 1, "47%");
83
	inner.getCellFormatter().setWidth(i, 2, "3%");
95
	inner.getCellFormatter().setWidth(i, 2, "3%");
84
	inner.getCellFormatter().setWidth(i, 3, "47%");
96
	inner.getCellFormatter().setWidth(i, 3, "47%");
85
   }
97
   }
86
 
98
 
87
 
99
 
88
	nameAssistant = new NameAssistant(mediator);
100
	nameAssistant = new NameAssistant(mediator);
89
	locationAssistant = new LocationAssistant(mediator);
101
	locationAssistant = new LocationAssistant(mediator);
90
	
102
	
91
 
103
 
92
	// Saisie Nom
104
	// Saisie Nom
93
	
105
	
94
     HTML labelNameAssistant = new HTML("Esp&egrave;ce:&nbsp;");
106
     HTML labelNameAssistant = new HTML("Esp&egrave;ce:&nbsp;");
95
     inner.setWidget(0,0,labelNameAssistant);
107
     inner.setWidget(0,0,labelNameAssistant);
96
     inner.setWidget(0,1,nameAssistant);
108
     inner.setWidget(0,1,nameAssistant);
97
    
109
    
98
     nameAssistant.setWidth("100%");
110
     nameAssistant.setWidth("100%");
99
 
111
 
100
	 // Saisie lieu
112
	 // Saisie lieu
101
	 
113
	 
102
     HTML labelLocationAssistant= new HTML("Commune:&nbsp;");
114
     HTML labelLocationAssistant= new HTML("Commune:&nbsp;");
103
     inner.setWidget(1,0,labelLocationAssistant);
115
     inner.setWidget(1,0,labelLocationAssistant);
104
     inner.setWidget(1,1,locationAssistant);
116
     inner.setWidget(1,1,locationAssistant);
105
 
117
 
106
     locationAssistant.setWidth("100%");
118
     locationAssistant.setWidth("100%");
107
   
119
   
108
     // Saisie Date 
120
     // Saisie Date 
109
	 
121
	 
110
     choicesPopup.add(calendar);
122
     choicesPopup.add(calendar);
111
     
123
     
112
     dateSelector.addClickListener(new ClickListener () {
124
     dateSelector.addClickListener(new ClickListener () {
113
    
125
    
114
       public void onClick(Widget w) {
126
       public void onClick(Widget w) {
115
    	  
127
    	  
116
    	   if (visible) {
128
    	   if (visible) {
117
    		  visible=false; 
129
    		  visible=false; 
118
    		  choicesPopup.hide();
130
    		  choicesPopup.hide();
119
    	   }
131
    	   }
120
    	   else {
132
    	   else {
121
    		visible=true; 
133
    		visible=true; 
122
    	    choicesPopup.show();
134
    	    choicesPopup.show();
123
	        choicesPopup.setPopupPosition(dateSelector.getAbsoluteLeft(),
135
	        choicesPopup.setPopupPosition(dateSelector.getAbsoluteLeft(),
124
	        dateSelector.getAbsoluteTop()  + dateSelector.getOffsetHeight());
136
	        dateSelector.getAbsoluteTop()  - dateSelector.getOffsetHeight() - choicesPopup.getOffsetHeight());
125
	        choicesPopup.setWidth(dateSelector.getOffsetWidth() + "px");
137
	        choicesPopup.setWidth(dateSelector.getOffsetWidth() + "px");
126
    	   }
138
    	   }
127
       }
139
       }
128
     
140
     
129
     });
141
     });
130
     
142
     
131
     calendar.addChangeListener(new ChangeListener() {
143
     calendar.addChangeListener(new ChangeListener() {
132
 
144
 
133
     public void onChange(Widget sender) {
145
     public void onChange(Widget sender) {
134
    	 
146
    	 
135
       Date dateSelected=calendar.getDate();
147
       Date dateSelected=calendar.getDate();
136
       date.setText(dateSelected.getDate()+"/"+(dateSelected.getMonth()+1)+"/"+(dateSelected.getYear()+1900));
148
       date.setText(dateSelected.getDate()+"/"+(dateSelected.getMonth()+1)+"/"+(dateSelected.getYear()+1900));
137
       
149
       
138
       visible=false; 
150
       visible=false; 
139
       choicesPopup.hide();
151
       choicesPopup.hide();
140
     }
152
     }
141
     });
153
     });
142
     
154
     
143
    HTML labelDate= new HTML("Date:&nbsp;");
155
    HTML labelDate= new HTML("Date:&nbsp;");
144
    inner.setWidget(2,0,labelDate);
156
    inner.setWidget(2,0,labelDate);
145
    
157
    
146
    HorizontalPanel datePanel = new HorizontalPanel();
158
    HorizontalPanel datePanel = new HorizontalPanel();
147
    datePanel.add(date);
159
    datePanel.add(date);
148
    datePanel.add(dateSelector);
160
    datePanel.add(dateSelector);
149
    inner.setWidget(2,1,datePanel);
161
    inner.setWidget(2,1,datePanel);
150
    
162
    
151
 
163
 
152
    
164
    
153
    
165
    
154
    date.addKeyboardListener( new KeyboardListener() {
166
    date.addKeyboardListener( new KeyboardListener() {
155
 
167
 
156
    		  public void onKeyDown(Widget arg0, char arg1, int arg2) {
168
    		  public void onKeyDown(Widget arg0, char arg1, int arg2) {
157
    			  
169
    			  
158
    			  
170
    			  
159
    			  if(arg1 == KEY_ENTER)
171
    			  if(arg1 == KEY_ENTER)
160
    			    {
172
    			    {
161
    			     mediator.onAddInventoryItem(); 
173
    			     mediator.onAddInventoryItem(); 
162
    			     date.setText("");
174
    			     date.setText("");
163
    			    }
175
    			    }
164
 
176
 
165
    		  }
177
    		  }
166
    		  
178
    		  
167
    		  public void onKeyUp(Widget arg0, char arg1, int arg2) {
179
    		  public void onKeyUp(Widget arg0, char arg1, int arg2) {
168
    		  }
180
    		  }
169
 
181
 
170
    		  public void onKeyPress(Widget arg0, char arg1, int arg2) {
182
    		  public void onKeyPress(Widget arg0, char arg1, int arg2) {
171
    		  }
183
    		  }
172
    		  
184
    		  
173
    		  }
185
    		  }
174
    );
186
    );
175
    
187
    
176
  
188
  
177
 
189
 
178
	 // Saisie Complement lieu 
190
	 // Saisie Complement lieu 
179
	 
191
	 
180
    HTML labelComplementLocation= new HTML("Station:&nbsp;");
192
    HTML labelComplementLocation= new HTML("Station:&nbsp;");
181
    inner.setWidget(1,2,labelComplementLocation);
193
    inner.setWidget(1,2,labelComplementLocation);
182
    inner.setWidget(1,3,complementLocation);
194
    inner.setWidget(1,3,complementLocation);
183
 
195
 
184
    complementLocation.setWidth("100%");
196
    complementLocation.setWidth("100%");
185
 
197
 
186
    
198
    
187
    complementLocation.addKeyboardListener( new KeyboardListener() {
199
    complementLocation.addKeyboardListener( new KeyboardListener() {
188
 
200
 
189
		  public void onKeyDown(Widget arg0, char arg1, int arg2) {
201
		  public void onKeyDown(Widget arg0, char arg1, int arg2) {
190
			  
202
			  
191
			  
203
			  
192
			  if(arg1 == KEY_ENTER)
204
			  if(arg1 == KEY_ENTER)
193
			    {
205
			    {
194
			     mediator.onAddInventoryItem(); 
206
			     mediator.onAddInventoryItem(); 
195
			     complementLocation.setText("");
207
			     complementLocation.setText("");
196
			    }
208
			    }
197
 
209
 
198
		  }
210
		  }
199
		  
211
		  
200
		  public void onKeyUp(Widget arg0, char arg1, int arg2) {
212
		  public void onKeyUp(Widget arg0, char arg1, int arg2) {
201
		  }
213
		  }
202
 
214
 
203
		  public void onKeyPress(Widget arg0, char arg1, int arg2) {
215
		  public void onKeyPress(Widget arg0, char arg1, int arg2) {
204
		  }
216
		  }
205
		  
217
		  
206
		  }
218
		  }
207
    );
219
    );
208
 
220
 
209
    
221
    
210
	 // Saisie Commentaire
222
	 // Saisie Commentaire
211
	 
223
	 
212
    HTML labelComment= new HTML("Notes:&nbsp;");
224
    HTML labelComment= new HTML("Notes:&nbsp;");
213
    inner.setWidget(2,2,labelComment);
225
    inner.setWidget(2,2,labelComment);
214
    inner.setWidget(2,3,comment);
226
    inner.setWidget(2,3,comment);
215
 
227
 
216
    comment.setWidth("100%");
228
    comment.setWidth("100%");
217
 
229
 
218
   
230
   
219
    comment.addKeyboardListener( new KeyboardListener() {
231
    comment.addKeyboardListener( new KeyboardListener() {
220
 
232
 
221
		  public void onKeyDown(Widget arg0, char arg1, int arg2) {
233
		  public void onKeyDown(Widget arg0, char arg1, int arg2) {
222
			  
234
			  
223
			  
235
			  
224
			  if(arg1 == KEY_ENTER)
236
			  if(arg1 == KEY_ENTER)
225
			    {
237
			    {
226
			     mediator.onAddInventoryItem(); 
238
			     mediator.onAddInventoryItem(); 
227
			     comment.setText("");
239
			     comment.setText("");
228
			    }
240
			    }
229
 
241
 
230
		  }
242
		  }
231
		  
243
		  
232
		  public void onKeyUp(Widget arg0, char arg1, int arg2) {
244
		  public void onKeyUp(Widget arg0, char arg1, int arg2) {
233
		  }
245
		  }
234
 
246
 
235
		  public void onKeyPress(Widget arg0, char arg1, int arg2) {
247
		  public void onKeyPress(Widget arg0, char arg1, int arg2) {
236
		  }
248
		  }
237
		  
249
		  
238
		  }
250
		  }
239
  );
251
  );
-
 
252
 
-
 
253
   
-
 
254
    Button addButton = new Button("Ajout");
-
 
255
    Button updateButton = new Button("Modification");
-
 
256
 
-
 
257
    addButton.addClickListener(
-
 
258
    
-
 
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);
240
 
-
 
241
    
282
    buttonPanel.add(updateButton);
242
	
283
    
243
 
284
 
244
	 inner.setWidth("100%");
285
	 inner.setWidth("100%");
245
 
286
 
246
	 outer.add(inner);
287
	 outer.add(inner);
247
	 outer.setCellWidth(inner, "100%");
288
	 outer.setCellWidth(inner, "100%");
-
 
289
	 outer.setSpacing(20);
-
 
290
	 
-
 
291
	outer.setHorizontalAlignment(HorizontalPanel.ALIGN_CENTER);
248
	 
-
 
249
 
-
 
250
 
-
 
251
		Button close = new Button("Cacher");
-
 
252
		close.addClickListener(this);
-
 
253
 
-
 
254
		outer.setHorizontalAlignment(HorizontalPanel.ALIGN_CENTER);
-
 
255
 
292
    outer.add(buttonPanel);
256
 
293
 
257
		outer.add(close);
294
 
258
 
295
 
259
	 
296
	 
260
    initWidget(outer);
297
    initWidget(outer);
261
   
-
 
262
   setPixelSize(1000,200);
-
 
263
 
298
   
264
    
299
    
265
  }
-
 
266
  
-
 
267
	public void onClick(Widget sender) {
300
  }
268
		hide();
-
 
269
	}
-
 
270
  
301
 
271
  
302
	/*
272
	public void show() {
-
 
273
		
-
 
274
	    DOM.setStyleAttribute(getElement(), "backgroundColor", "white");
-
 
275
	    this.setOpacity(this,85);
-
 
276
		RootPanel.get().remove(this);
303
	 * Numero d'ordre du relevé affiché
277
		RootPanel.get().add(this,200,200);
304
	 * 
278
	}
-
 
279
	
305
	 */
280
	public void hide() {
306
	
-
 
307
	public void setOrdre(String ordre) {
-
 
308
		this.ordre = ordre;
-
 
309
	}
-
 
310
 
-
 
311
 
281
	    this.setOpacity(RootPanel.get(),100);
-
 
282
		RootPanel.get().remove(this);
-
 
283
	}
312
	/*
284
 
-
 
285
	
313
	 * Numero d'ordre du relevé affiché
286
	private void setOpacity(UIObject e, int percentage) {
-
 
287
		if ( percentage > 100 ) percentage = 100;
-
 
288
		if ( percentage < 0 ) percentage = 0;
-
 
289
		
-
 
290
		String opac;
-
 
291
		if ( percentage == 100 ) opac = "1";
-
 
292
		else if ( percentage == 0 ) opac = "0";
-
 
293
		else if ( percentage < 10 ) opac = ".0" + percentage;
-
 
294
		else opac = "." + percentage;
314
	 * 
-
 
315
	 */
-
 
316
	
-
 
317
	public String getOrdre() {
-
 
318
		return this.ordre;
-
 
319
	}
-
 
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
				
295
		
397
			}
296
		Element h = e.getElement();
398
		});
297
		DOM.setStyleAttribute(h, "filter", "alpha(opacity=" + percentage + ")");
399
 
298
		DOM.setStyleAttribute(h, "opacity", opac);
400
	}
299
	}
401
 
300
	
402
 
301
}
403
}