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