Subversion Repositories eFlore/Applications.coel

Rev

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

Rev 854 Rev 858
Line 9... Line 9...
9
import org.tela_botanica.client.vues.Formulaire;
9
import org.tela_botanica.client.vues.Formulaire;
Line 10... Line 10...
10
 
10
 
11
import com.extjs.gxt.ui.client.Registry;
11
import com.extjs.gxt.ui.client.Registry;
12
import com.extjs.gxt.ui.client.store.ListStore;
12
import com.extjs.gxt.ui.client.store.ListStore;
-
 
13
import com.extjs.gxt.ui.client.widget.form.ComboBox;
-
 
14
import com.extjs.gxt.ui.client.widget.form.Field;
13
import com.extjs.gxt.ui.client.widget.form.ComboBox;
15
import com.extjs.gxt.ui.client.widget.form.Validator;
Line 14... Line 16...
14
import com.google.gwt.core.client.GWT;
16
import com.google.gwt.core.client.GWT;
15
 
17
 
16
public class ChampComboBoxListeValeurs extends ComboBox<Valeur> implements Rafraichissable {
18
public class ChampComboBoxListeValeurs extends ComboBox<Valeur> implements Rafraichissable {
Line 17... Line 19...
17
	private Configuration config = null;
19
	private Configuration config = null;
18
	private Mediateur mediateur = null;
20
	private Mediateur mediateur = null;
-
 
21
 
Line 19... Line 22...
19
 
22
	private String listeValeursCode = null;
-
 
23
	private String nomChampATrier = null;
-
 
24
	private String valeurDefautId = null;
-
 
25
	
-
 
26
	public ChampComboBoxListeValeurs(String labelDuChamp, String codeDeLaliste) {
-
 
27
		initialiserChampComboBox(labelDuChamp, codeDeLaliste, 0);
-
 
28
	}
-
 
29
	
-
 
30
	public ChampComboBoxListeValeurs(String labelDuChamp, String codeDeLaliste, int tabIndex) {
20
	private String listeValeursCode = null;
31
		initialiserChampComboBox(labelDuChamp, codeDeLaliste, tabIndex);
21
	private String nomChampATrier = null;
32
	}
Line 22... Line 33...
22
	
33
	
23
	public ChampComboBoxListeValeurs(String labelDuChamp, String codeDeLaliste) {
34
	private void initialiserChampComboBox(String labelDuChamp, String codeDeLaliste, int tabIndex) {
24
		config = (Configuration) Registry.get(RegistreId.CONFIG);
35
		config = (Configuration) Registry.get(RegistreId.CONFIG);
25
		mediateur = (Mediateur) Registry.get(RegistreId.MEDIATEUR);
36
		mediateur = (Mediateur) Registry.get(RegistreId.MEDIATEUR);
26
		
37
		
Line -... Line 38...
-
 
38
		setForceSelection(true);
-
 
39
		setTriggerAction(TriggerAction.ALL);
-
 
40
		setDisplayField("nom");
-
 
41
		setStore(new ListStore<Valeur>());
-
 
42
		setEditable(false);
27
		setForceSelection(true);
43
 
-
 
44
		setTabIndex(tabIndex);
-
 
45
		
-
 
46
		if (labelDuChamp == null) {
-
 
47
			setLabelSeparator("");
-
 
48
		} else {
-
 
49
			setFieldLabel(labelDuChamp);
-
 
50
		}
-
 
51
		
-
 
52
		setValidator(new Validator() {
-
 
53
			@Override
-
 
54
			public String validate(Field<?> field, String value) {
-
 
55
				String retour = null;
-
 
56
				if (field.getRawValue().equals("")) {
-
 
57
					field.setValue(null);
-
 
58
				} else if (getStore().findModel("nom", field.getRawValue()) == null) {
-
 
59
					String contenuBrut = field.getRawValue();
-
 
60
					field.setValue(null);
Line 28... Line 61...
28
		setTriggerAction(TriggerAction.ALL);
61
					field.setRawValue(contenuBrut);
29
		setDisplayField("nom");
62
					retour = "Veuillez sélectionner une valeur ou laisser le champ vide";
30
		setStore(new ListStore<Valeur>());
63
				}
Line 41... Line 74...
41
	}
74
	}
42
	public void setListeCode(String code) {
75
	public void setListeCode(String code) {
43
		listeValeursCode = code;
76
		listeValeursCode = code;
44
	}
77
	}
Line -... Line 78...
-
 
78
	
-
 
79
	public void setValeurDefaut(String id) {
-
 
80
		valeurDefautId = id;
-
 
81
		actualiserValeurParDefaut();
-
 
82
	}
45
	
83
	
46
	public String getTrie() {
84
	public String getTrie() {
47
		String champATrier = "nom";
85
		String champATrier = "nom";
48
		if (nomChampATrier != null) {
86
		if (nomChampATrier != null) {
49
			champATrier = nomChampATrier;
87
			champATrier = nomChampATrier;
Line 52... Line 90...
52
	}
90
	}
53
	public void setTrie(String champATrier) {
91
	public void setTrie(String champATrier) {
54
		nomChampATrier = champATrier;
92
		nomChampATrier = champATrier;
55
	}
93
	}
Line -... Line 94...
-
 
94
	
-
 
95
	public void actualiserValeurParDefaut() {
-
 
96
		if (valeurDefautId != null && getStore() != null) {
-
 
97
			setValue(getStore().findModel("id_valeur", valeurDefautId));
-
 
98
		}
-
 
99
	}
56
	
100
	
57
	@Override
101
	@Override
58
	public void rafraichir(Object nouvellesDonnees) {
102
	public void rafraichir(Object nouvellesDonnees) {
59
		if (nouvellesDonnees instanceof ValeurListe) {
103
		if (nouvellesDonnees instanceof ValeurListe) {
60
			ValeurListe listeValeurs = (ValeurListe) nouvellesDonnees;
104
			ValeurListe listeValeurs = (ValeurListe) nouvellesDonnees;
61
			if (listeValeurs.getId().equals(config.getListeId(getListeCode()))) {
105
			if (listeValeurs.getId().equals(config.getListeId(getListeCode()))) {
-
 
106
				Formulaire.rafraichirComboBox(listeValeurs, this, getTrie());
62
				Formulaire.rafraichirComboBox(listeValeurs, this, getTrie());
107
				actualiserValeurParDefaut();
63
			} 
108
			} 
64
		} else {
109
		} else {
65
			GWT.log(Mediateur.i18nM.erreurRafraichir(nouvellesDonnees.getClass(), this.getClass()), null);
110
			GWT.log(Mediateur.i18nM.erreurRafraichir(nouvellesDonnees.getClass(), this.getClass()), null);
66
		}
111
		}