Subversion Repositories eFlore/Applications.coel

Rev

Rev 658 | Rev 662 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
127 gduche 1
package org.tela_botanica.client.vues;
2
 
3
import java.util.ArrayList;
4
import java.util.List;
5
 
6
import org.tela_botanica.client.Mediateur;
7
import org.tela_botanica.client.RegistreId;
512 gduche 8
import org.tela_botanica.client.images.Images;
596 gduche 9
import org.tela_botanica.client.interfaces.ListePaginable;
127 gduche 10
import org.tela_botanica.client.interfaces.Rafraichissable;
353 gduche 11
import org.tela_botanica.client.modeles.Information;
127 gduche 12
import org.tela_botanica.client.modeles.Personne;
13
import org.tela_botanica.client.modeles.PersonneListe;
617 gduche 14
import org.tela_botanica.client.modeles.Utilisateur;
15
 
127 gduche 16
import com.extjs.gxt.ui.client.Registry;
377 gduche 17
import com.extjs.gxt.ui.client.Style.SortDir;
562 gduche 18
import com.extjs.gxt.ui.client.data.BasePagingLoader;
19
import com.extjs.gxt.ui.client.data.ModelData;
20
import com.extjs.gxt.ui.client.data.PagingLoadResult;
21
import com.extjs.gxt.ui.client.data.PagingLoader;
22
import com.extjs.gxt.ui.client.data.PagingModelMemoryProxy;
566 jp_milcent 23
import com.extjs.gxt.ui.client.event.BaseEvent;
489 gduche 24
import com.extjs.gxt.ui.client.event.ButtonEvent;
566 jp_milcent 25
import com.extjs.gxt.ui.client.event.Events;
26
import com.extjs.gxt.ui.client.event.Listener;
127 gduche 27
import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
28
import com.extjs.gxt.ui.client.event.SelectionChangedListener;
29
import com.extjs.gxt.ui.client.event.SelectionListener;
30
import com.extjs.gxt.ui.client.store.ListStore;
31
import com.extjs.gxt.ui.client.widget.ContentPanel;
353 gduche 32
import com.extjs.gxt.ui.client.widget.Info;
489 gduche 33
import com.extjs.gxt.ui.client.widget.button.Button;
512 gduche 34
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
35
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
36
import com.extjs.gxt.ui.client.widget.grid.Grid;
37
import com.extjs.gxt.ui.client.widget.grid.GridSelectionModel;
127 gduche 38
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
562 gduche 39
import com.extjs.gxt.ui.client.widget.toolbar.PagingToolBar;
127 gduche 40
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
278 jp_milcent 41
import com.google.gwt.core.client.GWT;
562 gduche 42
import com.google.gwt.i18n.client.Dictionary;
127 gduche 43
 
