Subversion Repositories eFlore/Archives.cel-v1

Rev

Rev 2 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2 Rev 3
Line 15... Line 15...
15
 */
15
 */
16
package org.tela_botanica.client;
16
package org.tela_botanica.client;
Line 17... Line 17...
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;
-
 
27
import com.google.gwt.user.client.ui.FlexTable;
-
 
28
import com.google.gwt.user.client.ui.Grid;
26
import com.google.gwt.user.client.ui.FlexTable;
29
import com.google.gwt.user.client.ui.HTML;
-
 
30
import com.google.gwt.user.client.ui.HorizontalPanel;
-
 
31
import com.google.gwt.user.client.ui.VerticalPanel;
27
import com.google.gwt.user.client.ui.Grid;
32
import com.google.gwt.user.client.ui.DockPanel;
-
 
33
import com.google.gwt.user.client.ui.Button;
28
import com.google.gwt.user.client.ui.VerticalPanel;
34
import com.google.gwt.user.client.ui.CheckBox;
-
 
35
import com.google.gwt.user.client.ui.Widget;
-
 
36
import com.google.gwt.user.client.ui.HTMLTable.CellFormatter;
Line 29... Line 37...
29
import com.google.gwt.user.client.ui.CheckBox;
37
import com.google.gwt.user.client.ui.ClickListener;
30
import com.google.gwt.user.client.ui.HTMLTable.CellFormatter;
38
import com.google.gwt.user.client.ui.HasAlignment;
31
 
39
 
32
 
40
 
Line -... Line 41...
-
 
41
/**
-
 
42
 * A composite that displays a list of emails that can be selected.
-
 
43
 */
-
 
44
public class TaxonList extends Composite implements AutoCompleteAsyncTextBoxListener  {
-
 
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;");
33
/**
121
  }
34
 * A composite that displays a list of emails that can be selected.
122
 
35
 */
123
	
36
public class TaxonList extends Composite implements AutoCompleteAsyncTextBoxListener  {
124
 
Line -... Line 125...
-
 
125
  private static final int VISIBLE_TAXON_COUNT = 15;
-
 
126
	
-
 
127
  private Grid header = new Grid(1,3);
-
 
128
  private FlexTable table = new FlexTable();
-
 
129
  private CellFormatter cellFormater = table.getCellFormatter();
37
 
130
  private VerticalPanel panel = new VerticalPanel();
-
 
131
  
38
 
132
  private int startIndex=0;
-
 
133
  private int count=65000;
39
  private Grid header = new Grid(1,3);
134
  
Line 40... Line 135...
40
  private FlexTable table = new FlexTable();
135
  private NavBar navBar = new NavBar();
41
  private CellFormatter cellFormater = table.getCellFormatter();
136
  
42
  private VerticalPanel panel = new VerticalPanel();
137
  public TaxonList() {
Line 52... Line 147...
52
    header.setStyleName("taxon-ListHeader");
147
    header.setStyleName("taxon-ListHeader");
Line 53... Line 148...
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");
-
 
151
    header.setText(0, 2, "Famille");
-
 
152
    
Line 56... Line 153...
56
    header.setText(0, 2, "Famille");
153
    
Line 57... Line 154...
57
   
154
   
58
    // Setup the table.
155
    // Setup the table.
59
	  
156
	  
Line -... Line 157...
-
 
157
    table.setCellSpacing(0);
-
 
158
    table.setCellPadding(2);
-
 
159
    table.setWidth("100%");
-
 
160
 
Line 60... Line 161...
60
    table.setCellSpacing(0);
161
 
Line 61... Line -...
61
    table.setCellPadding(2);
-
 
-
 
162
    navBar.setWidth("100%");
62
    table.setWidth("100%");
163
 
63
 
164
    
Line 64... Line 165...
64
   
165
   
Line -... Line 166...
-
 
166
    table.setStyleName("taxon-List");
-
 
167
 
-
 
168
    panel.add(navBar);
-
 
169
    panel.add(header);
-
 
170
    panel.add(table);
-
 
171
    
-
 
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) {
65
    table.setStyleName("taxon-List");
187
		    		    	count=(int) jsonNumber.getValue();
-
 
188
		    		    	if ((count%VISIBLE_TAXON_COUNT)>0) {
-
 
189
		    		    		startIndex=count-(count%VISIBLE_TAXON_COUNT); 
-
 
190
		    		    	}
-
 
191
		    		    	else {
Line 66... Line 192...
66
 
192
		    		    		startIndex=count-VISIBLE_TAXON_COUNT; 
Line 67... Line 193...
67
    
193
		    		    	}
Line 68... Line -...
68
    panel.add(header);
-
 
69
    panel.add(table);
194
	 				
70
    
195
		    		    	update();
71
    initWidget(panel);
-
 
72
    
196
		    		    }
73
    update();
-
 
74
 
-
 
75
  }
197
		    	}
76
 
-
 
77
  public void onValidate(SourcesAutoCompleteAsyncTextBoxEvents sender, String str) {
-
 
Line 78... Line 198...
78
		
198
	 	});
79
	  // TODO : passer par une table de stockage temporaire
199
    
Line 80... Line 200...
80
	  // TODO : creer un objet externe ... 
200
 
-
 
201
  }
-
 
202
 
-
 
203
  public void onValidate(SourcesAutoCompleteAsyncTextBoxEvents sender, String str) {
-
 
204
		
-
 
205
// Ajout ligne 
-
 
206
	 
-
 
207
 
81
	  
208
	    count++;
82
	   int lastOrdre=new Integer(table.getText(table.getRowCount()-1,2)).intValue()+1;
209
	  
Line 83... Line 210...
83
	   
210
	    HTTPRequest.asyncPost("http://localhost/david/jrest/Inventory/", "identifiant=dd&nom="+str, 
Line 101... Line 228...
101
  public void deleteElement() {
228
  public void deleteElement() {
Line 102... Line 229...
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", 
Line 109... Line 236...
109
			   new ResponseTextHandler(){
236
			   new ResponseTextHandler(){
-
 
237
 
-
 
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; 
110
 
244
			    	}
111
			   	public void onCompletion(String str) {
245
			    	update();
Line 112... Line 246...
112
			   	}
246
			   	}
113
			  });
247
			  });
114
 
248
 
Line 115... Line 249...
115
	  	 }
249
	  	 }
116
	  }
250
	  }
-
 
251
  }
-
 
252
  
-
 
253
  
-
 
254
  private void update() {
-
 
255
 
-
 
256
	 navBar.gotoFirst.setEnabled(false);
117
  }
257
	 navBar.gotoPrev.setEnabled(false);
118
  
258
     navBar.gotoNext.setEnabled(false);
119
  
259
     navBar.gotoEnd.setEnabled(false);
Line 120... Line 260...
120
  private void update() {
260
 
Line 121... Line 261...
121
	
261
     setStatusText("Patientez ...");
Line 134... Line 274...
134
		                        table.removeRow(i);
274
		                        table.removeRow(i);
135
		                }
275
		                }
Line 136... Line 276...
136
 
276
 
-
 
277
 
137
 
278
		    		    if ((jsonArray = jsonValue.isArray()) != null) {
138
		    		    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);
-
 
287
		    		    	  }
-
 
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);
146
		    		    	  }
320
		    		    	  }
147
		    		      }
321
		    		      }
148
		    		    }
322
		    		    }
Line 149... Line 323...
149
		    	}
323
		    	}
-
 
324
		    });
150
		    });
325
 
-
 
326
  }
-
 
327
 
Line 151... Line 328...
151
 
328