Subversion Repositories eFlore/Applications.coel

Rev

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

Rev 684 Rev 703
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.Mediateur;
6
import org.tela_botanica.client.Mediateur;
7
import org.tela_botanica.client.RegistreId;
7
import org.tela_botanica.client.RegistreId;
8
import org.tela_botanica.client.i18n.Constantes;
8
import org.tela_botanica.client.i18n.Constantes;
9
import org.tela_botanica.client.images.Images;
9
import org.tela_botanica.client.images.Images;
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.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.SortDir;
17
import com.extjs.gxt.ui.client.Style.SortDir;
18
import com.extjs.gxt.ui.client.event.BaseEvent;
18
import com.extjs.gxt.ui.client.event.BaseEvent;
19
import com.extjs.gxt.ui.client.event.ButtonEvent;
19
import com.extjs.gxt.ui.client.event.ButtonEvent;
20
import com.extjs.gxt.ui.client.event.Events;
20
import com.extjs.gxt.ui.client.event.Events;
21
import com.extjs.gxt.ui.client.event.Listener;
21
import com.extjs.gxt.ui.client.event.Listener;
22
import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
22
import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
23
import com.extjs.gxt.ui.client.event.SelectionChangedListener;
23
import com.extjs.gxt.ui.client.event.SelectionChangedListener;
24
import com.extjs.gxt.ui.client.event.SelectionListener;
24
import com.extjs.gxt.ui.client.event.SelectionListener;
25
import com.extjs.gxt.ui.client.store.ListStore;
25
import com.extjs.gxt.ui.client.store.ListStore;
26
import com.extjs.gxt.ui.client.widget.ContentPanel;
26
import com.extjs.gxt.ui.client.widget.ContentPanel;
27
import com.extjs.gxt.ui.client.widget.Info;
27
import com.extjs.gxt.ui.client.widget.Info;
28
import com.extjs.gxt.ui.client.widget.button.Button;
28
import com.extjs.gxt.ui.client.widget.button.Button;
29
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
29
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
30
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
30
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
31
import com.extjs.gxt.ui.client.widget.grid.Grid;
31
import com.extjs.gxt.ui.client.widget.grid.Grid;
32
import com.extjs.gxt.ui.client.widget.grid.GridSelectionModel;
32
import com.extjs.gxt.ui.client.widget.grid.GridSelectionModel;
33
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
33
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
34
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
34
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
35
import com.google.gwt.core.client.GWT;
35
import com.google.gwt.core.client.GWT;
36
 
36
 
