Subversion Repositories eFlore/Applications.coel

Rev

Rev 1360 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1360 Rev 1364
1
package org.tela_botanica.client.vues;
1
package org.tela_botanica.client.vues;
2
 
2
 
3
import org.tela_botanica.client.Mediateur;
3
import org.tela_botanica.client.Mediateur;
4
import org.tela_botanica.client.composants.ChampComboBoxRechercheTempsReelPaginable;
4
import org.tela_botanica.client.composants.ChampComboBoxRechercheTempsReelPaginable;
5
import org.tela_botanica.client.composants.pagination.ProxyProjets;
5
import org.tela_botanica.client.composants.pagination.ProxyProjets;
6
import org.tela_botanica.client.i18n.Constantes;
6
import org.tela_botanica.client.i18n.Constantes;
7
import org.tela_botanica.client.interfaces.Rafraichissable;
7
import org.tela_botanica.client.interfaces.Rafraichissable;
8
import org.tela_botanica.client.modeles.projet.Projet;
8
import org.tela_botanica.client.modeles.projet.Projet;
9
import org.tela_botanica.client.util.Debug;
9
import org.tela_botanica.client.util.Debug;
10
import org.tela_botanica.client.util.UtilString;
10
import org.tela_botanica.client.util.UtilString;
11
 
11
 
12
import com.extjs.gxt.ui.client.data.ModelData;
12
import com.extjs.gxt.ui.client.data.ModelData;
13
import com.extjs.gxt.ui.client.data.ModelType;
13
import com.extjs.gxt.ui.client.data.ModelType;
14
import com.extjs.gxt.ui.client.event.ComponentEvent;
14
import com.extjs.gxt.ui.client.event.ComponentEvent;
15
import com.extjs.gxt.ui.client.event.KeyListener;
15
import com.extjs.gxt.ui.client.event.KeyListener;
16
import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
16
import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
17
import com.extjs.gxt.ui.client.event.SelectionChangedListener;
17
import com.extjs.gxt.ui.client.event.SelectionChangedListener;
18
import com.extjs.gxt.ui.client.widget.ContentPanel;
18
import com.extjs.gxt.ui.client.widget.ContentPanel;
19
import com.extjs.gxt.ui.client.widget.form.Field;
19
import com.extjs.gxt.ui.client.widget.form.Field;
20
import com.extjs.gxt.ui.client.widget.form.Validator;
20
import com.extjs.gxt.ui.client.widget.form.Validator;
21
import com.extjs.gxt.ui.client.widget.layout.FormLayout;
21
import com.extjs.gxt.ui.client.widget.layout.FormLayout;
22
import com.google.gwt.event.dom.client.KeyCodes;
22
import com.google.gwt.event.dom.client.KeyCodes;
23
 
23
 
