Subversion Repositories eFlore/Applications.cel

Rev

Rev 12 | Go to most recent revision | Blame | Last modification | View Log | RSS feed

package org.tela_botanica.client.vues;



import java.util.Iterator;

import org.tela_botanica.client.interfaces.Rafraichissable;
import org.tela_botanica.client.modeles.ListeReferentielCommune;
import org.tela_botanica.client.modeles.ReferentielCommune;
import org.tela_botanica.client.observation.ObservationMediateur;


import com.google.gwt.user.client.Window;
import com.gwtext.client.core.EventCallback;
import com.gwtext.client.core.EventObject;
import com.gwtext.client.core.ListenerConfig;
import com.gwtext.client.core.Position;
import com.gwtext.client.data.ArrayReader;
import com.gwtext.client.data.FieldDef;
import com.gwtext.client.data.MemoryProxy;
import com.gwtext.client.data.RecordDef;
import com.gwtext.client.data.Store;
import com.gwtext.client.data.StringFieldDef;
import com.gwtext.client.widgets.Button;
import com.gwtext.client.widgets.Panel;
import com.gwtext.client.widgets.form.ComboBox;
import com.gwtext.client.widgets.form.DateField;
import com.gwtext.client.widgets.form.FormPanel;
import com.gwtext.client.widgets.form.TextField;
import com.gwtext.client.widgets.form.event.ComboBoxListenerAdapter;
import com.gwtext.client.widgets.layout.ColumnLayout;
import com.gwtext.client.widgets.layout.ColumnLayoutData;
import com.gwtext.client.widgets.layout.FormLayout;
import com.gwtext.client.data.Record;

/**
 * Panneau contenant les infos, les métadonnées et l'arbre des mots clés, il implémente l'interface rafraichissable
 * @author aurelien
 *
 */
public class FormulaireSaisieObservationVue extends Panel implements Rafraichissable  {


        /**
         * Le médiateur associé à la vue
         */
        private ObservationMediateur    observationMediateur            = null;
        
        
        private TextField nameAssistant = null;
        private DateField date = null;
        private TextField lieudit = null;
        private TextField station = null;
        private TextField milieu = null;
        private TextField comment = null;
        private ComboBox  commune = null;
        
        private boolean selectionCommune=false;
        
          public static final int KEY_ALT = 18;
          public static final int KEY_BACKSPACE = 8;
          public static final int KEY_CTRL = 17;
          public static final int KEY_DELETE = 46;
          public static final int KEY_DOWN = 40;
          public static final int KEY_END = 35;
          public static final int KEY_ENTER = 13;
          public static final int KEY_ESCAPE = 27;
          public static final int KEY_HOME = 36;
          public static final int KEY_LEFT = 37;
          public static final int KEY_PAGEDOWN = 34;
          public static final int KEY_PAGEUP = 33;
          public static final int KEY_RIGHT = 39;
          public static final int KEY_SHIFT = 16;
          public static final int KEY_TAB = 9;
          public static final int KEY_UP = 38;
        
        /**
         * Store combobox communes
         */
        private Store                   store                           = null;
        

        

        /**
         * Booleen d'instanciation
         */
        boolean estInstancie = false ;
        
        /**
         * Constructeur sans argument (privé car ne doit pas être utilisé)
         */
        private FormulaireSaisieObservationVue()
        {
                super() ;
        }
        