37
public class CollectionListeVue extends ContentPanel implements Rafraichissable {
37
public class CollectionListeVue extends ContentPanel implements Rafraichissable {
38
	
38
	
39
	private Mediateur mediateur = null;
39
	private Mediateur mediateur = null;
40
	private Constantes i18nC = null;
40
	private Constantes i18nC = null;
41
 
41
 
42
	private Grid<Collection> grille = null;
42
	private Grid<Collection> grille = null;
43
	private ListStore<Collection> store = null;
43
	private ListStore<Collection> store = null;
44
 
44
 
45
	private Button modifier;
45
	private Button modifier;
46
	private Button supprimer;
46
	private Button supprimer;
47
	private Button ajouter;
47
	private Button ajouter;
48
 
48
 
49
	public CollectionListeVue(Mediateur mediateurCourant) {
49
	public CollectionListeVue(Mediateur mediateurCourant) {
50
		mediateur = mediateurCourant;
50
		mediateur = mediateurCourant;
51
		i18nC = mediateur.i18nC;
51
		i18nC = mediateur.i18nC;
52
		
52
		
53
		setLayout(new FitLayout());
53
		setLayout(new FitLayout());
54
		setHeading(i18nC.collectionListeTitre());
54
		setHeading(i18nC.collectionListeTitre());
55
		
55
		
56
		ToolBar toolBar = new ToolBar();
56
		ToolBar toolBar = new ToolBar();
57
		ajouter = new Button(i18nC.ajouter());
57
		ajouter = new Button(i18nC.ajouter());
58
		ajouter.setIcon(Images.ICONES.ajouter());
58
		ajouter.setIcon(Images.ICONES.ajouter());
59
		ajouter.addSelectionListener(new SelectionListener<ButtonEvent>() {  
59
		ajouter.addSelectionListener(new SelectionListener<ButtonEvent>() {  
60
			public void componentSelected(ButtonEvent ce) {  
60
			public void componentSelected(ButtonEvent ce) {  
61
				mediateur.clicAjouterCollection();
61
				mediateur.clicAjouterCollection();
62
			}
62
			}
63
		});
63
		});
64
		toolBar.add(ajouter);
64
		toolBar.add(ajouter);
65
 
65
 
66
		modifier = new Button(i18nC.modifier());
66
		modifier = new Button(i18nC.modifier());
67
		modifier.setIcon(Images.ICONES.formModifier());
67
		modifier.setIcon(Images.ICONES.formModifier());
68
		modifier.addSelectionListener(new SelectionListener<ButtonEvent>() {
68
		modifier.addSelectionListener(new SelectionListener<ButtonEvent>() {
69
			public void componentSelected(ButtonEvent ce) {
69
			public void componentSelected(ButtonEvent ce) {
70
				mediateur.clicModifierCollection(grille.getSelectionModel().getSelectedItems());
70
				mediateur.clicModifierCollection(grille.getSelectionModel().getSelectedItems());
71
			}
71
			}
72
		});
72
		});
73
		toolBar.add(modifier);
73
		toolBar.add(modifier);
74
		
74
		
75
		supprimer = new Button(i18nC.supprimer());
75
		supprimer = new Button(i18nC.supprimer());
76
		supprimer.setIcon(Images.ICONES.supprimer());
76
		supprimer.setIcon(Images.ICONES.supprimer());
77
		supprimer.addSelectionListener(new SelectionListener<ButtonEvent>() {
77
		supprimer.addSelectionListener(new SelectionListener<ButtonEvent>() {
78
			public void componentSelected(ButtonEvent ce) {
78
			public void componentSelected(ButtonEvent ce) {
79
				clicSupprimerCollection(grille.getSelectionModel().getSelectedItems());
79
				clicSupprimerCollection(grille.getSelectionModel().getSelectedItems());
80
			}
80
			}
81
		});
81
		});
82
		toolBar.add(supprimer);
82
		toolBar.add(supprimer);
83
 
83
 
84
		setTopComponent(toolBar);
84
		setTopComponent(toolBar);
85
 
85
 
86
		List<ColumnConfig> colonnes = new ArrayList<ColumnConfig>();
86
		List<ColumnConfig> colonnes = new ArrayList<ColumnConfig>();
87
		colonnes.add(new ColumnConfig("nom", i18nC.nom(), 300));
87
		colonnes.add(new ColumnConfig("nom", i18nC.personneNom(), 300));
88
		colonnes.add(new ColumnConfig("structure_nom", i18nC.structure(), 200));
88
		colonnes.add(new ColumnConfig("structure_nom", i18nC.structure(), 200));
89
		colonnes.add(new ColumnConfig("structure_ville", i18nC.ville(), 150));
89
		colonnes.add(new ColumnConfig("structure_ville", i18nC.ville(), 150));
90
		colonnes.get(1).setHidden(true);
90
		colonnes.get(1).setHidden(true);
91
		ColumnModel modeleDeColonne = new ColumnModel(colonnes);
91
		ColumnModel modeleDeColonne = new ColumnModel(colonnes);
92
		
92
		
93
		GridSelectionModel<Collection> modeleDeSelection = new GridSelectionModel<Collection>();
93
		GridSelectionModel<Collection> modeleDeSelection = new GridSelectionModel<Collection>();
94
		modeleDeSelection.addSelectionChangedListener(new SelectionChangedListener<Collection>() {
94
		modeleDeSelection.addSelectionChangedListener(new SelectionChangedListener<Collection>() {
95
			public void selectionChanged(SelectionChangedEvent<Collection> event) {
95
			public void selectionChanged(SelectionChangedEvent<Collection> event) {
96
				Collection collectionSelectionnee = (Collection) event.getSelectedItem();
96
				Collection collectionSelectionnee = (Collection) event.getSelectedItem();
97
				clicListe(collectionSelectionnee);
97
				clicListe(collectionSelectionnee);
98
			}
98
			}
99
		});
99
		});
100
		
100
		
101
		store = new ListStore<Collection>();
101
		store = new ListStore<Collection>();
102
		store.sort("nom", SortDir.ASC);
102
		store.sort("nom", SortDir.ASC);
103
		
103
		
104
		grille = new Grid<Collection>(store, modeleDeColonne);
104
		grille = new Grid<Collection>(store, modeleDeColonne);
105
		grille.setWidth("100%");
105
		grille.setWidth("100%");
106
		grille.setAutoExpandColumn("nom");
106
		grille.setAutoExpandColumn("nom");
107
		grille.getView().setAutoFill(true);
107
		grille.getView().setAutoFill(true);
108
		grille.getView().setForceFit(true);
108
		grille.getView().setForceFit(true);
109
		grille.setSelectionModel(modeleDeSelection);
109
		grille.setSelectionModel(modeleDeSelection);
110
		grille.addListener(Events.ViewReady, new Listener<BaseEvent>() {
110
		grille.addListener(Events.ViewReady, new Listener<BaseEvent>() {
111
			@Override
111
			@Override
112
			public void handleEvent(BaseEvent be) {
112
			public void handleEvent(BaseEvent be) {
113
				grille.getSelectionModel().select(0, false);
113
				grille.getSelectionModel().select(0, false);
114
			}
114
			}
115
		});
115
		});
116
		grille.addListener(Events.OnDoubleClick, new Listener<BaseEvent>() {
116
		grille.addListener(Events.OnDoubleClick, new Listener<BaseEvent>() {
117
			@Override
117
			@Override
118
			public void handleEvent(BaseEvent be) {
118
			public void handleEvent(BaseEvent be) {
119
				modifier.fireEvent(Events.Select);
119
				modifier.fireEvent(Events.Select);
120
			}
120
			}
121
		});
121
		});
122
		add(grille);
122
		add(grille);
123
	}
123
	}
124
 
124
 
125
	private void clicListe(Collection m) {
125
	private void clicListe(Collection m) {
126
		if (store.getCount() > 0) {
126
		if (store.getCount() > 0) {
127
			mediateur.clicListeCollection(m);
127
			mediateur.clicListeCollection(m);
128
		}
128
		}
129
	}
129
	}
130
	
130
	
131
	private void clicSupprimerCollection(List<Collection> collectionsASupprimer) {
131
	private void clicSupprimerCollection(List<Collection> collectionsASupprimer) {
132
		if (store.getCount() > 0) {
132
		if (store.getCount() > 0) {
133
			mediateur.clicSupprimerCollection(this, collectionsASupprimer);
133
			mediateur.clicSupprimerCollection(this, collectionsASupprimer);
134
		}
134
		}
135
	}
135
	}
136
	
136
	
137
	private void gererEtatActivationBouton() {
137
	private void gererEtatActivationBouton() {
138
		int nbreElementDuMagazin = store.getCount();
138
		int nbreElementDuMagazin = store.getCount();
139
		if (nbreElementDuMagazin == 0) {
139
		if (nbreElementDuMagazin == 0) {
140
			supprimer.disable();
140
			supprimer.disable();
141
			modifier.disable();
141
			modifier.disable();
142
		} else if (nbreElementDuMagazin > 0) {
142
		} else if (nbreElementDuMagazin > 0) {
143
			modifier.enable();
143
			modifier.enable();
144
			if (((Utilisateur) Registry.get(RegistreId.UTILISATEUR_COURANT)).isIdentifie()) {
144
			if (((Utilisateur) Registry.get(RegistreId.UTILISATEUR_COURANT)).isIdentifie()) {
145
				supprimer.enable();
145
				supprimer.enable();
146
			}
146
			}
147
		}
147
		}
148
	}
148
	}
149
 
149
 
150
	public void rafraichir(Object nouvelleDonnees) {
150
	public void rafraichir(Object nouvelleDonnees) {
151
		if (nouvelleDonnees instanceof CollectionListe) {
151
		if (nouvelleDonnees instanceof CollectionListe) {
152
			CollectionListe collections = (CollectionListe) nouvelleDonnees;
152
			CollectionListe collections = (CollectionListe) nouvelleDonnees;
153
 
153
 
154
			if (collections != null) {			
154
			if (collections != null) {			
155
				List<Collection> liste = collections.toList();
155
				List<Collection> liste = collections.toList();
156
				store.removeAll();
156
				store.removeAll();
157
				store.add(liste);
157
				store.add(liste);
158
	
158
	
159
				mediateur.actualiserPanneauCentral();
159
				mediateur.actualiserPanneauCentral();
160
			}
160
			}
161
		} else if (nouvelleDonnees instanceof Information) {
161
		} else if (nouvelleDonnees instanceof Information) {
162
			Information info = (Information) nouvelleDonnees;
162
			Information info = (Information) nouvelleDonnees;
163
			if (info.getType().equals("suppression_collection")) {
163
			if (info.getType().equals("suppression_collection")) {
164
				// Affichage d'un message d'information 
164
				// Affichage d'un message d'information 
165
				Info.display(i18nC.suppressionCollection(), info.toString().replaceAll("\n", "<br />"));
165
				Info.display(i18nC.suppressionCollection(), info.toString().replaceAll("\n", "<br />"));
166
 
166
 
167
				// Suppression des structures sélectionnées
167
				// Suppression des structures sélectionnées
168
				List<Collection> selectionCollection = grille.getSelectionModel().getSelectedItems();
168
				List<Collection> selectionCollection = grille.getSelectionModel().getSelectedItems();
169
				final int taille = selectionCollection.size();
169
				final int taille = selectionCollection.size();
170
				for (int i = 0; i < taille; i++) {
170
				for (int i = 0; i < taille; i++) {
171
					//GWT.log("INDEX :"+table.indexOf(selectionStructure.get(i)), null);
171
					//GWT.log("INDEX :"+table.indexOf(selectionStructure.get(i)), null);
172
					store.remove(selectionCollection.get(i));
172
					store.remove(selectionCollection.get(i));
173
				}
173
				}
174
				
174
				
175
				gererEtatActivationBouton();
175
				gererEtatActivationBouton();
176
			} else if (info.getType().equals("maj_utilisateur")) {
176
			} else if (info.getType().equals("maj_utilisateur")) {
177
				gererEtatActivationBouton();
177
				gererEtatActivationBouton();
178
			}
178
			}
179
		} else {
179
		} else {
180
			GWT.log("Pas de correspondance dans la méthode rafraichir() de la classe "+this.getClass(), null);
180
			GWT.log("Pas de correspondance dans la méthode rafraichir() de la classe "+this.getClass(), null);
181
		}
181
		}
182
		layout();
182
		layout();
183
	}
183
	}
184
}
184
}