Subversion Repositories eFlore/Archives.cel-v1

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 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
 
19
import com.google.gwt.json.client.JSONArray;
20
import com.google.gwt.json.client.JSONParser;
21
import com.google.gwt.json.client.JSONString;
22
import com.google.gwt.json.client.JSONValue;
23
import com.google.gwt.user.client.HTTPRequest;
24
import com.google.gwt.user.client.ResponseTextHandler;
25
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.Grid;
28
import com.google.gwt.user.client.ui.VerticalPanel;
29
import com.google.gwt.user.client.ui.CheckBox;
30
import com.google.gwt.user.client.ui.HTMLTable.CellFormatter;
31
 
32
 
33
/**
34
 * A composite that displays a list of emails that can be selected.
35
 */
36
public class TaxonList extends Composite implements AutoCompleteAsyncTextBoxListener  {
37
 
38
 
39
  private Grid header = new Grid(1,3);
40
  private FlexTable table = new FlexTable();
41
  private CellFormatter cellFormater = table.getCellFormatter();
42
  private VerticalPanel panel = new VerticalPanel();
43
 
44
  public TaxonList() {
45
 
46
    // Setup the header
47
 
48
    header.setCellSpacing(0);
49
    header.setCellPadding(2);
50
    header.setWidth("100%");
51
 
52
    header.setStyleName("taxon-ListHeader");
53
 
54
    header.setText(0, 0, "Action");
55
    header.setText(0, 1, "Nom");
56
    header.setText(0, 2, "Famille");
57
 
58
    // Setup the table.
59
 
60
    table.setCellSpacing(0);
61
    table.setCellPadding(2);
62
    table.setWidth("100%");
63
 
64
 
65
    table.setStyleName("taxon-List");
66
 
67
 
68
    panel.add(header);
69
    panel.add(table);
70
 
71
    initWidget(panel);
72
 
73
    update();
74
 
75
  }
76
 
77
  public void onValidate(SourcesAutoCompleteAsyncTextBoxEvents sender, String str) {
78
 
79
	  // TODO : passer par une table de stockage temporaire
80
	  // TODO : creer un objet externe ...
81
 
82
	   int lastOrdre=new Integer(table.getText(table.getRowCount()-1,2)).intValue()+1;
83
 
84
	   int row=table.insertRow(table.getRowCount());
85
	   table.setWidget(row,0,new CheckBox());
86
	   table.setText(row,1,str);
87
	   table.setText(row,2,new Integer(lastOrdre).toString());
88
	   cellFormater.setVisible(row,2,false);
89
 
90
	    HTTPRequest.asyncPost("http://localhost/david/jrest/Inventory/", "identifiant=dd&nom="+str,
91
	    new ResponseTextHandler(){
92
 
93
	    	public void onCompletion(String str) {
94
	    	}
95
	    });
96
 
97
 
98
  }
99
 
100
 
101
  public void deleteElement() {
102
 
103
	    // Lifo ...
104
      for (int i=table.getRowCount()-1; i>=0;i--){
105
		 if (((CheckBox) table.getWidget(i,0)).isChecked())  {
106
			 String str=table.getText(i,2);
107
			 table.removeRow(i);
108
			 HTTPRequest.asyncPost("http://localhost/david/jrest/Inventory/dd/"+str, "action=DELETE",
109
			   new ResponseTextHandler(){
110
 
111
			   	public void onCompletion(String str) {
112
			   	}
113
			  });
114
 
115
	  	 }
116
	  }
117
  }
118
 
119
 
120
  private void update() {
121
 
122
 
123
	 HTTPRequest.asyncGet("http://localhost/david/jrest/InventoryList/dd/"+"1",
124
		    new ResponseTextHandler(){
125
 
126
		    	public void onCompletion(String str) {
127
 
128
		    		    JSONValue jsonValue= JSONParser.parse(str);
129
		    		    JSONArray jsonArray;
130
		    		    JSONArray jsonArrayNested;
131
 
132
		    		    // Lifo ...
133
		    	        for (int i=table.getRowCount()-1; i>=0;i--){
134
		                        table.removeRow(i);
135
		                }
136
 
137
 
138
		    		    if ((jsonArray = jsonValue.isArray()) != null) {
139
		    		      for (int i = 0; i < jsonArray.size(); ++i) {
140
		    		    	  if ((jsonArrayNested = jsonArray.get(i).isArray()) != null) {
141
		    		    		  int row=table.insertRow(table.getRowCount());
142
		    		    		  table.setWidget(row,0,new CheckBox());
143
		    		    		  table.setText(row,1,((JSONString) jsonArrayNested.get(0)).stringValue());
144
		    		    		  table.setText(row,2,((JSONString) jsonArrayNested.get(1)).stringValue());
145
		    		    		  cellFormater.setVisible(row,2,false);
146
		    		    	  }
147
		    		      }
148
		    		    }
149
		    	}
150
		    });
151
 
152
  }
153
 
154
 
155
}