Subversion Repositories eFlore/Applications.coel

Rev

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

Rev 156 Rev 210
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.Structure;
12
import org.tela_botanica.client.modeles.Structure;
13
import org.tela_botanica.client.modeles.StructureListe;
13
import org.tela_botanica.client.modeles.StructureListe;
14
import org.tela_botanica.client.modeles.Utilisateur;
14
import org.tela_botanica.client.modeles.Utilisateur;
15
 
15
 
16
import com.extjs.gxt.ui.client.Registry;
16
import com.extjs.gxt.ui.client.Registry;
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.layout.FitLayout;
27
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
27
import com.extjs.gxt.ui.client.widget.table.Table;
28
import com.extjs.gxt.ui.client.widget.table.Table;
28
import com.extjs.gxt.ui.client.widget.table.TableColumn;
29
import com.extjs.gxt.ui.client.widget.table.TableColumn;
29
import com.extjs.gxt.ui.client.widget.table.TableColumnModel;
30
import com.extjs.gxt.ui.client.widget.table.TableColumnModel;
30
import com.extjs.gxt.ui.client.widget.table.TableItem;
31
import com.extjs.gxt.ui.client.widget.table.TableItem;
31
import com.extjs.gxt.ui.client.widget.toolbar.TextToolItem;
32
import com.extjs.gxt.ui.client.widget.toolbar.TextToolItem;
32
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
33
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
33
import com.google.gwt.core.client.GWT;
34
import com.google.gwt.core.client.GWT;
34
import com.google.gwt.user.client.Window;
35
import com.google.gwt.user.client.Window;
35
 
36
 
36
public class StructureListePanneauVue extends ContentPanel implements Rafraichissable {
37
public class StructureListePanneauVue extends ContentPanel implements Rafraichissable {
37
	
38
	
38
	private Rafraichissable structureListePanneauVue = null ;
39
	private Rafraichissable structureListePanneauVue = null ;
39
	private Mediateur mediateur = null ;
40
	private Mediateur mediateur = null ;
40
	private Table table = null;
41
	private Table table = null;
41
	private ListStore<Structure> store = null;
42
	private ListStore<Structure> store = null;
42
	private TableBinder<Structure> binder = null;
43
	private TableBinder<Structure> binder = null;
43
	private TextToolItem modifier;
44
	private TextToolItem modifier;
44
	private TextToolItem supprimer;
45
	private TextToolItem supprimer;
45
	private TextToolItem ajouter;
46
	private TextToolItem ajouter;
46
 
47
 
47
	public StructureListePanneauVue() {
48
	public StructureListePanneauVue() {
48
		Utilisateur utilisateur = (Utilisateur) Registry.get(RegistreId.UTILISATEUR);
49
		Utilisateur utilisateur = (Utilisateur) Registry.get(RegistreId.UTILISATEUR);
49
		mediateur = Registry.get(RegistreId.MEDIATEUR);
50
		mediateur = Registry.get(RegistreId.MEDIATEUR);
50
		structureListePanneauVue = this;
51
		structureListePanneauVue = this;
51
		
52
		
52
		ToolBar toolBar = new ToolBar();
53
		ToolBar toolBar = new ToolBar();
53
		ajouter = new TextToolItem("Ajouter");
54
		ajouter = new TextToolItem("Ajouter");
54
		ajouter.setIconStyle(ComposantClass.ICONE_AJOUTER);
55
		ajouter.setIconStyle(ComposantClass.ICONE_AJOUTER);
55
		ajouter.addSelectionListener(new SelectionListener<ComponentEvent>() {  
56
		ajouter.addSelectionListener(new SelectionListener<ComponentEvent>() {  
56
			public void componentSelected(ComponentEvent ce) {  
57
			public void componentSelected(ComponentEvent ce) {  
57
				mediateur.clicAjouterStructure();
58
				mediateur.clicAjouterStructure();
58
			}
59
			}
59
		});
60
		});
60
		toolBar.add(ajouter);
61
		toolBar.add(ajouter);
61
 
62
 
62
		modifier = new TextToolItem("Modifier");
63
		modifier = new TextToolItem("Modifier");
63
		modifier.setIconStyle(ComposantClass.ICONE_MODIFIER);
64
		modifier.setIconStyle(ComposantClass.ICONE_MODIFIER);
64
		modifier.addSelectionListener(new SelectionListener<ComponentEvent>() {
65
		modifier.addSelectionListener(new SelectionListener<ComponentEvent>() {
65
			public void componentSelected(ComponentEvent ce) {
66
			public void componentSelected(ComponentEvent ce) {
66
				mediateur.clicModifierStructure(binder.getSelection());
67
				mediateur.clicModifierStructure(binder.getSelection());
67
			}
68
			}
68
		});
69
		});
69
		toolBar.add(modifier);
70
		toolBar.add(modifier);
70
		
71
		
71
		supprimer = new TextToolItem("Supprimer");
72
		supprimer = new TextToolItem("Supprimer");
72
		supprimer.setIconStyle(ComposantClass.ICONE_SUPPRIMER);
73
		supprimer.setIconStyle(ComposantClass.ICONE_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
				mediateur.clicSupprimerStructure(structureListePanneauVue, binder.getSelection());
76
				mediateur.clicSupprimerStructure(structureListePanneauVue, binder.getSelection());
76
			}
77
			}
77
		});
78
		});
