Subversion Repositories eFlore/Applications.coel

Rev

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

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