Subversion Repositories eFlore/Applications.coel

Rev

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

Rev 489 Rev 512
1
package org.tela_botanica.client.vues;
1
package org.tela_botanica.client.vues;
2
 
2
 
3
import java.util.ArrayList;
3
import java.util.ArrayList;
4
import java.util.Iterator;
4
import java.util.Iterator;
5
import java.util.List;
5
import java.util.List;
6
 
6
 
7
import org.tela_botanica.client.ComposantClass;
7
import org.tela_botanica.client.ComposantClass;
8
import org.tela_botanica.client.Mediateur;
8
import org.tela_botanica.client.Mediateur;
9
import org.tela_botanica.client.RegistreId;
9
import org.tela_botanica.client.RegistreId;
-
 
10
import org.tela_botanica.client.images.Images;
10
import org.tela_botanica.client.interfaces.Rafraichissable;
11
import org.tela_botanica.client.interfaces.Rafraichissable;
11
import org.tela_botanica.client.modeles.Information;
12
import org.tela_botanica.client.modeles.Information;
12
import org.tela_botanica.client.modeles.Personne;
13
import org.tela_botanica.client.modeles.Personne;
13
import org.tela_botanica.client.modeles.PersonneListe;
14
import org.tela_botanica.client.modeles.PersonneListe;
14
 
-
 
15
import com.extjs.gxt.ui.client.Registry;
15
import com.extjs.gxt.ui.client.Registry;
16
import com.extjs.gxt.ui.client.Style.Scroll;
-
 
17
import com.extjs.gxt.ui.client.Style.SelectionMode;
-
 
18
import com.extjs.gxt.ui.client.Style.SortDir;
16
import com.extjs.gxt.ui.client.Style.SortDir;
19
import com.extjs.gxt.ui.client.binder.TableBinder;
-
 
20
import com.extjs.gxt.ui.client.event.ButtonEvent;
17
import com.extjs.gxt.ui.client.event.ButtonEvent;
21
import com.extjs.gxt.ui.client.event.ComponentEvent;
-
 
22
import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
18
import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
23
import com.extjs.gxt.ui.client.event.SelectionChangedListener;
19
import com.extjs.gxt.ui.client.event.SelectionChangedListener;
24
import com.extjs.gxt.ui.client.event.SelectionListener;
20
import com.extjs.gxt.ui.client.event.SelectionListener;
25
import com.extjs.gxt.ui.client.store.ListStore;
21
import com.extjs.gxt.ui.client.store.ListStore;
26
import com.extjs.gxt.ui.client.widget.ContentPanel;
22
import com.extjs.gxt.ui.client.widget.ContentPanel;
27
import com.extjs.gxt.ui.client.widget.Info;
23
import com.extjs.gxt.ui.client.widget.Info;
28
import com.extjs.gxt.ui.client.widget.LayoutContainer;
-
 
29
import com.extjs.gxt.ui.client.widget.button.Button;
24
import com.extjs.gxt.ui.client.widget.button.Button;
-
 
25
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
-
 
26
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
30
import com.extjs.gxt.ui.client.widget.form.LabelField;
27
import com.extjs.gxt.ui.client.widget.grid.Grid;
-
 
28
import com.extjs.gxt.ui.client.widget.grid.GridSelectionModel;
31
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
29
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
32
import com.extjs.gxt.ui.client.widget.layout.FormLayout;
-
 
33
import com.extjs.gxt.ui.client.widget.table.Table;
-
 
34
import com.extjs.gxt.ui.client.widget.table.TableColumn;
-
 
35
import com.extjs.gxt.ui.client.widget.table.TableColumnModel;
-
 
36
import com.extjs.gxt.ui.client.widget.table.TableItem;
-
 
37
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
30
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
38
import com.google.gwt.core.client.GWT;
31
import com.google.gwt.core.client.GWT;
39
import com.google.gwt.user.client.Window;
-
 
40
 
32
 