78
		if (!utilisateur.isIdentifie()) {
79
		if (!utilisateur.isIdentifie()) {
79
			supprimer.disable();
80
			supprimer.disable();
80
		}
81
		}
81
		toolBar.add(supprimer);
82
		toolBar.add(supprimer);
82
 
83
 
83
		setTopComponent(toolBar);
84
		setTopComponent(toolBar);
84
 
85
 
85
		List<TableColumn> columns = new ArrayList<TableColumn>();
86
		List<TableColumn> columns = new ArrayList<TableColumn>();
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("ville", "Ville", .3f));
88
		columns.add(new TableColumn("ville", "Ville", .3f));
88
		columns.add(new TableColumn("nom", "Nom", .7f));
89
		columns.add(new TableColumn("nom", "Nom", .7f));
89
		
90
		
90
		TableColumnModel cm = new TableColumnModel(columns);
91
		TableColumnModel cm = new TableColumnModel(columns);
91
 
-
 
92
		table = new Table(cm);
92
		table = new Table(cm);
93
		table.setSelectionMode(SelectionMode.MULTI);
93
		table.setSelectionMode(SelectionMode.MULTI);
94
		table.setBorders(false);
94
		table.setBorders(false);
95
 
-
 
-
 
95
		table.setStripeRows(true);
96
		add(table);
96
		add(table);
-
 
97
		
97
 
98
		
-
 
99
		store = new ListStore<Structure>();
98
		store = new ListStore<Structure>();
100
		store.sort("ville", SortDir.ASC);
99
 
101
		
100
		binder = new TableBinder<Structure>(table, store);
102
		binder = new TableBinder<Structure>(table, store);
101
		binder.setAutoSelect(true);
103
		binder.setAutoSelect(true);
102
		binder.addSelectionChangedListener(new SelectionChangedListener<Structure>() {
104
		binder.addSelectionChangedListener(new SelectionChangedListener<Structure>() {
103
			public void selectionChanged(SelectionChangedEvent<Structure> event) {
105
			public void selectionChanged(SelectionChangedEvent<Structure> event) {
104
				Structure m = (Structure) event.getSelectedItem();
106
				Structure m = (Structure) event.getSelectedItem();
105
				clicListe(m);
107
				clicListe(m);
106
			}
108
			}
107
		});
109
		});
108
 
110
 
109
		setLayout(new FitLayout());
111
		setLayout(new FitLayout());
110
	}
112
	}
111
 
113
 
112
	public ListStore<Structure> getStore() {
114
	public ListStore<Structure> getStore() {
113
		return store;
115
		return store;
114
	}
116
	}
115
 
117
 
116
	public TableBinder<Structure> getBinder() {
118
	public TableBinder<Structure> getBinder() {
117
		return binder;
119
		return binder;
118
	}
120
	}
119
 
121
 
120
	private void clicListe(Structure institution) {
122
	private void clicListe(Structure institution) {
121
		mediateur.clicListeInstitution(institution);
123
		mediateur.clicListeInstitution(institution);
122
	}
124
	}
123
 
125
 
