Subversion Repositories eFlore/Applications.coel

Rev

Rev 1292 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1287 cyprien 1
package org.tela_botanica.client.composants;
2
 
3
import java.util.List;
4
 
5
import org.tela_botanica.client.composants.pagination.ChargeurListe;
6
import org.tela_botanica.client.composants.pagination.Proxy;
7
import org.tela_botanica.client.composants.pagination.TransformateurJSONaModelData;
8
import org.tela_botanica.client.modeles.Valeur;
9
import org.tela_botanica.client.util.Debug;
10
 
11
import com.extjs.gxt.ui.client.event.BaseEvent;
12
import com.extjs.gxt.ui.client.event.Events;
13
import com.extjs.gxt.ui.client.event.Listener;
14
import com.extjs.gxt.ui.client.store.ListStore;
15
import com.extjs.gxt.ui.client.widget.LayoutContainer;
16
import com.extjs.gxt.ui.client.widget.VerticalPanel;
17
import com.extjs.gxt.ui.client.widget.form.ComboBox;
18
 
19
import com.extjs.gxt.ui.client.data.BasePagingLoadConfig;
20
import com.extjs.gxt.ui.client.data.LoadEvent;
21
import com.extjs.gxt.ui.client.data.Loader;
22
import com.extjs.gxt.ui.client.data.ModelData;
23
import com.extjs.gxt.ui.client.data.ModelType;
24
import com.extjs.gxt.ui.client.data.PagingLoadResult;
25
 
26
public class ChampComboBoxRechercheTempsReelPaginable extends LayoutContainer {
27
 
28
	  //-------------//
29
	 //  ATTRIBUTS	//
30
	//-------------//
31
 
32
	private ListStore<ModelData> store = null;
33
	private ComboBox<ModelData> combo = null;
34
 
35
	private String recherche = "";
36
 
37
	private Proxy<?> proxy = null;
38
	private TransformateurJSONaModelData<PagingLoadResult<ModelData>> reader = null;
39
	private ChargeurListe<PagingLoadResult<ModelData>> loader = null;
40
 
41
	private int start = 0;
42
	private int limit = 10;
43
	private int largeur = 200;
44
 
45
	private BasePagingLoadConfig plc = null;
46
	private ModelType modeltype = null;
47
	private String displayName = "";
48
 
49
 
50
	  //-------------//
51
	 //   METHODES	//
52
	//-------------//
53
 
54
	/*--------------
55
	  Constructeur
56
	--------------*/
57
	public ChampComboBoxRechercheTempsReelPaginable(Proxy<?> proxy, ModelType modeltype, String displayName) {
58
 
59
		this.modeltype = modeltype;
60
		this.proxy = proxy;
61
		this.displayName = displayName;
62
 
63
		plc = new BasePagingLoadConfig();
64
		plc.setLimit(limit);
65
		plc.setOffset(start);
66
 
67
		reader = new TransformateurJSONaModelData<PagingLoadResult<ModelData>>(modeltype);
68
 
69
		loader = new ChargeurListe<PagingLoadResult<ModelData>>(proxy, reader);
70
        loader.setLimit(plc.getLimit());
71
        loader.setOffset(plc.getOffset());
72
 
73
		loader.addListener(Loader.BeforeLoad, new Listener<LoadEvent>() {
74
			public void handleEvent(LoadEvent be) {
75
				be.<ModelData> getConfig().set("start", be.<ModelData> getConfig().get("offset"));
76
			}
77
		});
78
 
79
		loader.addListener(Loader.Load, new Listener<LoadEvent>() {
80
			public void handleEvent(LoadEvent be) {
81
 
82
		    }
83
		});
84
 
85
		loader.addListener(Loader.LoadException, new Listener<LoadEvent>() {
86
			public void handleEvent(LoadEvent be) {
87
 
88
		    }
89
		});
90
 
91
		combo = new ComboBox<ModelData>();
92
		combo.setWidth(largeur);
93
		combo.setDisplayField(displayName);
94
		combo.setHideTrigger(false);
95
		combo.setPageSize(plc.getLimit());
96
        store = new ListStore<ModelData>(loader);
97
        combo.setStore(store);
98
        loader.load(plc, recherche);
99
 
100
		combo.addListener(Events.KeyUp, new Listener<BaseEvent>() {
101
 
102
			public void handleEvent(BaseEvent be) {
103
				recherche = combo.getRawValue();
104
				plc.setLimit(limit); plc.setOffset(start);
105
				loader.setLimit(limit); loader.setOffset(start);
106
				loader.load(plc, recherche);
107
			}
108
 
109
		});
110
 
111
		VerticalPanel vp = new VerticalPanel();
112
		vp.add(combo);
113
 
114
		add(vp);
115
	}
116
 
117
 
118
	/*------------
119
	  Accesseurs
120
	------------*/
121
	public ComboBox<ModelData> getCombo()
122
	{
123
		return this.combo;
124
	}
125
 
126
	public Valeur getValeur()
127
	{
128
		return new Valeur(combo.getSelection().get(0));
129
	}
130
 
131
	public ListStore<?> getStore()
132
	{
133
		return combo.getStore();
134
	}
135
 
136
	public void setWidth(int largeur)
137
	{
138
		this.largeur = largeur;
139
		this.combo.setWidth(largeur);
140
	}
141
 
142
 
143
	/*-----------------------------
144
	  Gestion du contenu du champ
145
	-----------------------------*/
146
 
147
	public List<ModelData> collecterValeursDuChamp()
148
	{
149
		return combo.getSelection();
150
	}
151
 
152
	public void peuplerChamp(List<ModelData> selection)
153
	{
154
		combo.setSelection(selection);
155
	}
156
 
157
 
158
	/*----------------
159
	  Méthode privées
160
	-----------------*/
161
 
162
 
163
}
164
 
165
 
166
 
167