Subversion Repositories eFlore/Applications.cel

Rev

Rev 1945 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1945 Rev 1967
Line 1... Line 1...
1
package org.tela_botanica.client.util;
1
package org.tela_botanica.client.util;
Line -... Line 2...
-
 
2
 
2
 
3
import java.util.ArrayList;
3
import java.util.Date;
4
import java.util.Date;
4
import java.util.HashMap;
5
import java.util.HashMap;
-
 
6
import java.util.Iterator;
5
import java.util.Iterator;
7
import java.util.List;
Line 6... Line 8...
6
import java.util.Map;
8
import java.util.Map;
7
 
9
 
-
 
10
import org.tela_botanica.client.interfaces.Rafraichissable;
Line 8... Line 11...
8
import org.tela_botanica.client.interfaces.Rafraichissable;
11
import org.tela_botanica.client.modeles.dao.ListeReferentielChampsEtendusDAO;
9
import org.tela_botanica.client.modeles.dao.ListeReferentielChampsEtendusDAO;
12
import org.tela_botanica.client.modeles.objets.Configuration;
10
 
13
 
11
import com.google.gwt.user.client.Timer;
14
import com.google.gwt.user.client.Timer;
Line 18... Line 21...
18
import com.gwtext.client.data.ArrayReader;
21
import com.gwtext.client.data.ArrayReader;
19
import com.gwtext.client.data.FieldDef;
22
import com.gwtext.client.data.FieldDef;
20
import com.gwtext.client.data.MemoryProxy;
23
import com.gwtext.client.data.MemoryProxy;
21
import com.gwtext.client.data.Record;
24
import com.gwtext.client.data.Record;
22
import com.gwtext.client.data.RecordDef;
25
import com.gwtext.client.data.RecordDef;
-
 
26
import com.gwtext.client.data.SimpleStore;
23
import com.gwtext.client.data.Store;
27
import com.gwtext.client.data.Store;
24
import com.gwtext.client.data.StringFieldDef;
28
import com.gwtext.client.data.StringFieldDef;
25
import com.gwtext.client.widgets.Button;
29
import com.gwtext.client.widgets.Button;
26
import com.gwtext.client.widgets.event.ButtonListenerAdapter;
30
import com.gwtext.client.widgets.event.ButtonListenerAdapter;
27
import com.gwtext.client.widgets.form.ComboBox;
31
import com.gwtext.client.widgets.form.ComboBox;
Line 48... Line 52...
48
	private final int KEY_SHIFT = 16;
52
	private final int KEY_SHIFT = 16;
49
	private final int KEY_TAB = 9;
53
	private final int KEY_TAB = 9;
50
	private final int KEY_UP = 38;
54
	private final int KEY_UP = 38;
Line 51... Line 55...
51
	
55
	
52
	final ComboBox nChamp;
56
	final ComboBox nChamp;
53
	String resultTplRefPerso = "<div class=\"search-item-ref\">{label}</div>";  
57
	final String champsListeTpl = "<div class=\"x-combo-list-item search-item-tpl search-c-field-tpl\" title=\"{label}\">{label}</div>";
54
	Button ajouterChampsEtenduEtFermer;
58
	Button ajouterChampsEtenduEtFermer;
55
	Button ajouterChampsEtendu;
59
	Button ajouterChampsEtendu;
56
	Button annulerAjouterChampEtendu;
60
	Button annulerAjouterChampEtendu;
Line -... Line 61...
-
 
61
	String idChamp = null;
-
 
62
	
57
	String idChamp = null;
63
	final ComboBox groupesChampsEtendus;
Line 58... Line 64...
58
	
64
	
59
	private Timer timer = null;
65
	private Timer timer = null;
-
 
66
	
60
	
67
	private Map<String, String> cacheClesValeur;
Line 61... Line 68...
61
	private Map<String, String> cacheClesValeur;
68
	private Record rdSelectionne = null;
