Subversion Repositories eFlore/Archives.cel-v1

Rev

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

Rev 2 Rev 3
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
 
18
 
19
import com.google.gwt.json.client.JSONArray;
19
import com.google.gwt.json.client.JSONArray;
-
 
20
import com.google.gwt.json.client.JSONNumber;
20
import com.google.gwt.json.client.JSONParser;
21
import com.google.gwt.json.client.JSONParser;
21
import com.google.gwt.json.client.JSONString;
22
import com.google.gwt.json.client.JSONString;
22
import com.google.gwt.json.client.JSONValue;
23
import com.google.gwt.json.client.JSONValue;
23
import com.google.gwt.user.client.HTTPRequest;
24
import com.google.gwt.user.client.HTTPRequest;
24
import com.google.gwt.user.client.ResponseTextHandler;
25
import com.google.gwt.user.client.ResponseTextHandler;
25
import com.google.gwt.user.client.ui.Composite;
26
import com.google.gwt.user.client.ui.Composite;
26
import com.google.gwt.user.client.ui.FlexTable;
27
import com.google.gwt.user.client.ui.FlexTable;
27
import com.google.gwt.user.client.ui.Grid;
28
import com.google.gwt.user.client.ui.Grid;
-
 
29
import com.google.gwt.user.client.ui.HTML;
-
 
30
import com.google.gwt.user.client.ui.HorizontalPanel;
28
import com.google.gwt.user.client.ui.VerticalPanel;
31
import com.google.gwt.user.client.ui.VerticalPanel;
-
 
32
import com.google.gwt.user.client.ui.DockPanel;
-
 
33
import com.google.gwt.user.client.ui.Button;
29
import com.google.gwt.user.client.ui.CheckBox;
34
import com.google.gwt.user.client.ui.CheckBox;
-
 
35
import com.google.gwt.user.client.ui.Widget;
30
import com.google.gwt.user.client.ui.HTMLTable.CellFormatter;
36
import com.google.gwt.user.client.ui.HTMLTable.CellFormatter;
-
 
37
import com.google.gwt.user.client.ui.ClickListener;
-
 
38
import com.google.gwt.user.client.ui.HasAlignment;
31
 
39
 
32
 
40
 
33
/**
41
/**
34
 * A composite that displays a list of emails that can be selected.
42
 * A composite that displays a list of emails that can be selected.
35
 */
43
 */
