1287 |
cyprien |
1 |
package org.tela_botanica.client.composants;
|
|
|
2 |
|
|
|
3 |
import java.util.List;
|
1329 |
cyprien |
4 |
import java.util.Map;
|
1287 |
cyprien |
5 |
|
|
|
6 |
import org.tela_botanica.client.composants.pagination.ChargeurListe;
|
|
|
7 |
import org.tela_botanica.client.composants.pagination.Proxy;
|
|
|
8 |
import org.tela_botanica.client.composants.pagination.TransformateurJSONaModelData;
|
1426 |
cyprien |
9 |
import org.tela_botanica.client.interfaces.Rafraichissable;
|
|
|
10 |
import org.tela_botanica.client.modeles.Information;
|
1287 |
cyprien |
11 |
import org.tela_botanica.client.modeles.Valeur;
|
1426 |
cyprien |
12 |
import org.tela_botanica.client.modeles.collection.Collection;
|
|
|
13 |
import org.tela_botanica.client.synchronisation.Sequenceur;
|
1287 |
cyprien |
14 |
import org.tela_botanica.client.util.Debug;
|
1426 |
cyprien |
15 |
import org.tela_botanica.client.vues.Formulaire;
|
1287 |
cyprien |
16 |
|
|
|
17 |
import com.extjs.gxt.ui.client.event.BaseEvent;
|
|
|
18 |
import com.extjs.gxt.ui.client.event.Events;
|
1426 |
cyprien |
19 |
import com.extjs.gxt.ui.client.event.FieldEvent;
|
1287 |
cyprien |
20 |
import com.extjs.gxt.ui.client.event.Listener;
|
|
|
21 |
import com.extjs.gxt.ui.client.store.ListStore;
|
1329 |
cyprien |
22 |
import com.extjs.gxt.ui.client.util.Size;
|
|
|
23 |
import com.extjs.gxt.ui.client.util.Util;
|
1287 |
cyprien |
24 |
import com.extjs.gxt.ui.client.widget.LayoutContainer;
|
|
|
25 |
import com.extjs.gxt.ui.client.widget.VerticalPanel;
|
|
|
26 |
import com.extjs.gxt.ui.client.widget.form.ComboBox;
|
1369 |
cyprien |
27 |
import com.extjs.gxt.ui.client.widget.layout.AbsoluteLayout;
|
|
|
28 |
import com.extjs.gxt.ui.client.widget.layout.AnchorLayout;
|
|
|
29 |
import com.extjs.gxt.ui.client.widget.layout.BoxLayout;
|
|
|
30 |
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
|
|
|
31 |
import com.extjs.gxt.ui.client.widget.layout.FlowLayout;
|
1329 |
cyprien |
32 |
import com.extjs.gxt.ui.client.widget.layout.FormData;
|
|
|
33 |
import com.extjs.gxt.ui.client.widget.layout.FormLayout;
|
1287 |
cyprien |
34 |
|
1329 |
cyprien |
35 |
import com.extjs.gxt.ui.client.data.BaseModelData;
|
1287 |
cyprien |
36 |
import com.extjs.gxt.ui.client.data.BasePagingLoadConfig;
|
|
|
37 |
import com.extjs.gxt.ui.client.data.LoadEvent;
|
|
|
38 |
import com.extjs.gxt.ui.client.data.Loader;
|
|
|
39 |
import com.extjs.gxt.ui.client.data.ModelData;
|
|
|
40 |
import com.extjs.gxt.ui.client.data.ModelType;
|
|
|
41 |
import com.extjs.gxt.ui.client.data.PagingLoadResult;
|
1426 |
cyprien |
42 |
import com.google.gwt.user.client.rpc.AsyncCallback;
|
1287 |
cyprien |
43 |
|
1426 |
cyprien |
44 |
public class ChampComboBoxRechercheTempsReelPaginable extends LayoutContainer implements Rafraichissable {
|
1287 |
cyprien |
45 |
|
|
|
46 |
//-------------//
|
|
|
47 |
// ATTRIBUTS //
|
|
|
48 |
//-------------//
|
|
|
49 |
|
|
|
50 |
private ListStore<ModelData> store = null;
|
|
|
51 |
private ComboBox<ModelData> combo = null;
|
|
|
52 |
|
|
|
53 |
private Proxy<?> proxy = null;
|
|
|
54 |
private TransformateurJSONaModelData<PagingLoadResult<ModelData>> reader = null;
|
|
|
55 |
private ChargeurListe<PagingLoadResult<ModelData>> loader = null;
|
|
|
56 |
|
|
|
57 |
private int start = 0;
|
|
|
58 |
private int limit = 10;
|
1369 |
cyprien |
59 |
private int largeur = 370;
|
1287 |
cyprien |
60 |
|
|
|
61 |
private BasePagingLoadConfig plc = null;
|
|
|
62 |
private ModelType modeltype = null;
|
|
|
63 |
private String displayName = "";
|
1329 |
cyprien |
64 |
private String recherche = "";
|
1287 |
cyprien |
65 |
|
1426 |
cyprien |
66 |
private String champValeurInitiale = "";
|
|
|
67 |
private String valeurInitiale = "";
|
|
|
68 |
|
1287 |
cyprien |
69 |
//-------------//
|
|
|
70 |
// METHODES //
|
|
|
71 |
//-------------//
|
|
|
72 |
|
|
|
73 |
/*--------------
|
|
|
74 |
Constructeur
|
|
|
75 |
--------------*/
|
1426 |
cyprien |
76 |
|
1287 |
cyprien |
77 |
public ChampComboBoxRechercheTempsReelPaginable(Proxy<?> proxy, ModelType modeltype, String displayName) {
|
|
|
78 |
|
|
|
79 |
this.modeltype = modeltype;
|
|
|
80 |
this.proxy = proxy;
|
|
|
81 |
this.displayName = displayName;
|
|
|
82 |
|
|
|
83 |
plc = new BasePagingLoadConfig();
|
|
|
84 |
plc.setLimit(limit);
|
|
|
85 |
plc.setOffset(start);
|
|
|
86 |
|
|
|
87 |
reader = new TransformateurJSONaModelData<PagingLoadResult<ModelData>>(modeltype);
|
|
|
88 |
|
1426 |
cyprien |
89 |
loader = new ChargeurListe<PagingLoadResult<ModelData>>(proxy, reader, this);
|
1287 |
cyprien |
90 |
loader.setLimit(plc.getLimit());
|
|
|
91 |
loader.setOffset(plc.getOffset());
|
|
|
92 |
|
|
|
93 |
loader.addListener(Loader.BeforeLoad, new Listener<LoadEvent>() {
|
|
|
94 |
public void handleEvent(LoadEvent be) {
|
|
|
95 |
be.<ModelData> getConfig().set("start", be.<ModelData> getConfig().get("offset"));
|
|
|
96 |
}
|
|
|
97 |
});
|
|
|
98 |
|
|
|
99 |
loader.addListener(Loader.Load, new Listener<LoadEvent>() {
|
|
|
100 |
public void handleEvent(LoadEvent be) {
|
|
|
101 |
|
|
|
102 |
}
|
|
|
103 |
});
|
|
|
104 |
|
|
|
105 |
loader.addListener(Loader.LoadException, new Listener<LoadEvent>() {
|
|
|
106 |
public void handleEvent(LoadEvent be) {
|
|
|
107 |
|
|
|
108 |
}
|
|
|
109 |
});
|
|
|
110 |
|
1369 |
cyprien |
111 |
combo = new ComboBox<ModelData>();
|
1287 |
cyprien |
112 |
combo.setWidth(largeur);
|
1369 |
cyprien |
113 |
this.setWidth(largeur);
|
1287 |
cyprien |
114 |
combo.setDisplayField(displayName);
|
|
|
115 |
combo.setHideTrigger(false);
|
|
|
116 |
combo.setPageSize(plc.getLimit());
|
|
|
117 |
store = new ListStore<ModelData>(loader);
|
|
|
118 |
combo.setStore(store);
|
1426 |
cyprien |
119 |
loader.load(plc, recherche, false);
|
1369 |
cyprien |
120 |
|
1426 |
cyprien |
121 |
combo.addListener(Events.KeyUp, new Listener<FieldEvent>() {
|
1287 |
cyprien |
122 |
|
1426 |
cyprien |
123 |
public void handleEvent(FieldEvent fe) {
|
|
|
124 |
// on vérifie que les touches enfoncées ne sont pas les flèches du clavier
|
1430 |
cyprien |
125 |
if (!fe.isNavKeyPress()) {
|
1426 |
cyprien |
126 |
recherche = combo.getRawValue();
|
|
|
127 |
plc.setLimit(limit); plc.setOffset(start);
|
|
|
128 |
loader.setLimit(limit); loader.setOffset(start);
|
|
|
129 |
loader.load(plc, recherche, false);
|
|
|
130 |
}
|
1287 |
cyprien |
131 |
}
|
|
|
132 |
|
|
|
133 |
});
|
1369 |
cyprien |
134 |
|
|
|
135 |
this.add(combo);
|
1287 |
cyprien |
136 |
}
|
|
|
137 |
|
|
|
138 |
/*------------
|
|
|
139 |
Accesseurs
|
|
|
140 |
------------*/
|
|
|
141 |
public ComboBox<ModelData> getCombo()
|
|
|
142 |
{
|
|
|
143 |
return this.combo;
|
|
|
144 |
}
|
|
|
145 |
|
1329 |
cyprien |
146 |
public ModelData getValeur()
|
1287 |
cyprien |
147 |
{
|
1426 |
cyprien |
148 |
if (combo.getSelection() != null && combo.getSelection().size() > 0) return combo.getSelection().get(0);
|
1329 |
cyprien |
149 |
else return null;
|
1287 |
cyprien |
150 |
}
|
|
|
151 |
|
|
|
152 |
public ListStore<?> getStore()
|
|
|
153 |
{
|
|
|
154 |
return combo.getStore();
|
|
|
155 |
}
|
|
|
156 |
|
|
|
157 |
public void setWidth(int largeur)
|
|
|
158 |
{
|
|
|
159 |
this.largeur = largeur;
|
|
|
160 |
this.combo.setWidth(largeur);
|
|
|
161 |
}
|
|
|
162 |
|
1329 |
cyprien |
163 |
public void setWidth(int tailleLabel, int largeurTotale)
|
|
|
164 |
{
|
1369 |
cyprien |
165 |
this.setWidth(largeurTotale);
|
1329 |
cyprien |
166 |
this.largeur = largeurTotale;
|
|
|
167 |
this.combo.setWidth(largeurTotale - tailleLabel);
|
|
|
168 |
|
|
|
169 |
FormLayout fl = new FormLayout();
|
|
|
170 |
fl.setLabelWidth(tailleLabel);
|
1369 |
cyprien |
171 |
fl.setDefaultWidth(largeurTotale - tailleLabel);
|
|
|
172 |
this.setLayout(fl);
|
|
|
173 |
|
|
|
174 |
this.layout();
|
1329 |
cyprien |
175 |
}
|
1287 |
cyprien |
176 |
|
|
|
177 |
/*-----------------------------
|
|
|
178 |
Gestion du contenu du champ
|
|
|
179 |
-----------------------------*/
|
|
|
180 |
|
|
|
181 |
public List<ModelData> collecterValeursDuChamp()
|
|
|
182 |
{
|
|
|
183 |
return combo.getSelection();
|
|
|
184 |
}
|
|
|
185 |
|
|
|
186 |
public void peuplerChamp(List<ModelData> selection)
|
|
|
187 |
{
|
|
|
188 |
combo.setSelection(selection);
|
|
|
189 |
}
|
|
|
190 |
|
1426 |
cyprien |
191 |
public void chargerValeurInitiale(String valeurInitiale, String champ)
|
|
|
192 |
{
|
|
|
193 |
this.valeurInitiale = valeurInitiale;
|
|
|
194 |
this.champValeurInitiale = champ;
|
|
|
195 |
|
|
|
196 |
loader.load(plc, valeurInitiale, true);
|
|
|
197 |
}
|
|
|
198 |
|
|
|
199 |
/*-----------------------------
|
|
|
200 |
Rafraichir
|
|
|
201 |
-----------------------------*/
|
|
|
202 |
public void rafraichir(Object nouvellesDonnees) {
|
|
|
203 |
if (nouvellesDonnees instanceof Information) {
|
|
|
204 |
Information info = (Information) nouvellesDonnees;
|
|
|
205 |
if (info.getType().equals("selectionnerValeurCombo")) {
|
|
|
206 |
if (combo.getStore().findModel(champValeurInitiale, valeurInitiale) == null) Debug.log("ERREUR. Modele non trouvé");
|
|
|
207 |
else combo.setValue(combo.getStore().findModel(champValeurInitiale, valeurInitiale));
|
|
|
208 |
}
|
|
|
209 |
}
|
|
|
210 |
}
|
1287 |
cyprien |
211 |
|
|
|
212 |
/*----------------
|
|
|
213 |
Méthode privées
|
|
|
214 |
-----------------*/
|
1426 |
cyprien |
215 |
|
|
|
216 |
|
1287 |
cyprien |
217 |
|
|
|
218 |
}
|
|
|
219 |
|
|
|
220 |
|
|
|
221 |
|
|
|
222 |
|