Subversion Repositories eFlore/Applications.coel

Rev

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

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