Subversion Repositories eFlore/Applications.coel

Rev

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