Subversion Repositories eFlore/Applications.cel

Rev

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

package org.tela_botanica.client.util;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.tela_botanica.client.cel2;
import org.tela_botanica.client.interfaces.Rafraichissable;
import org.tela_botanica.client.modeles.dao.ListeReferentielChampsEtendusDAO;
import org.tela_botanica.client.modeles.objets.Configuration;
import org.tela_botanica.client.modeles.objets.Utilisateur;
import org.tela_botanica.client.util.autocompletion.AutoCompletionComboBox;

import com.google.gwt.core.client.Callback;
import com.google.gwt.http.client.Response;
import com.google.gwt.user.client.Timer;
import com.gwtext.client.core.EventCallback;
import com.gwtext.client.core.EventObject;
import com.gwtext.client.core.Ext;
import com.gwtext.client.core.ListenerConfig;
import com.gwtext.client.data.ArrayReader;
import com.gwtext.client.data.FieldDef;
import com.gwtext.client.data.MemoryProxy;
import com.gwtext.client.data.Record;
import com.gwtext.client.data.RecordDef;
import com.gwtext.client.data.Store;
import com.gwtext.client.data.StringFieldDef;
import com.gwtext.client.widgets.Component;
import com.gwtext.client.widgets.ToolTip;
import com.gwtext.client.widgets.form.ComboBox;
import com.gwtext.client.widgets.form.Field;
import com.gwtext.client.widgets.form.event.ComboBoxListenerAdapter;

public class ChampSaisieEtendu extends AutoCompletionComboBox {
                
                private String cle = null;
                private String label = null;
                
                private String description = null;
                private ToolTip tpDesc = null;
                
                public ChampSaisieEtendu(String label, String cle, String urlRequete) {

                        super(label, urlRequete);  
                        this.cle =cle;
                        this.label = label;
                        
                        // A activer pour télécharger la description
                        // si jamais on le décide
                        addListener(new ComboBoxListenerAdapter() {
                                @Override
                                public void onRender(Component component) {
                                        ChampSaisieEtendu.this.getEl().addListener("mouseover", new EventCallback() {
                                                @Override
                                                public void execute(EventObject e) {
                                                        if(description == null) {
                                                                telechargerEtAfficherDescriptionDistante();
                                                        } else {
                                                                afficherDescription(description);
                                                        }
                                                }
                                        });
                                }
                        });
                }

                private void telechargerEtAfficherDescriptionDistante() {
                        ListeReferentielChampsEtendusDAO.telechargerDescriptionWikini(cle, new Callback<String, String>() {             
                                @Override
                                public void onSuccess(String description) {
                                        ChampSaisieEtendu.this.description = description;
                                        afficherDescription(description);
                                }
                                
                                @Override
                                public void onFailure(String description) {
                                        afficherDescription(description);
                                }
                        });
                }
                
                private void afficherDescription(String description) {
                        if(!description.trim().isEmpty()) {
                                if(tpDesc == null) {
                                        tpDesc = new ToolTip(description);
                                        tpDesc.applyTo(this.getElement());
                                        tpDesc.showAt(ChampSaisieEtendu.this.getEl().getX(), ChampSaisieEtendu.this.getEl().getY());
                                } else {
                                        tpDesc.show();
                                }
                        }
                }
                
                public String getCle() {
                        return cle;
                }
                
                public String getLabel() {
                        return label;
                }

                @Override
                protected Map<String, String> parserResultatRequete(Response response) {
                        return ListeReferentielChampsEtendusDAO.parserRetourListeValeursChampsEtendus(response);
                }

                @Override
                protected void onModificationValeur() {
                        // TODO Auto-generated method stub      
                }
                
                @Override
                protected void onSelectionValeur() {
                        // TODO Auto-generated method stub      
                }

                @Override
                protected void onValidationSaisie() {
                        // TODO Auto-generated method stub
                }
}