436 gduche 44
public class PersonneListeVue extends ContentPanel implements Rafraichissable {
127 gduche 45
 
278 jp_milcent 46
	private Mediateur mediateur = null ;
512 gduche 47
 
48
	private Grid<Personne> grille = null;
287 gduche 49
	private Personne personneSelectionnee = null;
596 gduche 50
	private BarrePaginationVue pagination;
563 gduche 51
	private ColumnModel modeleColonnes;
562 gduche 52
	private final int nbElementsPage = Integer.valueOf(((Dictionary) Dictionary.getDictionary("configuration")).get("nbElementsPage"));
617 gduche 53
	private final Button supprimer;
258 gduche 54
 
436 gduche 55
	public PersonneListeVue() {
278 jp_milcent 56
		mediateur = Registry.get(RegistreId.MEDIATEUR);
127 gduche 57
 
566 jp_milcent 58
		setHeading(mediateur.i18nC.personneListeLabel());
59
		setLayout(new FitLayout());
562 gduche 60
 
127 gduche 61
		//Définition de la barre d'outil
62
		ToolBar toolBar = new ToolBar();
489 gduche 63
		Button ajouter = new Button(mediateur.i18nC.ajouter());
512 gduche 64
		ajouter.setIcon(Images.ICONES.ajouter());
489 gduche 65
		ajouter.addSelectionListener(new SelectionListener<ButtonEvent>() {
66
			public void componentSelected(ButtonEvent ce) {
278 jp_milcent 67
				mediateur.clicAjouterPersonne();
127 gduche 68
			}
69
		});
70
		toolBar.add(ajouter);
217 aurelien 71
		final Rafraichissable r = this ;
127 gduche 72
 
489 gduche 73
		final Button modifier = new Button(mediateur.i18nC.modifier());
512 gduche 74
		modifier.setIcon(Images.ICONES.formModifier());
489 gduche 75
		modifier.addSelectionListener(new SelectionListener<ButtonEvent>() {
76
			public void componentSelected(ButtonEvent ce) {
661 gduche 77
 
78
				int tailleSelection = grille.getSelectionModel().getSelectedItems().size();
79
				if ( tailleSelection == 0)	{
80
					Info.display("Information", "Veuillez sélectionner une personne.");
81
				}	else if (tailleSelection > 1) {
82
					Info.display("Information", "Veuillez sélectionner une seule personne à la fois.");
83
				} else {
84
					mediateur.clicModifierPersonne(personneSelectionnee);
85
				}
217 aurelien 86
			}
87
		});
127 gduche 88
		toolBar.add(modifier);
89
 
617 gduche 90
		supprimer = new Button(mediateur.i18nC.supprimer());
489 gduche 91
		supprimer.addSelectionListener(new SelectionListener<ButtonEvent>() {
92
			public void componentSelected(ButtonEvent ce) {
512 gduche 93
				mediateur.clicSupprimerPersonne(r, grille.getSelectionModel().getSelectedItems());
217 aurelien 94
			}
95
		});
512 gduche 96
		supprimer.setIcon(Images.ICONES.supprimer());
127 gduche 97
		toolBar.add(supprimer);
617 gduche 98
 
99
		gererEtatActivationBouton();
566 jp_milcent 100
 
127 gduche 101
		setTopComponent(toolBar);
566 jp_milcent 102
 
103
		// Définition des colomnes de la grille:
512 gduche 104
		List<ColumnConfig> lstColumns = new ArrayList<ColumnConfig>();
566 jp_milcent 105
		ColumnConfig ccId = new ColumnConfig("id_personne", "Id", 45);
541 gduche 106
		lstColumns.add(ccId);
566 jp_milcent 107
		ColumnConfig ccFmtNomComplet = new ColumnConfig("fmt_nom_complet", "Nom Complet", 200);
512 gduche 108
		lstColumns.add(ccFmtNomComplet);
566 jp_milcent 109
		ColumnConfig ccCodePostal = new ColumnConfig("code_postal", "Code postal", 100);
512 gduche 110
		lstColumns.add(ccCodePostal);
566 jp_milcent 111
		ColumnConfig ccVille = new ColumnConfig("ville", "Ville", 100);
512 gduche 112
		lstColumns.add(ccVille);
566 jp_milcent 113
		ColumnConfig ccCourriel = new ColumnConfig("courriel_princ", "Courriel", 200);
512 gduche 114
		lstColumns.add(ccCourriel);
566 jp_milcent 115
		ColumnConfig ccNom = new ColumnConfig("nom", "Nom", 100);
512 gduche 116
		ccNom.setHidden(true);
117
		lstColumns.add(ccNom);
566 jp_milcent 118
		ColumnConfig ccPrenom = new ColumnConfig("prenom", "Prénom", 100);
512 gduche 119
		ccPrenom.setHidden(true);
120
		lstColumns.add(ccPrenom);
563 gduche 121
		modeleColonnes = new ColumnModel(lstColumns);
566 jp_milcent 122
 
123
		// Définition de la grille
512 gduche 124
		GridSelectionModel<Personne> gsmSelectionGrille = new GridSelectionModel<Personne>();
125
		gsmSelectionGrille.addSelectionChangedListener(new SelectionChangedListener<Personne>() {
520 gduche 126
			public void selectionChanged(SelectionChangedEvent<Personne> event) {
127
				Personne p = (Personne) event.getSelectedItem();
128
				personneSelectionnee = p;
129
				clicListe(p);
130
			}
150 gduche 131
		});
287 gduche 132
 
566 jp_milcent 133
		grille = new Grid<Personne>( new ListStore<Personne>(), modeleColonnes);
512 gduche 134
		grille.setSelectionModel(gsmSelectionGrille);
566 jp_milcent 135
		grille.setWidth("100%");
512 gduche 136
		grille.setAutoExpandColumn("fmt_nom_complet");
566 jp_milcent 137
		grille.getView().setAutoFill(true);
138
		grille.getView().setForceFit(true);
139
		grille.addListener(Events.ViewReady, new Listener<BaseEvent>() {
140
			@Override
141
			public void handleEvent(BaseEvent be) {
624 gduche 142
				grille.getStore().sort("fmt_nom_complet", SortDir.ASC);
566 jp_milcent 143
				grille.getSelectionModel().select(0, false);
144
			}
145
		});
562 gduche 146
		add(grille);
512 gduche 147
 
566 jp_milcent 148
		// Définition de la barre de pagination
596 gduche 149
		pagination = new BarrePaginationVue(new PersonneListe(), mediateur);
562 gduche 150
		setBottomComponent(pagination);
127 gduche 151
	}
152
 
150 gduche 153
	private void clicListe(Personne personne) {
278 jp_milcent 154
		mediateur.clicListePersonne(personne);
127 gduche 155
	}
156
 
617 gduche 157
	private void gererEtatActivationBouton()	{
158
 
159
		if (((Utilisateur) Registry.get(RegistreId.UTILISATEUR_COURANT)).isIdentifie() == false)	{
160
			supprimer.setEnabled(false);
161
		} else	{
162
 
163
			supprimer.setEnabled(true);
164
		}
165
 
166
	}
167
 
353 gduche 168
	public void rafraichir(Object nouvellesDonnees) {
169
		if (nouvellesDonnees instanceof PersonneListe) {
596 gduche 170
 
353 gduche 171
			PersonneListe listePersonnes = (PersonneListe) nouvellesDonnees;
127 gduche 172
 
596 gduche 173
			pagination.setlistePaginable(listePersonnes);
174
			pagination.rafraichir(listePersonnes.getPageTable());
175
 
567 jp_milcent 176
			if (listePersonnes != null) {
177
				List<Personne> liste = (List<Personne>) listePersonnes.toList();
178
 
596 gduche 179
				ListStore<Personne> store = new ListStore<Personne>();
180
				store.add(liste);
567 jp_milcent 181
				grille.reconfigure(store, modeleColonnes);
182
 
183
				mediateur.actualiserPanneauCentral();
649 gduche 184
				grille.fireEvent(Events.ViewReady);
596 gduche 185
 
567 jp_milcent 186
			}
417 gduche 187
		} else if (nouvellesDonnees instanceof Information)	{
617 gduche 188
 
417 gduche 189
			Information info = (Information) nouvellesDonnees;
190
			if (info.getType().equals("suppression_personne")) 	{
512 gduche 191
				Info.display("Suppression de personne", info.getMessages().toString());
566 jp_milcent 192
				List<Personne> selectionPersonnes = grille.getSelectionModel().getSelectedItems();
193
				final int taille = selectionPersonnes.size();
194
				for (int i = 0; i < taille; i++) {
195
					grille.getStore().remove(selectionPersonnes.get(i));
196
				}
658 gduche 197
 
198
				//Rechargement de la liste
199
				pagination.getlistePaginable().recharger();
200
 
617 gduche 201
			} else if (info.getType().equals("maj_utilisateur"))	{
202
				gererEtatActivationBouton();
203
			} else {
512 gduche 204
				Info.display("Erreur", info.getMessages().toString());
361 jp_milcent 205
			}
206
		} else {
533 jp_milcent 207
			GWT.log(mediateur.i18nM.erreurRafraichir(nouvellesDonnees.getClass(), this.getClass()), null);
127 gduche 208
		}
596 gduche 209
 
210
 
211
 
278 jp_milcent 212
		layout();
127 gduche 213
	}
214
}
189 gduche 215
 
216
 
217
 
218
 
219
 
220