Subversion Repositories eFlore/Applications.coel

Rev

Rev 596 | Rev 623 | 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) {
287 gduche 77
				mediateur.clicModifierPersonne(personneSelectionnee);
217 aurelien 78
			}
79
		});
127 gduche 80
		toolBar.add(modifier);
81
 
617 gduche 82
		supprimer = new Button(mediateur.i18nC.supprimer());
489 gduche 83
		supprimer.addSelectionListener(new SelectionListener<ButtonEvent>() {
84
			public void componentSelected(ButtonEvent ce) {
512 gduche 85
				mediateur.clicSupprimerPersonne(r, grille.getSelectionModel().getSelectedItems());
217 aurelien 86
			}
87
		});
512 gduche 88
		supprimer.setIcon(Images.ICONES.supprimer());
127 gduche 89
		toolBar.add(supprimer);
617 gduche 90
 
91
		gererEtatActivationBouton();
566 jp_milcent 92
 
127 gduche 93
		setTopComponent(toolBar);
566 jp_milcent 94
 
95
		// Définition des colomnes de la grille:
512 gduche 96
		List<ColumnConfig> lstColumns = new ArrayList<ColumnConfig>();
566 jp_milcent 97
		ColumnConfig ccId = new ColumnConfig("id_personne", "Id", 45);
541 gduche 98
		lstColumns.add(ccId);
566 jp_milcent 99
		ColumnConfig ccFmtNomComplet = new ColumnConfig("fmt_nom_complet", "Nom Complet", 200);
512 gduche 100
		lstColumns.add(ccFmtNomComplet);
566 jp_milcent 101
		ColumnConfig ccCodePostal = new ColumnConfig("code_postal", "Code postal", 100);
512 gduche 102
		lstColumns.add(ccCodePostal);
566 jp_milcent 103
		ColumnConfig ccVille = new ColumnConfig("ville", "Ville", 100);
512 gduche 104
		lstColumns.add(ccVille);
566 jp_milcent 105
		ColumnConfig ccCourriel = new ColumnConfig("courriel_princ", "Courriel", 200);
512 gduche 106
		lstColumns.add(ccCourriel);
566 jp_milcent 107
		ColumnConfig ccNom = new ColumnConfig("nom", "Nom", 100);
512 gduche 108
		ccNom.setHidden(true);
109
		lstColumns.add(ccNom);
566 jp_milcent 110
		ColumnConfig ccPrenom = new ColumnConfig("prenom", "Prénom", 100);
512 gduche 111
		ccPrenom.setHidden(true);
112
		lstColumns.add(ccPrenom);
563 gduche 113
		modeleColonnes = new ColumnModel(lstColumns);
566 jp_milcent 114
 
115
		// Définition de la grille
512 gduche 116
		GridSelectionModel<Personne> gsmSelectionGrille = new GridSelectionModel<Personne>();
117
		gsmSelectionGrille.addSelectionChangedListener(new SelectionChangedListener<Personne>() {
520 gduche 118
			public void selectionChanged(SelectionChangedEvent<Personne> event) {
119
				Personne p = (Personne) event.getSelectedItem();
120
				personneSelectionnee = p;
121
				clicListe(p);
122
			}
150 gduche 123
		});
287 gduche 124
 
566 jp_milcent 125
		grille = new Grid<Personne>( new ListStore<Personne>(), modeleColonnes);
512 gduche 126
		grille.setSelectionModel(gsmSelectionGrille);
566 jp_milcent 127
		grille.setWidth("100%");
512 gduche 128
		grille.setAutoExpandColumn("fmt_nom_complet");
566 jp_milcent 129
		grille.getView().setAutoFill(true);
130
		grille.getView().setForceFit(true);
131
		grille.addListener(Events.ViewReady, new Listener<BaseEvent>() {
132
			@Override
133
			public void handleEvent(BaseEvent be) {
134
				grille.getSelectionModel().select(0, false);
135
			}
136
		});
562 gduche 137
		add(grille);
512 gduche 138
 
566 jp_milcent 139
		// Définition de la barre de pagination
596 gduche 140
		pagination = new BarrePaginationVue(new PersonneListe(), mediateur);
562 gduche 141
		setBottomComponent(pagination);
127 gduche 142
	}
143
 
150 gduche 144
	private void clicListe(Personne personne) {
278 jp_milcent 145
		mediateur.clicListePersonne(personne);
127 gduche 146
	}
147
 
617 gduche 148
	private void gererEtatActivationBouton()	{
149
 
150
		if (((Utilisateur) Registry.get(RegistreId.UTILISATEUR_COURANT)).isIdentifie() == false)	{
151
			supprimer.setEnabled(false);
152
		} else	{
153
 
154
			supprimer.setEnabled(true);
155
		}
156
 
157
	}
158
 
353 gduche 159
	public void rafraichir(Object nouvellesDonnees) {
160
		if (nouvellesDonnees instanceof PersonneListe) {
596 gduche 161
 
162
 
163
 
353 gduche 164
			PersonneListe listePersonnes = (PersonneListe) nouvellesDonnees;
596 gduche 165
			System.out.println("PLV.150." + listePersonnes.size());
127 gduche 166
 
596 gduche 167
			pagination.setlistePaginable(listePersonnes);
168
			pagination.rafraichir(listePersonnes.getPageTable());
169
 
567 jp_milcent 170
			if (listePersonnes != null) {
171
				List<Personne> liste = (List<Personne>) listePersonnes.toList();
172
 
596 gduche 173
				ListStore<Personne> store = new ListStore<Personne>();
174
				store.add(liste);
567 jp_milcent 175
				grille.reconfigure(store, modeleColonnes);
176
 
177
				mediateur.actualiserPanneauCentral();
178
				store.sort("fmt_nom_complet", SortDir.ASC);
596 gduche 179
 
180
 
567 jp_milcent 181
			}
417 gduche 182
		} else if (nouvellesDonnees instanceof Information)	{
617 gduche 183
 
417 gduche 184
			Information info = (Information) nouvellesDonnees;
185
			if (info.getType().equals("suppression_personne")) 	{
512 gduche 186
				Info.display("Suppression de personne", info.getMessages().toString());
566 jp_milcent 187
				List<Personne> selectionPersonnes = grille.getSelectionModel().getSelectedItems();
188
				final int taille = selectionPersonnes.size();
189
				for (int i = 0; i < taille; i++) {
190
					grille.getStore().remove(selectionPersonnes.get(i));
191
				}
617 gduche 192
			} else if (info.getType().equals("maj_utilisateur"))	{
193
				gererEtatActivationBouton();
194
			} else {
512 gduche 195
				Info.display("Erreur", info.getMessages().toString());
361 jp_milcent 196
			}
197
		} else {
533 jp_milcent 198
			GWT.log(mediateur.i18nM.erreurRafraichir(nouvellesDonnees.getClass(), this.getClass()), null);
127 gduche 199
		}
596 gduche 200
 
201
 
202
 
278 jp_milcent 203
		layout();
127 gduche 204
	}
205
}
189 gduche 206
 
207
 
208
 
209
 
210
 
211