62
	private Record rdSelectionne = null;
69
    private Record groupeSelectionne = null;
63
	private String valeurBrute = "";
70
	private String valeurBrute = "";
64
	
71
	
Line -... Line 72...
-
 
72
	public FormulaireSaisieChampEtendu() {	
-
 
73
		super();
-
 
74
		setPaddings(3);
-
 
75
		setBodyBorder(false);
-
 
76
		
-
 
77
		HTML indicationSaisieGroupe = new HTML("Vous pouvez ajouter plusieurs champs à la fois correspondant à un groupe "+
-
 
78
				"par exemple les champs du projet sauvage de ma rue ou florilèges, ou bien "+
-
 
79
				"les champs phytosociolgiques ");
-
 
80
		indicationSaisieGroupe.addStyleName("aideCreerChampEtendu");
-
 
81
		
-
 
82
		groupesChampsEtendus = new ComboBox();
-
 
83
		groupesChampsEtendus.setLabel("Ajouter un groupe de champs");
-
 
84
		groupesChampsEtendus.setStore(getGroupesChampsEtendusStore());
-
 
85
		groupesChampsEtendus.setDisplayField("label") ;
-
 
86
		groupesChampsEtendus.setValueField("valeur");
-
 
87
		groupesChampsEtendus.setEditable(false);
-
 
88
		groupesChampsEtendus.setHideTrigger(false);
-
 
89
		groupesChampsEtendus.setForceSelection(true);
-
 
90
		groupesChampsEtendus.setCls("champ-separation");
-
 
91
		groupesChampsEtendus.setValue("");
-
 
92
		
65
	public FormulaireSaisieChampEtendu() {	
93
		if(groupesChampsEtendusSontDefinis()) {
66
		super();
94
			add(indicationSaisieGroupe);
67
		setPaddings(3);
95
			add(groupesChampsEtendus);
68
		setBodyBorder(false);
96
		}
69
		
97
		
Line 70... Line 98...
70
		HTML indicationSaisie = new HTML("Saisissez un nom de champ ou choisisez un nom proposé par l'autocomplétion "+
98
		HTML indicationSaisie = new HTML("Saisissez un nom de champ ou choisisez un nom proposé par l'autocomplétion "+
71
				"Si vous choissisez un nom de champ existant vous pourrez profiter d'une autocomplétion "+
99
				"Si vous choissisez un nom de champ existant vous pourrez profiter d'une autocomplétion "+
72
				"sur les valeur déjà saisies pour ce champ par les autres utilisateurs");
100
				"sur les valeur déjà saisies pour ce champ par les autres utilisateurs");
73
		indicationSaisie.addStyleName("aideCreerChampEtendu");
101
		indicationSaisie.addStyleName("aideCreerChampEtendu");
74
		add(indicationSaisie);
102
		add(indicationSaisie);
Line 75... Line 103...
75
		
103
		
76
		HorizontalPanel hp = new HorizontalPanel();
104
		HorizontalPanel hp = new HorizontalPanel();
77
		hp.setBorderWidth(0);
105
		hp.setBorderWidth(0);
78
		
106
				
79
		nChamp = new ComboBox("Nom du champ", "nom_champ_etendu");
107
		nChamp = new ComboBox("Nom du champ", "nom_champ_etendu");
80
		add(nChamp);
108
		add(nChamp);
Line 81... Line 109...
81
		
109
		
82
		ajouterChampsEtenduEtFermer = new Button("Valider");
110
		ajouterChampsEtenduEtFermer = new Button("Ajouter et fermer");
83
		ajouterChampsEtenduEtFermer.setTooltip("Ajouter un champ étendu et fermer la fenêtre");
111
		ajouterChampsEtenduEtFermer.setTooltip("Ajouter un champ étendu ou un groupe de champs et fermer la fenêtre");
84
		ajouterChampsEtendu = new Button("Ajouter");
112
		ajouterChampsEtendu = new Button("Ajouter");
Line 85... Line -...
85
		ajouterChampsEtendu.setTooltip("Ajouter un champ étendu");
-
 
86
		annulerAjouterChampEtendu = new Button("Annuler");
113
		ajouterChampsEtendu.setTooltip("Ajouter un champ étendu ou un groupe de champ");
87
		annulerAjouterChampEtendu.setTooltip("Fermer la fenêtre sans ajouter de champ");
-
 
88
		
114
		annulerAjouterChampEtendu = new Button("Annuler");
89
		hp.add(ajouterChampsEtenduEtFermer);
115
		annulerAjouterChampEtendu.setTooltip("Fermer la fenêtre sans ajouter de champ");
90
		hp.add(ajouterChampsEtendu);
116
		
91
		hp.add(annulerAjouterChampEtendu);	
117
		hp.add(ajouterChampsEtenduEtFermer);
92
		add(hp);
-
 
93
		
118
		hp.add(ajouterChampsEtendu);
94
		nChamp.setTpl(resultTplRefPerso);
119
		hp.add(annulerAjouterChampEtendu);	
Line 95... Line 120...
95
		nChamp.setMode(ComboBox.REMOTE);
120
		add(hp);
96
		nChamp.setItemSelector("div.search-item-ref");
121
		
Line 179... Line 204...
179
            	nChamp.setRawValue(valeurBrute);
204
            	nChamp.setRawValue(valeurBrute);
180
            	nChamp.collapse();
205
            	nChamp.collapse();
181
            }
206
            }
