Subversion Repositories eFlore/Applications.coel

Rev

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

package org.tela_botanica.client.composants;

import java.util.List;
import java.util.Map;

import org.tela_botanica.client.composants.pagination.ChargeurListe;
import org.tela_botanica.client.composants.pagination.Proxy;
import org.tela_botanica.client.composants.pagination.TransformateurJSONaModelData;
import org.tela_botanica.client.modeles.Valeur;
import org.tela_botanica.client.util.Debug;

import com.extjs.gxt.ui.client.event.BaseEvent;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.util.Size;
import com.extjs.gxt.ui.client.util.Util;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.VerticalPanel;
import com.extjs.gxt.ui.client.widget.form.ComboBox;
import com.extjs.gxt.ui.client.widget.layout.AbsoluteLayout;
import com.extjs.gxt.ui.client.widget.layout.AnchorLayout;
import com.extjs.gxt.ui.client.widget.layout.BoxLayout;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
import com.extjs.gxt.ui.client.widget.layout.FlowLayout;
import com.extjs.gxt.ui.client.widget.layout.FormData;
import com.extjs.gxt.ui.client.widget.layout.FormLayout;

import com.extjs.gxt.ui.client.data.BaseModelData;
import com.extjs.gxt.ui.client.data.BasePagingLoadConfig;
import com.extjs.gxt.ui.client.data.LoadEvent;
import com.extjs.gxt.ui.client.data.Loader;
import com.extjs.gxt.ui.client.data.ModelData;
import com.extjs.gxt.ui.client.data.ModelType;
import com.extjs.gxt.ui.client.data.PagingLoadResult;

public class ChampComboBoxRechercheTempsReelPaginable extends LayoutContainer {

          //-------------//
         //  ATTRIBUTS  //
        //-------------//
        
        private ListStore<ModelData> store = null;
        private ComboBox<ModelData> combo = null;

        private Proxy<?> proxy = null;
        private TransformateurJSONaModelData<PagingLoadResult<ModelData>> reader = null;
        private ChargeurListe<PagingLoadResult<ModelData>> loader = null;
        
        private int start = 0;
        private int limit = 10;
        private int largeur = 370;

        private BasePagingLoadConfig plc = null;
        private ModelType modeltype = null;
        private String displayName = "";
        private String recherche = "";
        
          //-------------//
         //   METHODES  //
        //-------------//

        /*--------------
          Constructeur 
        --------------*/
        public ChampComboBoxRechercheTempsReelPaginable(Proxy<?> proxy, ModelType modeltype, String displayName) {
                
                this.modeltype = modeltype;
                this.proxy = proxy;
                this.displayName = displayName;

                plc = new BasePagingLoadConfig();
                plc.setLimit(limit);
                plc.setOffset(start);
                
                reader = new TransformateurJSONaModelData<PagingLoadResult<ModelData>>(modeltype);
                
                loader = new ChargeurListe<PagingLoadResult<ModelData>>(proxy, reader);
        loader.setLimit(plc.getLimit());
        loader.setOffset(plc.getOffset());

                loader.addListener(Loader.BeforeLoad, new Listener<LoadEvent>() {
                        public void handleEvent(LoadEvent be) {                                 
                                be.<ModelData> getConfig().set("start", be.<ModelData> getConfig().get("offset"));
                        }  
                });

                loader.addListener(Loader.Load, new Listener<LoadEvent>() {  
                        public void handleEvent(LoadEvent be) {  

                    }  
                });
                
                loader.addListener(Loader.LoadException, new Listener<LoadEvent>() {  
                        public void handleEvent(LoadEvent be) {

                    }  
                });
                
                combo = new ComboBox<ModelData>();
                combo.setWidth(largeur);
                this.setWidth(largeur);
                combo.setDisplayField(displayName);
                combo.setHideTrigger(false);
                combo.setPageSize(plc.getLimit());
        store = new ListStore<ModelData>(loader);
        combo.setStore(store);
        loader.load(plc, recherche);

                combo.addListener(Events.KeyUp, new Listener<BaseEvent>() {
                
                        public void handleEvent(BaseEvent be) {
                                recherche = combo.getRawValue();
                                plc.setLimit(limit); plc.setOffset(start);
                                loader.setLimit(limit); loader.setOffset(start);
                                loader.load(plc, recherche);
                        }
                          
                });

                this.add(combo);
        }

        /*------------
          Accesseurs 
        ------------*/
        public ComboBox<ModelData> getCombo()
        {
                return this.combo;
        }
        
        public ModelData getValeur()
        {
                if (!Util.isEmptyString(combo.getRawValue())) return combo.getSelection().get(0);
                else return null;
        }
        
        public ListStore<?> getStore()
        {
                return combo.getStore();
        }
        
        public void setWidth(int largeur)
        {
                this.largeur = largeur;
                this.combo.setWidth(largeur);
        }
        
        public void setWidth(int tailleLabel, int largeurTotale)
        {
                this.setWidth(largeurTotale);
                this.largeur = largeurTotale;
                this.combo.setWidth(largeurTotale - tailleLabel);
                
                FormLayout fl = new FormLayout();
                fl.setLabelWidth(tailleLabel);
                fl.setDefaultWidth(largeurTotale - tailleLabel);
                this.setLayout(fl);

                this.layout();
        }
        
        /*-----------------------------
          Gestion du contenu du champ 
        -----------------------------*/
        
        public List<ModelData> collecterValeursDuChamp()
        {
                return combo.getSelection();
        }
        
        public void peuplerChamp(List<ModelData> selection)
        {
                combo.setSelection(selection);
        }

        
        /*----------------
          Méthode privées 
        -----------------*/

}