        /**
         * Constructeur avec argument
         * @param im
         */
        public FormulaireSaisieObservationVue(ObservationMediateur obs)
        {

                
                // on associe le médiateur
                observationMediateur = obs ;
                
                this.setHeader(true);
                this.setTitle("Saisie");
           
                
                this.setCollapsible(true) ;
                
                FormPanel panneauFormulaire = new FormPanel(Position.RIGHT);
                panneauFormulaire.setBorder(false);
                
                // Panneau intermediaire qui contient deux colonnes de formulaire
                
                Panel panneauIntermediaire = new Panel();  
                panneauIntermediaire.setLayout(new ColumnLayout());  
                panneauIntermediaire.setBorder(false);
                   
                //create first panel and add fields to it  
                Panel panneauPremierColonne = new Panel();  
                panneauPremierColonne.setLayout(new FormLayout());  
                panneauPremierColonne.setBorder(false);

                //create second panel and add fields to it  
            Panel panneauSecondeColonne = new Panel();  
                panneauSecondeColonne.setLayout(new FormLayout());  
                panneauSecondeColonne.setBorder(false);
        
        /*
            //    creation du store
                FieldDef defCommune = new StringFieldDef("commune");
                FieldDef defDepartement = new StringFieldDef("departement");
                
                
                FieldDef[] defTab = { defCommune, defDepartement};
                
                RecordDef rd = new RecordDef(defTab);
                
                
                store = new Store(rd);
                
                //store.load();*/
                
                commune=new ComboBox("Commune","commune",275 );  
                
        
                //commune.setStore(store);
                
                final String resultTpl = "<div class=\"search-item\">{commune}</div>";  

                
                commune.setTpl(resultTpl);
                commune.setMode(ComboBox.REMOTE);
                // commune.setPageSize(10); // Ne fonctionne pas 
                commune.setItemSelector("div.search-item");
                
                
                //commune.setDisplayField("title");
                
                commune.setTypeAhead(true);  
                commune.setLoadingText("Recherche...");  
                  
                commune.setHideTrigger(true);
                
                
                /*
                final String resultTpl = "<div class=\"search-item\"><h3><span>{lastPost:date(\"M j, Y\")}"  
                                                         +  "<br/>by {author}</span>{title}</h3>{excerpt}</div>";  
                
                commune.setTpl(resultTpl);
                */
                
                //commune.setMode(ComboBox.REMOTE);
                
                /*
                commune.setTitle("ExtJS Forums");  
                commune.setHideLabel(true);  
                commune.setItemSelector("div.search-item");
                
                  */
   
                
            
                
        commune.addListener(new ComboBoxListenerAdapter() {  
             public void onSelect(ComboBox comboBox, Record record, int index) {  
                 commune.setValue(record.getAsString("commune"));
                 selectionCommune=true;
             }  
         });  
         
        
//      Selection parmi la liste déroulante
            
        
                ListenerConfig listenerConfig=new ListenerConfig();
                listenerConfig.setDelay(10);
                listenerConfig.setStopPropagation(false);
                listenerConfig.setStopEvent(false);
                

        
            commune.addKeyPressListener(new EventCallback()     {
                
                    public void execute(EventObject e) {
                        
                                  
                                  switch(e.getKey()) {
                                                  
                                  
                                  case KEY_ALT:
                              case KEY_CTRL:
                              case KEY_DOWN:
                              case KEY_END:
                              
                              case KEY_ESCAPE:
                              case KEY_HOME:
                              case KEY_LEFT:
                              case KEY_PAGEDOWN:
                              case KEY_PAGEUP:
                              case KEY_RIGHT:
                              case KEY_SHIFT:
                              case KEY_TAB:
                              case KEY_UP:
                                
                                break;
                              
                              case KEY_ENTER:
                                  
                                 if (selectionCommune) {
                                         selectionCommune=false;
                                 }
                                 else {
                                        // lancer mise a jour                                    
                                 }
                                
                                
                                  break;
                               
                              default:
                                  
                                  obtenirListeReferentielCommune();
                                                                
                                break;
                            }

                         
                        
                        }
                 
                        },    listenerConfig
                
                );
            
            



            panneauPremierColonne.add(commune);  

                
            
            station = new TextField("Station", "station", 275);  
            station.setAllowBlank(true);  
            panneauPremierColonne.add(station);  
            
            date = new DateField("Date", "date", 100);  
            date.setAllowBlank(true);
            date.setFormat("d/m/yyyy") ;
            panneauPremierColonne.add(date);  
        
                nameAssistant = new TextField("Espèce", "espece", 275);  
                nameAssistant.setAllowBlank(false);  
                panneauPremierColonne.add(nameAssistant);  
                
            comment = new TextField("Notes", "comment", 275);  
            comment.setAllowBlank(true);  
            panneauPremierColonne.add(comment); 
            
            
            lieudit = new TextField("Lieu-dit", "lieudit", 275);  
            lieudit.setAllowBlank(true);  
            panneauSecondeColonne.add(lieudit);  
               
        
            milieu = new TextField("Milieu", "milieu", 275);  
            milieu.setAllowBlank(true);  
            panneauSecondeColonne.add(milieu);  
           
         
                
                panneauIntermediaire.add(panneauPremierColonne, new ColumnLayoutData(.5));
                panneauIntermediaire.add(panneauSecondeColonne, new ColumnLayoutData(.5));
                
                panneauFormulaire.add(panneauIntermediaire);
                
                Button boutonOK = new Button("Ok");  
                panneauFormulaire.addButton(boutonOK);
                    
                Button boutonAnnuler = new Button("Annuler");  
                panneauFormulaire.addButton(boutonAnnuler);
                    
        
                this.add(panneauFormulaire) ;
                
                
                this.setAutoHeight(true);
        
                
        
                // on ajoute les listeners
                ajouterListeners() ;
                
                

        }
        