182
	     });
207
	     });
Line -... Line 208...
-
 
208
	    
-
 
209
	    groupesChampsEtendus.addListener(new ComboBoxListenerAdapter() {  
-
 
210
			@Override
-
 
211
			public void onSelect(ComboBox comboBox, Record record, int index) {  
-
 
212
            	groupeSelectionne = record;
-
 
213
            }
-
 
214
	     });
183
	    
215
	    
184
	    ajouterChampsEtenduEtFermer.addListener(new ButtonListenerAdapter() {			
216
	    ajouterChampsEtenduEtFermer.addListener(new ButtonListenerAdapter() {			
185
			@Override
217
			@Override
186
			public void onClick(Button button, EventObject e) {
218
			public void onClick(Button button, EventObject e) {
187
				if(champEtenduEstValide()) {
219
				if(doitAjouterGroupe()) {
188
					surValidation(validerEtRenvoyerChampEtendu());
220
					surValidationMultiple(renvoyerListeChampsEtendus(groupeSelectionne.getAsString("valeur")));
-
 
221
				} else {
-
 
222
					if(champEtenduEstValide()) {
-
 
223
						surValidation(validerEtRenvoyerChampEtendu());
189
				} else {
224
					} else {
-
 
225
						Window.alert("Le nom du champ étendu ne peut pas être vide");
190
					Window.alert("Le nom du champ étendu ne peut pas être vide");
226
					}
191
				}	
227
				}
192
			}
228
			}
Line 193... Line 229...
193
		});
229
		});
194
	    
230
	    
Line 233... Line 269...
233
		ChampSaisieEtendu retour = new ChampSaisieEtendu(valeurChamp, idNouveauChamp);
269
		ChampSaisieEtendu retour = new ChampSaisieEtendu(valeurChamp, idNouveauChamp);
234
		retour.setId(idNouveauChamp);
270
		retour.setId(idNouveauChamp);
235
		return retour;
271
		return retour;
236
	}
272
	}
Line -... Line 273...
-
 
273
	
-
 