41
public class PersonneListeVue extends ContentPanel implements Rafraichissable {
33
public class PersonneListeVue extends ContentPanel implements Rafraichissable {
42
	
34
	
43
	private Mediateur mediateur = null ;
35
	private Mediateur mediateur = null ;
44
	private Table table = null;
-
 
45
	private ListStore<Personne> store = null;
-
 
-
 
36
	
46
	private TableBinder<Personne> binder = null;
37
	private Grid<Personne> grille = null;
47
	private Personne personneSelectionnee = null;
38
	private Personne personneSelectionnee = null;
48
	
39
	
49
	public PersonneListeVue() {
40
	public PersonneListeVue() {
50
		mediateur = Registry.get(RegistreId.MEDIATEUR);
41
		mediateur = Registry.get(RegistreId.MEDIATEUR);
51
		
42
		
52
		//Définition de la barre d'outil
43
		//Définition de la barre d'outil
53
		ToolBar toolBar = new ToolBar();
44
		ToolBar toolBar = new ToolBar();
54
		Button ajouter = new Button(mediateur.i18nC.ajouter());
45
		Button ajouter = new Button(mediateur.i18nC.ajouter());
55
		ajouter.setIconStyle(ComposantClass.ICONE_AJOUTER);
46
		ajouter.setIcon(Images.ICONES.ajouter());
56
		ajouter.addSelectionListener(new SelectionListener<ButtonEvent>() {  
47
		ajouter.addSelectionListener(new SelectionListener<ButtonEvent>() {  
57
			public void componentSelected(ButtonEvent ce) {  
48
			public void componentSelected(ButtonEvent ce) {  
58
				mediateur.clicAjouterPersonne();
49
				mediateur.clicAjouterPersonne();
59
			}  
50
			}  
60
		});
51
		});
61
		toolBar.add(ajouter);
52
		toolBar.add(ajouter);
62
		
-
 
63
		
-
 
64
		final Rafraichissable r = this ;
53
		final Rafraichissable r = this ;
65
 
-
 
66
		// TODO : ajouter btn mod & supp
54
 
67
		final Button modifier = new Button(mediateur.i18nC.modifier());
55
		final Button modifier = new Button(mediateur.i18nC.modifier());
68
		modifier.setIconStyle(ComposantClass.ICONE_MODIFIER);
56
		modifier.setIcon(Images.ICONES.formModifier());
69
		modifier.addSelectionListener(new SelectionListener<ButtonEvent>() {  
57
		modifier.addSelectionListener(new SelectionListener<ButtonEvent>() {  
70
			public void componentSelected(ButtonEvent ce) {  
58
			public void componentSelected(ButtonEvent ce) {  
71
				mediateur.clicModifierPersonne(personneSelectionnee);
59
				mediateur.clicModifierPersonne(personneSelectionnee);
72
			}  
60
			}  
73
		});
61
		});
74
		toolBar.add(modifier);
62
		toolBar.add(modifier);
75
		
63
		
76
		final Button supprimer = new Button(mediateur.i18nC.supprimer());
64
		final Button supprimer = new Button(mediateur.i18nC.supprimer());
77
		supprimer.addSelectionListener(new SelectionListener<ButtonEvent>() {  
65
		supprimer.addSelectionListener(new SelectionListener<ButtonEvent>() {  
78
			public void componentSelected(ButtonEvent ce) {  
66
			public void componentSelected(ButtonEvent ce) {  
79
			
-
 
80
				mediateur.clicSupprimerPersonne(r, binder.getSelection());
67
				mediateur.clicSupprimerPersonne(r, grille.getSelectionModel().getSelectedItems());
81
			}  
68
			}  
82
		});
69
		});
83
		
70
		
84
		supprimer.setIconStyle(ComposantClass.ICONE_SUPPRIMER);
71
		supprimer.setIcon(Images.ICONES.supprimer());
85
		toolBar.add(supprimer);
-
 
86
		
72
		toolBar.add(supprimer);
87
		setTopComponent(toolBar);
73
		setTopComponent(toolBar);
88
		
-
 
89
		List<TableColumn> columns = new ArrayList<TableColumn>();
-
 
90
		
-
 
91
		// ATTENTION : les noms des colonnes doivent correspondrent aux noms variables de la classe utilisée dans la liste
-
 
92
		columns.add(new TableColumn("fmt_nom_complet", mediateur.i18nC.personneNomComplet(), .30f));
-
 
93
		columns.add(new TableColumn("code_postal", mediateur.i18nC.personneCodePostal(), .10f));
-
 
94
		columns.add(new TableColumn("ville", mediateur.i18nC.personneVille(), .20f));
-
 
95
		columns.add(new TableColumn("courriel_princ", mediateur.i18nC.personneCourriel(), .25f));
-
 
96
		columns.add(new TableColumn("nom", mediateur.i18nC.personneNom(), .10f));
-
 
97
		columns.add(new TableColumn("prenom", mediateur.i18nC.personnePrenom(), .10f));
-
 
98
		
-
 
99
		columns.get(4).setHidden(true);
-
 
100
		columns.get(5).setHidden(true);
-
 
101
		
-
 
102
		TableColumnModel cm = new TableColumnModel(columns);
-
 
103
		
-
 
104
		table = new Table(cm);
-
 
105
		table.setSelectionMode(SelectionMode.MULTI);
-
 
106
		table.setBorders(false);
-
 
-
 
74
		
-
 
75
		List<ColumnConfig> lstColumns = new ArrayList<ColumnConfig>();
-
 
76
		
-
 
77
		// Définition des colomnes de la grille:
-
 
78
		ColumnConfig ccFmtNomComplet = new ColumnConfig();
-
 
79
		ccFmtNomComplet.setId("fmt_nom_complet");
-
 
80
		ccFmtNomComplet.setHeader("Nom Complet");
-
 
81
		ccFmtNomComplet.setWidth(200);
-
 
82
		lstColumns.add(ccFmtNomComplet);
-
 
83
		
-
 
84
		ColumnConfig ccCodePostal = new ColumnConfig();
-
 
85
		ccCodePostal.setId("code_postal");
-
 
86
		ccCodePostal.setHeader("Code postal");
-
 
87
		ccCodePostal.setWidth(100);
-
 
88
		lstColumns.add(ccCodePostal);
-
 
89
		
-
 
90
		ColumnConfig ccVille = new ColumnConfig();
107
		
91
		ccVille.setId("ville");
108
		table.setHorizontalScroll(true);
92
		ccVille.setHeader("Ville");
-
 
93
		ccVille.setWidth(100);
-
 
94
		lstColumns.add(ccVille);
109
		
95
		
-
 
96
		ColumnConfig ccCourriel = new ColumnConfig();
-
 
97
		ccCourriel.setId("courriel_princ");
-
 
98
		ccCourriel.setHeader("Courriel");
-
 
99
		ccCourriel.setWidth(200);
-
 
100
		lstColumns.add(ccCourriel);
-
 
101
		
-
 
102
		ColumnConfig ccNom = new ColumnConfig();
-
 
103
		ccNom.setId("nom");
-
 
104
		ccNom.setHeader("Nom");
110
		add(table);
105
		ccNom.setWidth(100);
111
 
106
		ccNom.setHidden(true);
-
 
107
		lstColumns.add(ccNom);
-
 
108
		
-
 
109
		ColumnConfig ccPrenom = new ColumnConfig();
112
		store = new ListStore<Personne>();
110
		ccPrenom.setId("prenom");
-
 
111
		ccPrenom.setHeader("Prénom");
-
 
112
		ccPrenom.setWidth(100);
-
 
113
		ccPrenom.setHidden(true);
113
 
114
		lstColumns.add(ccPrenom);
-
 
115
		
114
		binder = new TableBinder<Personne>(table, store);
116
		grille = new Grid<Personne>( new ListStore<Personne>(),new ColumnModel(lstColumns));
115
		binder.setAutoSelect(true);
117
		
116
		
118
		GridSelectionModel<Personne> gsmSelectionGrille = new GridSelectionModel<Personne>();
117
		binder.addSelectionChangedListener(new SelectionChangedListener<Personne>() {
119
		gsmSelectionGrille.addSelectionChangedListener(new SelectionChangedListener<Personne>() {
118
		public void selectionChanged(SelectionChangedEvent<Personne> event) {
120
						public void selectionChanged(SelectionChangedEvent<Personne> event) {
119
				Personne p = (Personne) event.getSelectedItem();
121
							Personne p = (Personne) event.getSelectedItem();
120
				personneSelectionnee = p;
122
							personneSelectionnee = p;
-
 
123
							clicListe(p);
-
 
124
						}
-
 
125
		});
-
 
126
		
121
				clicListe(p);
127
		grille.setSelectionModel(gsmSelectionGrille);
122
			}
128
		grille.setAutoExpandColumn("fmt_nom_complet");
123
		});
129
		
124
		
130
		add(grille);
125
		setLayout(new FitLayout());
131
		setLayout(new FitLayout());
126
	}
132
	}
127
 
133
 
128
	private void clicListe(Personne personne) {
134
	private void clicListe(Personne personne) {
129
		mediateur.clicListePersonne(personne);
135
		mediateur.clicListePersonne(personne);
130
	}
136
	}
131
 
137
 
132
	public void rafraichir(Object nouvellesDonnees) {
138
	public void rafraichir(Object nouvellesDonnees) {
133
		
139
		
134
		if (nouvellesDonnees instanceof PersonneListe) {
140
		if (nouvellesDonnees instanceof PersonneListe) {
135
			
141
			
136
			setHeading(mediateur.i18nC.personneListeLabel());
142
			setHeading(mediateur.i18nC.personneListeLabel());
137
			PersonneListe listePersonnes = (PersonneListe) nouvellesDonnees;
143
			PersonneListe listePersonnes = (PersonneListe) nouvellesDonnees;
138
			
144
			
139
			List<Personne> liste = new ArrayList<Personne>();
145
			List<Personne> liste = new ArrayList<Personne>();
140
			for (Iterator<String> it = listePersonnes.keySet().iterator(); it.hasNext();) {
146
			for (Iterator<String> it = listePersonnes.keySet().iterator(); it.hasNext();) {
141
				liste.add(listePersonnes.get(it.next()));
147
				liste.add(listePersonnes.get(it.next()));
142
			}
148
			}
-
 
149
			
143
			
150
			ListStore<Personne> store = grille.getStore();
144
			store.removeAll();
151
			store.removeAll();
145
			store.add(liste);
152
			store.add(liste);
146
			
153
			
147
			mediateur.actualiserPanneauCentral();
154
			mediateur.actualiserPanneauCentral();
148
			
155
			
149
			table.sort(0, SortDir.ASC);
156
			store.sort("fmt_nom_complet", SortDir.ASC);
150
			if (store.getCount() > 0) {
-
 
151
				//TODO : check below:
157
			if (store.getCount() > 0) {
152
				table.getSelectionModel().select(0, 1, true);
158
				grille.getSelectionModel().select(0, true);
153
			}
-
 
154
			
-
 
155
			
159
			}
156
			
160
			
157
		} else if (nouvellesDonnees instanceof Information)	{
161
		} else if (nouvellesDonnees instanceof Information)	{
158
			
162
			
159
			Information info = (Information) nouvellesDonnees;
163
			Information info = (Information) nouvellesDonnees;
160
			Info.display("Erreur", info.getMessages().toString());
-
 
161
			
-
 
162
			if (info.getType().equals("suppression_personne")) 	{
164
			if (info.getType().equals("suppression_personne")) 	{
-
 
165
				
-
 
166
				Info.display("Suppression de personne", info.getMessages().toString());	
163
			
167
			
-
 
168
					List<Personne> selectionPersonnes = grille.getSelectionModel().getSelectedItems();
164
					List<TableItem> selectionPersonnes = table.getSelectedItems();
169
					
165
					final int taille = selectionPersonnes.size();
170
					final int taille = selectionPersonnes.size();
166
					for (int i = 0; i < taille; i++) {
-
 
167
						//GWT.log("INDEX :"+table.indexOf(selectionStructure.get(i)), null);
171
					for (int i = 0; i < taille; i++) {
168
						table.remove(selectionPersonnes.get(i));
172
						grille.getStore().remove(selectionPersonnes.get(i));
-
 
173
					}
-
 
174
			} else	{
169
					}
175
				Info.display("Erreur", info.getMessages().toString());
170
			}
-
 
171
			
-
 
172
			
176
			}
173
			
177
			
174
		} else {
178
		} else {
175
			GWT.log(mediateur.messages.erreurRafraichir(nouvellesDonnees.getClass(), this.getClass()), null);
179
			GWT.log(mediateur.messages.erreurRafraichir(nouvellesDonnees.getClass(), this.getClass()), null);
176
		}
180
		}
177
		layout();
181
		layout();
178
	}
182
	}
179
}
183
}
180
 
184
 
181
 
185
 
182
 
186
 
183
 
187
 
184
 
188
 
185
 
189