Subversion Repositories eFlore/Applications.coel

Rev

Rev 1428 | Rev 1513 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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