Subversion Repositories eFlore/Applications.coel

Rev

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

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