Subversion Repositories eFlore/Applications.coel

Rev

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

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