Subversion Repositories eFlore/Applications.coel

Rev

Rev 1248 | Rev 1360 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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