Subversion Repositories eFlore/Applications.coel

Rev

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

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