Subversion Repositories eFlore/Applications.coel

Rev

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

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