Subversion Repositories eFlore/Applications.coel

Rev

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

Rev 1248 Rev 1330
Line 1... Line 1...
1
package org.tela_botanica.client.vues;
1
package org.tela_botanica.client.vues;
Line 2... Line -...
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;
-
 
8
import org.tela_botanica.client.modeles.projet.Projet;
11
import org.tela_botanica.client.modeles.projet.Projet;
9
import org.tela_botanica.client.util.Debug;
Line -... Line 10...
-
 
10
import org.tela_botanica.client.util.UtilString;
-
 
11
 
-
 
12
import com.extjs.gxt.ui.client.data.ModelData;
12
import org.tela_botanica.client.modeles.projet.ProjetListe;
13
import com.extjs.gxt.ui.client.data.ModelType;
13
 
14
import com.extjs.gxt.ui.client.event.ComponentEvent;
14
import com.extjs.gxt.ui.client.Registry;
15
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;
16
import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
17
import com.extjs.gxt.ui.client.store.ListStore;
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.button.Button;
-
 
20
import com.extjs.gxt.ui.client.widget.form.ComboBox;
19
import com.extjs.gxt.ui.client.widget.form.Field;
21
import com.extjs.gxt.ui.client.widget.form.ComboBox.TriggerAction;
20
import com.extjs.gxt.ui.client.widget.form.Validator;
Line 22... Line 21...
22
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
21
import com.extjs.gxt.ui.client.widget.layout.FormLayout;
23
import com.google.gwt.core.client.GWT;
22
import com.google.gwt.event.dom.client.KeyCodes;
24
 
23
 
25
public class FiltreVue extends ContentPanel implements Rafraichissable {
24
public class FiltreVue extends ContentPanel implements Rafraichissable {
Line 26... Line -...
26
	private Mediateur mediateur = null;
-
 
27
	private Constantes i18nC = null;
25
	private Mediateur mediateur = null;
Line 28... Line 26...
28
	private ListStore<Projet> projets = null;
26
	private Constantes i18nC = null;
-
 
27
	private Projet tousProjets = null;
29
	
28
	
30
	private ComboBox<Projet> listeProjets;
29
	private ChampComboBoxRechercheTempsReelPaginable projetsCombo = null;
Line -... Line 30...
-
 
30
	
-
 
31
	public FiltreVue(Mediateur mediateurCourrant) {
-
 
32
		
31
	private ProjetListe projetsCache = null;
33
		mediateur = mediateurCourrant;
32
	
34
		i18nC = Mediateur.i18nC;
33
	public FiltreVue(Mediateur mediateurCourrant) {
35
		
34
		mediateur = mediateurCourrant;
-
 
35
		i18nC = Mediateur.i18nC;
-
 
36
		
-
 
37
		setHeading(i18nC.titreFiltre());
-
 
38
		setLayout(new FitLayout());
-
 
39
		setLayoutOnChange(true);
-
 
40
 
-
 
41
		chargerProjets();
-
 
42
		initialiserListeProjets();
-
 
43
	}
-
 
44
	
-
 
Line 45... Line 36...
45
	private void chargerProjets() {
36
		tousProjets = new Projet();
46
		mediateur.selectionnerProjet(this, null);
-
 
47
	}
37
		tousProjets.set("nom", i18nC.tousProjets());
48
	
-
 
49
	private void initialiserListeProjets() {
-
 
50
	
38
		
51
		
-
 
52
		// Ajout de la sélection des projets
-
 
53
		listeProjets = new ComboBox<Projet>();
-
 
54
		projets = new ListStore<Projet>();
-
 
Line 55... Line 39...
55
		listeProjets.setStore(projets);
39
		setHeading(i18nC.titreFiltre());
-
 
40
		setLayout(new FormLayout());
-
 
41
		setLayoutOnChange(true);
-
 
42
		
-
 
43
		/*********************************/
-
 
44
		/**			Champ Projets		**/
-
 
45
		/*********************************/
56
		listeProjets.setEditable(false);
46
		
57
		listeProjets.setDisplayField("nom");
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";
58
		listeProjets.setEmptyText(i18nC.txtListeProjetDefaut());
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);
59
		listeProjets.setTypeAhead(true);
61
		projetsCombo.getCombo().setValidator(new Validator() {
60
		listeProjets.setTriggerAction(TriggerAction.ALL);  
62
			public String validate(Field<?> field, String value) {
-
 
63
				String retour = null;
-
 
64
				if (field.getRawValue().equals("")) {
61
		  
65
					field.setValue(null);
62
		
66
				} else if (projetsCombo.getStore().findModel("cpr_nom", field.getRawValue()) == null) {
63
		// Ajout d'un écouteur pour le changement => enregistre la valeur courante du projet dans le registre
-
 
64
	    listeProjets.addSelectionChangedListener(new SelectionChangedListener<Projet>() {
-
 
65
			
-
 
66
			public void selectionChanged(SelectionChangedEvent<Projet> se) {
-
 
67
				mediateur.activerChargement(i18nC.chargement());
-
 
68
				mediateur.selectionnerProjetCourant(se.getSelectedItem());
-
 
Line 69... Line -...
69
			}
-
 
70
		});
67
					String contenuBrut = field.getRawValue();
71
	    
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
		
-
 
79
		// Ajout d'un écouteur pour le changement => enregistre la valeur courante du projet dans le registre
-
 
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());
72
	    add(listeProjets);
85
					mediateur.selectionnerProjetCourant(projet);
-
 
86
				}
73
	}
87
			}
-
 
88
		});
74
	
89
		
75
	private void afficherListeProjets(List projetsRecus) {
90
		projetsCombo.getCombo().addKeyListener(new KeyListener() {
76
		projets.removeAll();
91
			public void componentKeyUp(ComponentEvent ce) {
-
 
92
				projetsCombo.getCombo().setRawValue("Tous les projets");
-
 
93
				projetsCombo.getCombo().setValue(null);
77
		
94
				projetsCombo.getCombo().clearSelections();
-
 
95
				if (ce.getKeyCode() == KeyCodes.KEY_ENTER) {
-
 
96
					mediateur.selectionnerProjetCourant(tousProjets);
78
		List<Projet> selection = new LinkedList<Projet>();
97
					projetsCombo.getCombo().setValue(tousProjets);
Line 79... Line 98...
79
		Projet tousProjets = new Projet();
98
					projetsCombo.getCombo().setVisible(false);
80
		tousProjets.set("nom", i18nC.tousProjets());
-
 
81
		projetsRecus.add(0, tousProjets);
-
 
82
		selection.add(tousProjets);
-
 
83
		projets.add(projetsRecus);
-
 
84
		listeProjets.setStore(projets);
-
 
85
		listeProjets.setSelection(selection);
-
 
86
		layout();
-
 
87
	}
-
 
88
	
99
					projetsCombo.getCombo().collapse();
89
	public void rafraichir(Object nouvellesDonnees) {
-
 
90
		if (nouvellesDonnees instanceof ProjetListe) {
-
 
91
			projetsCache = (ProjetListe) nouvellesDonnees;
100
					projetsCombo.getCombo().setVisible(true);
92
			Registry.register(RegistreId.PROJETS, projetsCache);
101
				}
93
			afficherListeProjets(projetsCache.toList());
102
			}