Blame | Last modification | View Log | RSS feed
/** Copyright 2006 Google Inc.** Licensed under the Apache License, Version 2.0 (the "License"); you may not* use this file except in compliance with the License. You may obtain a copy of* the License at** http://www.apache.org/licenses/LICENSE-2.0** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the* License for the specific language governing permissions and limitations under* the License.*/package org.tela_botanica.client;import com.google.gwt.json.client.JSONArray;import com.google.gwt.json.client.JSONParser;import com.google.gwt.json.client.JSONString;import com.google.gwt.json.client.JSONValue;import com.google.gwt.user.client.HTTPRequest;import com.google.gwt.user.client.ResponseTextHandler;import com.google.gwt.user.client.ui.Composite;import com.google.gwt.user.client.ui.FlexTable;import com.google.gwt.user.client.ui.Grid;import com.google.gwt.user.client.ui.VerticalPanel;import com.google.gwt.user.client.ui.CheckBox;import com.google.gwt.user.client.ui.HTMLTable.CellFormatter;/*** A composite that displays a list of emails that can be selected.*/public class TaxonList extends Composite implements AutoCompleteAsyncTextBoxListener {private Grid header = new Grid(1,3);private FlexTable table = new FlexTable();private CellFormatter cellFormater = table.getCellFormatter();private VerticalPanel panel = new VerticalPanel();public TaxonList() {// Setup the headerheader.setCellSpacing(0);header.setCellPadding(2);header.setWidth("100%");header.setStyleName("taxon-ListHeader");header.setText(0, 0, "Action");header.setText(0, 1, "Nom");header.setText(0, 2, "Famille");// Setup the table.table.setCellSpacing(0);table.setCellPadding(2);table.setWidth("100%");table.setStyleName("taxon-List");panel.add(header);panel.add(table);initWidget(panel);update();}public void onValidate(SourcesAutoCompleteAsyncTextBoxEvents sender, String str) {// TODO : passer par une table de stockage temporaire// TODO : creer un objet externe ...int lastOrdre=new Integer(table.getText(table.getRowCount()-1,2)).intValue()+1;int row=table.insertRow(table.getRowCount());table.setWidget(row,0,new CheckBox());table.setText(row,1,str);table.setText(row,2,new Integer(lastOrdre).toString());cellFormater.setVisible(row,2,false);HTTPRequest.asyncPost("http://localhost/david/jrest/Inventory/", "identifiant=dd&nom="+str,new ResponseTextHandler(){public void onCompletion(String str) {}});}public void deleteElement() {// Lifo ...for (int i=table.getRowCount()-1; i>=0;i--){if (((CheckBox) table.getWidget(i,0)).isChecked()) {String str=table.getText(i,2);table.removeRow(i);HTTPRequest.asyncPost("http://localhost/david/jrest/Inventory/dd/"+str, "action=DELETE",new ResponseTextHandler(){public void onCompletion(String str) {}});}}}private void update() {HTTPRequest.asyncGet("http://localhost/david/jrest/InventoryList/dd/"+"1",new ResponseTextHandler(){public void onCompletion(String str) {JSONValue jsonValue= JSONParser.parse(str);JSONArray jsonArray;JSONArray jsonArrayNested;// Lifo ...for (int i=table.getRowCount()-1; i>=0;i--){table.removeRow(i);}if ((jsonArray = jsonValue.isArray()) != null) {for (int i = 0; i < jsonArray.size(); ++i) {if ((jsonArrayNested = jsonArray.get(i).isArray()) != null) {int row=table.insertRow(table.getRowCount());table.setWidget(row,0,new CheckBox());table.setText(row,1,((JSONString) jsonArrayNested.get(0)).stringValue());table.setText(row,2,((JSONString) jsonArrayNested.get(1)).stringValue());cellFormater.setVisible(row,2,false);}}}}});}}