        private void ajouterListeners()
        {
                // on ajoute un écouteur
                /*validerInfo.addListener(new ButtonListenerAdapter() {

                        // gestion du clic
                        
                        public void onClick(Button button, EventObject e) {
                                
                                // lors du clic sur le bouton valider on met à jour les commentaires et la date
                //      getIMediateur().mettreAJourInfo(commentaireGeneral.getText(), dateImage.getRawValue(), noteVue.getNote()) ;
                                
                        }       
                });
                */
        
        
        }
        
        /**
         * Desactive visuellement ce panneau
         */
        public void desactiverPanneau()
        {
                this.setDisabled(true) ;
        }
        
        /**
         * Active visuellement ce panneau
         */
        public void activerPanneau()
        {
                this.setDisabled(false) ;
        }

        public void rafraichir(Object nouvelleDonnees, boolean repandreRaffraichissement) {
                // 
                
                
                // si l'on a reçu une liste de commune
                        if(nouvelleDonnees instanceof ListeReferentielCommune)
                        {
                                
                                        ListeReferentielCommune data = (ListeReferentielCommune) nouvelleDonnees ;
                                        Object[][] communeData = new Object[data.size()][2];
                                        int i = 0 ;
                                
                                        // on la parse et on récupère les informations quiç nous interessent
                                        for (Iterator it = data.keySet().iterator(); it.hasNext();) 
                                        {
                                                
                                                ReferentielCommune ref=(ReferentielCommune) data.get(it.next());
                                                
                                                communeData[i][0]= ref.getCommune();
                                                communeData[i][1]= ref.getDepartement();
                                                
                                                                                                                                        
                                                i++ ;
                                        }
                                        
                                           //     creation du store
                                        FieldDef defCommune = new StringFieldDef("commune");
                                        FieldDef defDepartement = new StringFieldDef("departement");
                                        
                                        
                                        FieldDef[] defTab = { defCommune, defDepartement};
                                        
                                        RecordDef rd = new RecordDef(defTab);
                                        
                                        final MemoryProxy dataProxy = new MemoryProxy(communeData);
                                        final ArrayReader reader = new ArrayReader(rd);         
                                        
                                        store=new Store(dataProxy,reader);
                                        store.load() ;
                
                                        commune.setStore(store);
                                
                                        
                                                        
                        }
        }
        

        public void obtenirListeReferentielCommune() {
          observationMediateur.obtenirListeReferentielCommune(this,commune.getText());
         
        }
    
        
        

}