Subversion Repositories eFlore/Applications.coel

Rev

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

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