Subversion Repositories eFlore/Applications.coel

Rev

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