Subversion Repositories eFlore/Applications.coel

Rev

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

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