Rev 1287 | Rev 1329 | 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 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.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.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 String recherche = "";
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 = 200;
private BasePagingLoadConfig plc = null;
private ModelType modeltype = null;
private String displayName = "";
//-------------//
// 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);
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);
}
});
VerticalPanel vp = new VerticalPanel();
vp.add(combo);
add(vp);
}
/*------------
Accesseurs
------------*/
public ComboBox<ModelData> getCombo()
{
return this.combo;
}
public Valeur getValeur()
{
return new Valeur(combo.getSelection().get(0));
}
public ListStore<?> getStore()
{
return combo.getStore();
}
public void setWidth(int largeur)
{
this.largeur = largeur;
this.combo.setWidth(largeur);
}
/*-----------------------------
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
-----------------*/
}