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