Subversion Repositories eFlore/Applications.coel

Rev

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

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