36
public class TaxonList extends Composite implements AutoCompleteAsyncTextBoxListener  {
44
public class TaxonList extends Composite implements AutoCompleteAsyncTextBoxListener  {
37
 
45
 
-
 
46
 
-
 
47
	  private class NavBar extends Composite implements ClickListener {
-
 
48
		  
-
 
49
	    public final DockPanel bar = new DockPanel();
-
 
50
	    public final Button gotoFirst = new Button("<<", this);
-
 
51
	    public final Button gotoNext = new Button(">", this);
-
 
52
	    public final Button gotoPrev = new Button("<", this);
-
 
53
	    public final Button gotoEnd = new Button(">>", this);
-
 
54
	    public final HTML status = new HTML();
-
 
55
  
-
 
56
 
-
 
57
	    public NavBar() {
-
 
58
	      initWidget(bar);
-
 
59
	      bar.setStyleName("navbar");
-
 
60
	      status.setStyleName("status");
-
 
61
 
-
 
62
	      HorizontalPanel buttons = new HorizontalPanel();
-
 
63
	      buttons.add(gotoFirst);
-
 
64
	      buttons.add(gotoPrev);
-
 
65
	      buttons.add(gotoNext);
-
 
66
	      buttons.add(gotoEnd);
-
 
67
	      bar.add(buttons, DockPanel.EAST);
-
 
68
	      bar.setCellHorizontalAlignment(buttons, DockPanel.ALIGN_RIGHT);
-
 
69
	      bar.add(status, DockPanel.CENTER);
-
 
70
	      bar.setVerticalAlignment(DockPanel.ALIGN_MIDDLE);
-
 
71
	      bar.setCellHorizontalAlignment(status, HasAlignment.ALIGN_RIGHT);
-
 
72
	      bar.setCellVerticalAlignment(status, HasAlignment.ALIGN_MIDDLE);
-
 
73
	      bar.setCellWidth(status, "100%");
-
 
74
 
-
 
75
	      // Initialize prev & first button to disabled.
-
 
76
	      //
-
 
77
	    }
-
 
78
 
-
 
79
	    
-
 
80
	    public void onClick(Widget sender) {
-
 
81
	  	    if (sender == gotoNext) {
-
 
82
	  	      // Move forward a page.
-
 
83
	  	      startIndex += VISIBLE_TAXON_COUNT;
-
 
84
	  	      if (startIndex >= count)
-
 
85
	  	          startIndex -= VISIBLE_TAXON_COUNT;
-
 
86
	  	    } 
-
 
87
	  	    else {
-
 
88
	  	     if (sender == gotoPrev) {
-
 
89
	  	      // Move back a page.
-
 
90
	  	      startIndex -= VISIBLE_TAXON_COUNT;
-
 
91
	  	      if (startIndex < 0)
-
 
92
	  	        startIndex = 0;
-
 
93
	  	      }
-
 
94
	  	     else {
-
 
95
	  	    	 if (sender==gotoEnd) {
-
 
96
	  	    	  	if ((count%VISIBLE_TAXON_COUNT)>0) {
-
 
97
    		    		startIndex=count-(count%VISIBLE_TAXON_COUNT); 
-
 
98
    		    	}
-
 
99
    		    	else {
-
 
100
    		    		startIndex=count-VISIBLE_TAXON_COUNT; 
-
 
101
    		    	}
-
 
102
	  	    	 }
-
 
103
	  	    	 else {
-
 
104
	  	    		 if (sender== gotoFirst) {
-
 
105
	  	    			 startIndex = 0;
-
 
106
	  	    		 }
-
 
107
	  	    	 }
-
 
108
	  	     }
-
 
109
	  	   }
-
 
110
	  	   update();
-
 
111
	    }
-
 
112
 
-
 
113
	  }
-
 
114
 
-
 
115
  public void setStatusText(String text) {
-
 
116
	    navBar.status.setText(text);
-
 
117
  }
-
 
118
 
-
 
119
  public void clearStatusText() {
-
 
120
	    navBar.status.setHTML("&nbsp;");
-
 
121
  }
-
 
122
 
-
 
123
	
-
 
124
 
-
 
125
  private static final int VISIBLE_TAXON_COUNT = 15;
38
 
126
	
39
  private Grid header = new Grid(1,3);
127
  private Grid header = new Grid(1,3);
40
  private FlexTable table = new FlexTable();
128
  private FlexTable table = new FlexTable();
41
  private CellFormatter cellFormater = table.getCellFormatter();
129
  private CellFormatter cellFormater = table.getCellFormatter();
42
  private VerticalPanel panel = new VerticalPanel();
130
  private VerticalPanel panel = new VerticalPanel();
-
 
131
  
-
 
132
  private int startIndex=0;
-
 
133
  private int count=65000;
-
 
134
  
-
 
135
  private NavBar navBar = new NavBar();
43
  
136
  
-
 
137
  public TaxonList() {
44
  public TaxonList() {
138
 
-
 
139
	  
45
	 
140
	  
46
    // Setup the header
141
    // Setup the header
47
	  
142
	  
48
    header.setCellSpacing(0);
143
    header.setCellSpacing(0);
49
    header.setCellPadding(2);
144
    header.setCellPadding(2);
50
    header.setWidth("100%");
145
    header.setWidth("100%");
51
 
146
 
52
    header.setStyleName("taxon-ListHeader");
147
    header.setStyleName("taxon-ListHeader");
53
    
148
    
54
    header.setText(0, 0, "Action");
149
    header.setText(0, 0, "Action");
55
    header.setText(0, 1, "Nom");
150
    header.setText(0, 1, "Nom");
56
    header.setText(0, 2, "Famille");
151
    header.setText(0, 2, "Famille");
-
 
152
    
-
 
153
    
57
   
154
   
58
    // Setup the table.
155
    // Setup the table.
59
	  
156
	  
60
    table.setCellSpacing(0);
157
    table.setCellSpacing(0);
61
    table.setCellPadding(2);
158
    table.setCellPadding(2);
62
    table.setWidth("100%");
159
    table.setWidth("100%");
-
 
160
 
-
 
161
 
-
 
162
    navBar.setWidth("100%");
-
 
163
 
63
 
164
    
64
   
165
   
65
    table.setStyleName("taxon-List");
166
    table.setStyleName("taxon-List");
66
 
-
 
-
 
167
 
67
    
168
    panel.add(navBar);
68
    panel.add(header);
169
    panel.add(header);
69
    panel.add(table);
170
    panel.add(table);
70
    
171
    
71
    initWidget(panel);
172
    initWidget(panel);
-
 
173
    
-
 
174
    // Recherche derniere ligne ... (il y a une autre stratégie pour la calculer si le resultat n'arrive pas assez vite)
-
 
175
 
-
 
176
    
-
 
177
	 HTTPRequest.asyncGet("http://localhost/david/jrest/InventoryList/dd/", 
-
 
178
		    new ResponseTextHandler(){
-
 
179
 
-
 
180
		    	public void onCompletion(String str) {
-
 
181
 
-
 
182
// On se positionne sur la dernière page ...
-
 
183
		    		
-
 
184
		    		JSONValue jsonValue= JSONParser.parse(str);
-
 
185
		    		JSONNumber jsonNumber;
-
 
186
		    		    if ((jsonNumber = jsonValue.isNumber()) != null) {
-
 
187
		    		    	count=(int) jsonNumber.getValue();
-
 
188
		    		    	if ((count%VISIBLE_TAXON_COUNT)>0) {
-
 
189
		    		    		startIndex=count-(count%VISIBLE_TAXON_COUNT); 
-
 
190
		    		    	}
-
 
191
		    		    	else {
-
 
192
		    		    		startIndex=count-VISIBLE_TAXON_COUNT; 
-
 
193
		    		    	}
72
    
194
	 				
-
 
195
		    		    	update();
-
 
196
		    		    }
-
 
197
		    	}
-
 
198
	 	});
73
    update();
199
    
74
 
200
 
75
  }
201
  }
76
 
202
 
77
  public void onValidate(SourcesAutoCompleteAsyncTextBoxEvents sender, String str) {
203
  public void onValidate(SourcesAutoCompleteAsyncTextBoxEvents sender, String str) {
78
		
-
 
79
	  // TODO : passer par une table de stockage temporaire
204
		
80
	  // TODO : creer un objet externe ... 
205
// Ajout ligne 
81
	  
-
 
82
	   int lastOrdre=new Integer(table.getText(table.getRowCount()-1,2)).intValue()+1;
206
	 
83
	   
-
 
84
	   int row=table.insertRow(table.getRowCount());
-
 
85
	   table.setWidget(row,0,new CheckBox());
207
 
86
	   table.setText(row,1,str);
-
 
87
	   table.setText(row,2,new Integer(lastOrdre).toString());
-
 
88
	   cellFormater.setVisible(row,2,false);
208
	    count++;
89
	  
209
	  
90
	    HTTPRequest.asyncPost("http://localhost/david/jrest/Inventory/", "identifiant=dd&nom="+str, 
210
	    HTTPRequest.asyncPost("http://localhost/david/jrest/Inventory/", "identifiant=dd&nom="+str, 
91
	    new ResponseTextHandler(){
211
	    new ResponseTextHandler(){
92
 
212
 
93
	    	public void onCompletion(String str) {
213
	    	public void onCompletion(String str) {
-
 
214
		    	if ((count%VISIBLE_TAXON_COUNT)>0) {
-
 
215
		    		startIndex=count-(count%VISIBLE_TAXON_COUNT); 
-
 
216
		    	}
-
 
217
		    	else {
-
 
218
		    		startIndex=count-VISIBLE_TAXON_COUNT; 
-
 
219
		    	}
-
 
220
		    	update();
94
	    	}
221
	    	}
95
	    });
222
	    });
96
	    
223
	    
97
 
224
 
98
  }
225
  }
99
  
226
  
100
 
227
 
101
  public void deleteElement() {
228
  public void deleteElement() {
102
 
229
 
103
	    // Lifo ...
230
	    // Lifo ...
104
      for (int i=table.getRowCount()-1; i>=0;i--){
231
      for (int i=table.getRowCount()-1; i>=0;i--){
105
		 if (((CheckBox) table.getWidget(i,0)).isChecked())  {
232
		 if (((CheckBox) table.getWidget(i,0)).isChecked())  {
106
			 String str=table.getText(i,2);
233
			String str=table.getText(i,2);
107
			 table.removeRow(i);
234
			count--;
108
			 HTTPRequest.asyncPost("http://localhost/david/jrest/Inventory/dd/"+str, "action=DELETE", 
235
			 HTTPRequest.asyncPost("http://localhost/david/jrest/Inventory/dd/"+str, "action=DELETE", 
109
			   new ResponseTextHandler(){
236
			   new ResponseTextHandler(){
110
 
237
 
111
			   	public void onCompletion(String str) {
238
			   	public void onCompletion(String str) {
-
 
239
			   		if ((count%VISIBLE_TAXON_COUNT)>0) {
-
 
240
			    		startIndex=count-(count%VISIBLE_TAXON_COUNT); 
-
 
241
			    	}
-
 
242
			    	else {
-
 
243
			    		startIndex=count-VISIBLE_TAXON_COUNT; 
-
 
244
			    	}
-
 
245
			    	update();
112
			   	}
246
			   	}
113
			  });
247
			  });
114
 
248
 
115
	  	 }
249
	  	 }
116
	  }
250
	  }
117
  }
251
  }
118
  
252
  
119
  
253
  
120
  private void update() {
254
  private void update() {
121
	
255
 
-
 
256
	 navBar.gotoFirst.setEnabled(false);
-
 
257
	 navBar.gotoPrev.setEnabled(false);
-
 
258
     navBar.gotoNext.setEnabled(false);
-
 
259
     navBar.gotoEnd.setEnabled(false);
-
 
260
 
-
 
261
     setStatusText("Patientez ...");
122
	  
262
 
123
	 HTTPRequest.asyncGet("http://localhost/david/jrest/InventoryList/dd/"+"1", 
263
	 HTTPRequest.asyncGet("http://localhost/david/jrest/InventoryList/dd/"+startIndex+"/"+VISIBLE_TAXON_COUNT, 
124
		    new ResponseTextHandler(){
264
		    new ResponseTextHandler(){
125
 
265
 
126
		    	public void onCompletion(String str) {
266
		    	public void onCompletion(String str) {
127
 
267
 
128
		    		    JSONValue jsonValue= JSONParser.parse(str);
268
		    		    JSONValue jsonValue= JSONParser.parse(str);
129
		    		    JSONArray jsonArray;
269
		    		    JSONArray jsonArray;
130
		    		    JSONArray jsonArrayNested;
270
		    		    JSONArray jsonArrayNested;
131
		    		 
271
		    		 
132
		    		    // Lifo ...
272
		    		    // Lifo ...
133
		    	        for (int i=table.getRowCount()-1; i>=0;i--){
273
		    	        for (int i=table.getRowCount()-1; i>=0;i--){
134
		                        table.removeRow(i);
274
		                        table.removeRow(i);
135
		                }
275
		                }
136
 
276
 
137
 
277
 
138
		    		    if ((jsonArray = jsonValue.isArray()) != null) {
278
		    		    if ((jsonArray = jsonValue.isArray()) != null) {
-
 
279
		    		      int i; 	
139
		    		      for (int i = 0; i < jsonArray.size(); ++i) {
280
		    		      for (i = 0; i < jsonArray.size(); ++i) {
140
		    		    	  if ((jsonArrayNested = jsonArray.get(i).isArray()) != null) {
281
		    		    	  if ((jsonArrayNested = jsonArray.get(i).isArray()) != null) {
141
		    		    		  int row=table.insertRow(table.getRowCount());
282
		    		    		  int row=table.insertRow(table.getRowCount());
142
		    		    		  table.setWidget(row,0,new CheckBox());
283
		    		    		  table.setWidget(row,0,new CheckBox());
143
		    		    		  table.setText(row,1,((JSONString) jsonArrayNested.get(0)).stringValue());
284
		    		    		  table.setText(row,1,((JSONString) jsonArrayNested.get(0)).stringValue());
144
		    		    		  table.setText(row,2,((JSONString) jsonArrayNested.get(1)).stringValue());
285
		    		    		  table.setText(row,2,((JSONString) jsonArrayNested.get(1)).stringValue());
145
		    		    		  cellFormater.setVisible(row,2,false);
286
		    		    		  cellFormater.setVisible(row,2,false);
146
		    		    	  }
287
		    		    	  }
147
		    		      }
288
		    		      }
-
 
289
		    		      // Calcul nombre d'enregistrement total
-
 
290
		    		      if (i<VISIBLE_TAXON_COUNT) {
-
 
291
		    		    	  count = startIndex+i;
-
 
292
		    		      }
-
 
293
		    		      
-
 
294
		    		      // Navigation 
-
 
295
		    		      
-
 
296
		    		      setStatusText((startIndex + 1) + " - " + (startIndex + VISIBLE_TAXON_COUNT));
-
 
297
 
-
 
298
		    		      // Premiere page 
-
 
299
		    		      if (startIndex<VISIBLE_TAXON_COUNT) {
-
 
300
		    		    		navBar.gotoPrev.setEnabled(false);
-
 
301
		    		    		navBar.gotoFirst.setEnabled(false);
-
 
302
		    		    		navBar.gotoNext.setEnabled(true);
-
 
303
		    		    		navBar.gotoEnd.setEnabled(true);
-
 
304
		    		    		
-
 
305
		    		      }
-
 
306
		    		      // Derniere page
-
 
307
		    		      else {
-
 
308
		    		    	  if (startIndex>=(count-VISIBLE_TAXON_COUNT)) {
-
 
309
		    		    		navBar.gotoPrev.setEnabled(true);
-
 
310
		    		    		navBar.gotoFirst.setEnabled(true);
-
 
311
		    		    		navBar.gotoNext.setEnabled(false);
-
 
312
		    		    		navBar.gotoEnd.setEnabled(false);
-
 
313
		    		    		setStatusText((startIndex + 1) + " - " + count);
-
 
314
		    		    	  }
-
 
315
		    		    	  else {
-
 
316
				    		      navBar.gotoPrev.setEnabled(true);
-
 
317
				    		      navBar.gotoFirst.setEnabled(true);
-
 
318
				    		      navBar.gotoNext.setEnabled(true);
-
 
319
				    		      navBar.gotoEnd.setEnabled(true);
-
 
320
		    		    	  }
-
 
321
		    		      }
148
		    		    }
322
		    		    }
149
		    	}
323
		    	}
150
		    });
324
		    });
151
 
325
 
152
  }
326
  }
-
 
327
 
153
	    
328
  
-
 
329
  
-
 
330
  
154
 
331
 
155
}
332
}