24
public class FiltreVue extends ContentPanel implements Rafraichissable {
24
public class FiltreVue extends ContentPanel implements Rafraichissable {
25
	private Mediateur mediateur = null;
25
	private Mediateur mediateur = null;
26
	private Constantes i18nC = null;
26
	private Constantes i18nC = null;
27
	private Projet tousProjets = null;
27
	private Projet tousProjets = null;
28
	
28
	
29
	private ChampComboBoxRechercheTempsReelPaginable projetsCombo = null;
29
	private ChampComboBoxRechercheTempsReelPaginable projetsCombo = null;
30
	
30
	
31
	public FiltreVue(Mediateur mediateurCourrant) {
31
	public FiltreVue(Mediateur mediateurCourrant) {
32
		
32
		
33
		mediateur = mediateurCourrant;
33
		mediateur = mediateurCourrant;
34
		i18nC = Mediateur.i18nC;
34
		i18nC = Mediateur.i18nC;
35
		
35
		
36
		tousProjets = new Projet();
36
		tousProjets = new Projet();
37
		tousProjets.set("nom", i18nC.tousProjets());
37
		tousProjets.set("nom", i18nC.tousProjets());
38
		
38
		
39
		setHeading(i18nC.titreFiltre());
39
		setHeading(i18nC.titreFiltre());
40
		setLayout(new FormLayout());
40
		setLayout(new FormLayout());
41
		setLayoutOnChange(true);
41
		setLayoutOnChange(true);
42
		
42
		
43
		/*********************************/
43
		/*********************************/
44
		/**			Champ Projets		**/
44
		/**			Champ Projets		**/
45
		/*********************************/
45
		/*********************************/
46
		
46
		
47
		ModelType modelTypeProjets = new ModelType();
47
		ModelType modelTypeProjets = new ModelType();
48
		modelTypeProjets.setRoot("projets");
48
		modelTypeProjets.setRoot("projets");
49
		modelTypeProjets.setTotalName("nbElements");
49
		modelTypeProjets.setTotalName("nbElements");
50
		modelTypeProjets.addField("cpr_nom");
50
		modelTypeProjets.addField("cpr_nom");
51
		modelTypeProjets.addField("cpr_id_projet");
51
		modelTypeProjets.addField("cpr_id_projet");
52
		
52
		
53
		String displayNameProjets = "cpr_nom";
53
		String displayNameProjets = "cpr_nom";
54
		ProxyProjets<ModelData> proxyProjets = new ProxyProjets<ModelData>();
54
		ProxyProjets<ModelData> proxyProjets = new ProxyProjets<ModelData>();
55
		
55
		
56
		projetsCombo = new ChampComboBoxRechercheTempsReelPaginable(proxyProjets, modelTypeProjets, displayNameProjets);
56
		projetsCombo = new ChampComboBoxRechercheTempsReelPaginable(proxyProjets, modelTypeProjets, displayNameProjets);
57
		projetsCombo.getCombo().setEmptyText("Tous les projets");
57
		projetsCombo.getCombo().setEmptyText("Tous les projets");
58
		projetsCombo.getCombo().setAllowBlank(true);
58
		projetsCombo.getCombo().setAllowBlank(true);
59
		projetsCombo.getCombo().setForceSelection(false);
59
		projetsCombo.getCombo().setForceSelection(false);
60
		projetsCombo.getCombo().setEditable(true);
60
		projetsCombo.getCombo().setEditable(true);
61
		projetsCombo.setWidth(215);
61
		projetsCombo.setWidth(215);
62
		projetsCombo.getCombo().setValidator(new Validator() {
62
		projetsCombo.getCombo().setValidator(new Validator() {
63
			public String validate(Field<?> field, String value) {
63
			public String validate(Field<?> field, String value) {
64
				String retour = null;
64
				String retour = null;
65
				if (field.getRawValue().equals("")) {
65
				if (field.getRawValue().equals("")) {
66
					field.setValue(null);
66
					field.setValue(null);
67
				} else if (projetsCombo.getStore().findModel("cpr_nom", field.getRawValue()) == null) {
67
				} else if (projetsCombo.getStore().findModel("cpr_nom", field.getRawValue()) == null) {
68
					String contenuBrut = field.getRawValue();
68
					String contenuBrut = field.getRawValue();
69
					field.setValue(null);
69
					field.setValue(null);
70
					field.setRawValue(contenuBrut);
70
					field.setRawValue(contenuBrut);
71
					retour = "Veuillez sélectionner une valeur ou laisser le champ vide";
71
					retour = "Veuillez sélectionner une valeur ou laisser le champ vide";
72
				}
72
				}
73
				return retour;
73
				return retour;
74
			}
74
			}
75
		});
75
		});
76
		
76
		
77
		final Projet tousProjets = new Projet();
77
		final Projet tousProjets = new Projet();
78
		tousProjets.set("nom", i18nC.tousProjets());
78
		tousProjets.set("nom", i18nC.tousProjets());
79
		
79
		
80
		// Ajout d'un écouteur pour le changement => enregistre la valeur courante du projet dans le registre
80
		// Ajout d'un écouteur pour le changement => enregistre la valeur courante du projet dans le registre
81
		projetsCombo.getCombo().addSelectionChangedListener(new SelectionChangedListener<ModelData>() {
81
		projetsCombo.getCombo().addSelectionChangedListener(new SelectionChangedListener<ModelData>() {
82
			public void selectionChanged(SelectionChangedEvent<ModelData> se) {
82
			public void selectionChanged(SelectionChangedEvent<ModelData> se) {
83
				if (se.getSelectedItem() != null) {
83
				if (se.getSelectedItem() != null) {
84
					mediateur.activerChargement(i18nC.chargement());
84
					mediateur.activerChargement(i18nC.chargement());
85
					Projet projet = new Projet (se.getSelectedItem());
85
					Projet projet = new Projet (se.getSelectedItem());
86
					mediateur.selectionnerProjetCourant(projet);
86
					mediateur.selectionnerProjetCourant(projet);
87
				}
87
				}
88
			}
88
			}
89
		});
89
		});
90
		
90
		
91
		projetsCombo.getCombo().addKeyListener(new KeyListener() {
91
		projetsCombo.getCombo().addKeyListener(new KeyListener() {
92
			public void componentKeyUp(ComponentEvent ce) {
92
			public void componentKeyUp(ComponentEvent ce) {
93
				projetsCombo.getCombo().setRawValue("Tous les projets");
93
				projetsCombo.getCombo().setRawValue("Tous les projets");
94
				projetsCombo.getCombo().setValue(null);
94
				projetsCombo.getCombo().setValue(null);
95
				projetsCombo.getCombo().clearSelections();
95
				projetsCombo.getCombo().clearSelections();
96
				if (ce.getKeyCode() == KeyCodes.KEY_ENTER) {
96
				if (ce.getKeyCode() == KeyCodes.KEY_ENTER) {
97
					mediateur.selectionnerProjetCourant(tousProjets);
97
					mediateur.selectionnerProjetCourant(tousProjets);
98
					projetsCombo.getCombo().setValue(tousProjets);
98
					projetsCombo.getCombo().setValue(tousProjets);
99
					projetsCombo.getCombo().setVisible(false);
99
					projetsCombo.getCombo().setVisible(false);
100
					projetsCombo.getCombo().collapse();
100
					projetsCombo.getCombo().collapse();
101
					projetsCombo.getCombo().setVisible(true);
101
					projetsCombo.getCombo().setVisible(true);
102
				}
102
				}
103
			}
103
			}
104
		});
104
		});
105
 
105
 
106
		add(projetsCombo);
106
		add(projetsCombo);
107
	}
107
	}
-
 
108
	
-
 
109
	public String getProjet() {
-
 
110
		if (projetsCombo.getValeur() != null) {
-
 
111
			Projet projet = new Projet(projetsCombo.getValeur());
-
 
112
			return projet.getAbreviation();
-
 
113
		} else {
-
 
114
			return null;
-
 
115
		}
-
 
116
 
-
 
117
	}
108
	
118
	
109
	public void rafraichir(Object nouvellesDonnees) {
119
	public void rafraichir(Object nouvellesDonnees) {
110
		// empty ...
120
		// empty ...
111
	}
121
	}
112
}
-
 
113
122
}
-
 
123