124
	public void rafraichir(Object nouvelleDonnees) {
126
	public void rafraichir(Object nouvelleDonnees) {
125
		if (nouvelleDonnees instanceof StructureListe) {
127
		if (nouvelleDonnees instanceof StructureListe) {
126
			StructureListe listeInstitutions = (StructureListe) nouvelleDonnees;
128
			StructureListe listeInstitutions = (StructureListe) nouvelleDonnees;
127
			setHeading("Institutions");
129
			setHeading("Institutions");
128
 
130
 
129
			List<Structure> liste = new ArrayList<Structure>();
131
			List<Structure> liste = new ArrayList<Structure>();
130
			for (Iterator<String> it = listeInstitutions.keySet().iterator(); it.hasNext();) {
132
			for (Iterator<String> it = listeInstitutions.keySet().iterator(); it.hasNext();) {
131
				liste.add(listeInstitutions.get(it.next()));
133
				liste.add(listeInstitutions.get(it.next()));
132
			}
134
			}
133
			
135
			
134
			store.removeAll();
136
			store.removeAll();
135
			store.add((List<Structure>) liste);
137
			store.add((List<Structure>) liste);
136
			
138
			
137
			// Test pour savoir si la liste contient des éléments
139
			// Test pour savoir si la liste contient des éléments
138
			if (listeInstitutions.size() > 0) {
140
			if (listeInstitutions.size() > 0) {
139
				binder.setSelection((Structure) listeInstitutions.get(0));
141
				binder.setSelection((Structure) listeInstitutions.get(0));
140
			}
142
			}
-
 
143
			
141
		} else if (nouvelleDonnees instanceof Information) {
144
		} else if (nouvelleDonnees instanceof Information) {
142
			Information info = (Information) nouvelleDonnees;
145
			Information info = (Information) nouvelleDonnees;
143
			if (info.getType().equals("suppression_structure")) {
146
			if (info.getType().equals("suppression_structure")) {
144
				// Affichage d'un message d'information 
147
				// Affichage d'un message d'information 
145
				//GWT.log(info.toString(), null);
148
				//GWT.log(info.toString(), null);
146
				Info.display("Suppression d'une Institution", info.toString().replaceAll("\n", "<br />"));
149
				Info.display("Suppression d'une Institution", info.toString().replaceAll("\n", "<br />"));
147
 
150
 
148
				// Suppression des structures sélectionnées
151
				// Suppression des structures sélectionnées
149
				List<TableItem> selectionStructure = table.getSelectedItems();
152
				List<TableItem> selectionStructure = table.getSelectedItems();
150
				final int taille = selectionStructure.size();
153
				final int taille = selectionStructure.size();
151
				for (int i = 0; i < taille; i++) {
154
				for (int i = 0; i < taille; i++) {
152
					//GWT.log("INDEX :"+table.indexOf(selectionStructure.get(i)), null);
155
					//GWT.log("INDEX :"+table.indexOf(selectionStructure.get(i)), null);
153
					table.remove(selectionStructure.get(i));
156
					table.remove(selectionStructure.get(i));
154
				}
157
				}
155
				
158
				
156
				// Désactivation des boutons si la liste est vide
159
				// Désactivation des boutons si la liste est vide
157
				if (table.getItemCount() == 0) {  
160
				if (table.getItemCount() == 0) {  
158
					supprimer.disable();
161
					supprimer.disable();
159
					modifier.disable();
162
					modifier.disable();
160
				}
163
				}
161
			} else if (info.getType().equals("maj_utilisateur")) {
164
			} else if (info.getType().equals("maj_utilisateur")) {
162
				if (((Utilisateur) Registry.get(RegistreId.UTILISATEUR)).isIdentifie()) {
165
				if (((Utilisateur) Registry.get(RegistreId.UTILISATEUR)).isIdentifie()) {
163
					if (table.getItemCount() != 0) {
166
					if (table.getItemCount() != 0) {
164
						supprimer.enable();
167
						supprimer.enable();
165
					}
168
					}
166
				} else {
169
				} else {
167
					supprimer.disable();
170
					supprimer.disable();
168
				}
171
				}
169
			}
172
			}
170
		} else {
173
		} else {
171
			GWT.log("Ce type d'objet n'est pas pris en compte par la méthode rafraichir de la classe EntetePanneauVue", null);
174
			GWT.log("Ce type d'objet n'est pas pris en compte par la méthode rafraichir de la classe EntetePanneauVue", null);
172
		}
175
		}
173
		layout();
176
		layout();
174
	}
177
	}
175
}
178
}