Subversion Repositories eFlore/Applications.coel

Rev

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

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