Subversion Repositories eFlore/Applications.coel

Rev

Rev 453 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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