274
	private List<ChampSaisieEtendu> renvoyerListeChampsEtendus(String groupe) {	
-
 
275
		List<ChampSaisieEtendu> champsDuGroupe = new ArrayList<ChampSaisieEtendu>();
-
 
276
		HashMap<String, String> listeChampsEtendus = Configuration.getGroupesChampsEtendus().get(groupe);
-
 
277
		for (Iterator<String> iterator = listeChampsEtendus.keySet().iterator(); iterator.hasNext();) {
-
 
278
			String cle = iterator.next();
-
 
279
			String label = listeChampsEtendus.get(cle);
-
 
280
			ChampSaisieEtendu champ = new ChampSaisieEtendu(label, cle);
-
 
281
			champsDuGroupe.add(champ);
-
 
282
		}
-
 
283
 
-
 
284
		return champsDuGroupe;
-
 
285
	}
-
 
286
	
-
 
287
	private boolean doitAjouterGroupe() {
-
 
288
		return groupeSelectionne != null && !groupeSelectionne.getAsString("valeur").equals("");
-
 
289
	}
237
	
290
	
238
	private boolean champEtenduEstValide() {
291
	private boolean champEtenduEstValide() {
239
		String valeurChamp = nChamp.getValueAsString();
292
		String valeurChamp = nChamp.getValueAsString();
240
		return (valeurChamp != null && !valeurChamp.isEmpty());
293
		return (valeurChamp != null && !valeurChamp.isEmpty());
Line 252... Line 305...
252
		ListeReferentielChampsEtendusDAO lrce = new ListeReferentielChampsEtendusDAO(null);
305
		ListeReferentielChampsEtendusDAO lrce = new ListeReferentielChampsEtendusDAO(null);
253
		lrce.obtenirListeNomsChampsEtendus(this, valeur+"*");
306
		lrce.obtenirListeNomsChampsEtendus(this, valeur+"*");
254
	}
307
	}
Line 255... Line 308...
255
	
308
	
-
 
309
	public abstract void surAjout(ChampSaisieEtendu champ);
256
	public abstract void surAjout(ChampSaisieEtendu champ);
310
	public abstract void surAjoutMultiple(List<ChampSaisieEtendu> champs);
-
 
311
	public abstract void surValidation(ChampSaisieEtendu champ);
257
	public abstract void surValidation(ChampSaisieEtendu champ);
312
	public abstract void surValidationMultiple(List<ChampSaisieEtendu> champs);
Line 258... Line 313...
258
	public abstract void surAnnulation();
313
	public abstract void surAnnulation();
259
	
314
	
Line 285... Line 340...
285
		Store store=new Store(dataProxy,reader);
340
		Store store=new Store(dataProxy,reader);
Line 286... Line 341...
286
		
341
		
287
		nChamp.setStore(store);
342
		nChamp.setStore(store);
288
		store.load();
343
		store.load();
-
 
344
	}
-
 
345
	
-
 
346
	private boolean groupesChampsEtendusSontDefinis() {
-
 
347
		return Configuration.getGroupesChampsEtendus().size() > 0;
-
 
348
	}
-
 
349
	
-
 
350
	private Store getGroupesChampsEtendusStore() {
-
 
351
		int i = 1;
-
 
352
				
-
 
353
		Map<String, HashMap<String, String>> listeGroupesChampsEtendus = Configuration.getGroupesChampsEtendus();		
-
 
354
		Object[][] valeurs = new Object[listeGroupesChampsEtendus.size()+1][2];
-
 
355
		
-
 
356
		valeurs[0][0] = "...";
-
 
357
		valeurs[0][1] = "";
-
 
358
		if(listeGroupesChampsEtendus.size() > 0) {
-
 
359
			for (Iterator<String> it = listeGroupesChampsEtendus.keySet().iterator(); it.hasNext();) 
-
 
360
			{
-
 
361
				String cle = it.next();
-
 
362
				valeurs[i][0]= cle;
-
 
363
				valeurs[i][1]= cle;
-
 
364
				i++;
-
 
365
			}
-
 
366
		}					
-
 
367
		SimpleStore store = new SimpleStore(new String[] {"label","valeur"},valeurs);
-
 
368
		store.load();
-
 
369
		return store;
289
	}
370
	}