Subversion Repositories eFlore/Applications.coel

Rev

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

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