Subversion Repositories eFlore/Archives.cel-v1

Rev

Rev 13 | Rev 27 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

package org.tela_botanica.client;



import java.util.EventListener;


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.ResponseTextHandler;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HorizontalPanel;


import org.tela_botanica.client.AutoCompleteAsyncTextBox;

/**
 * Affiche une liste de nom pour selection. Son retournés le nom selectionné (gettext()) et un code associé (getvalue()).
 */

public class NameAssistant extends Composite implements EventListener, ResponseTextHandler  {

  private AutoCompleteAsyncTextBox autoCompletebox = new AutoCompleteAsyncTextBox(this);
  private HorizontalPanel panel = new HorizontalPanel();
  
  private Mediator mediator = null;
        
  
  public NameAssistant(Mediator med) {

        mediator=med;
        mediator.registerNameAssistant(this);           
        
        
        autoCompletebox.setSearchUrl(mediator.getServiceBaseUrl()+"/NameSearch/");
        
        panel.add(autoCompletebox);

        autoCompletebox.setWidth("100%");
    initWidget(panel);
    autoCompletebox.addAutoCompleteAsyncTextBoxListener(mediator);

  }

public void onCompletion(String str) {
          
                        JSONValue jsonValue= JSONParser.parse(str);
                        JSONArray jsonArray;
                        JSONArray jsonArrayNested;

                        
                        if ((jsonArray = jsonValue.isArray()) != null) {
                                for (int i = 0; i < jsonArray.size(); ++i) {
                                  if ((jsonArrayNested = jsonArray.get(i).isArray()) != null) {
                                        autoCompletebox.addItem(((JSONString) jsonArrayNested.get(0)).stringValue(),((JSONString) jsonArrayNested.get(1)).stringValue());
                                  }
                                }
                        }

                        autoCompletebox.displayList();
                    
}         


public void setText(String str) {
        autoCompletebox.setText(str);
}


public String getText() {
        return autoCompletebox.getText();
}


public String getValue() {
        return autoCompletebox.getValue();
}

public void setValue(String value) {
        autoCompletebox.setValue(value);
}

  
}