Subversion Repositories eFlore/Applications.coel

Rev

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

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