Subversion Repositories eFlore/Applications.coel

Rev

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

Rev Author Line No. Line
935 jpm 1
package org.tela_botanica.client.vues.structure;
60 jpm 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;
1239 cyprien 8
import org.tela_botanica.client.composants.InfoLogger;
422 jp_milcent 9
import org.tela_botanica.client.i18n.Constantes;
521 gduche 10
import org.tela_botanica.client.images.Images;
60 jpm 11
import org.tela_botanica.client.interfaces.Rafraichissable;
133 jpm 12
import org.tela_botanica.client.modeles.Information;
156 jp_milcent 13
import org.tela_botanica.client.modeles.Utilisateur;
1613 aurelien 14
import org.tela_botanica.client.modeles.personne.Personne;
15
import org.tela_botanica.client.modeles.publication.Publication;
935 jpm 16
import org.tela_botanica.client.modeles.structure.Structure;
17
import org.tela_botanica.client.modeles.structure.StructureListe;
1040 gduche 18
import org.tela_botanica.client.vues.BarrePaginationVue;
60 jpm 19
 
20
import com.extjs.gxt.ui.client.Registry;
210 jp_milcent 21
import com.extjs.gxt.ui.client.Style.SortDir;
566 jp_milcent 22
import com.extjs.gxt.ui.client.event.BaseEvent;
490 gduche 23
import com.extjs.gxt.ui.client.event.ButtonEvent;
566 jp_milcent 24
import com.extjs.gxt.ui.client.event.Events;
25
import com.extjs.gxt.ui.client.event.Listener;
60 jpm 26
import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
27
import com.extjs.gxt.ui.client.event.SelectionChangedListener;
69 jpm 28
import com.extjs.gxt.ui.client.event.SelectionListener;
60 jpm 29
import com.extjs.gxt.ui.client.store.ListStore;
30
import com.extjs.gxt.ui.client.widget.ContentPanel;
133 jpm 31
import com.extjs.gxt.ui.client.widget.Info;
490 gduche 32
import com.extjs.gxt.ui.client.widget.button.Button;
521 gduche 33
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
34
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
35
import com.extjs.gxt.ui.client.widget.grid.Grid;
36
import com.extjs.gxt.ui.client.widget.grid.GridSelectionModel;
60 jpm 37
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
38
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
133 jpm 39
import com.google.gwt.core.client.GWT;
1040 gduche 40
import com.google.gwt.user.client.Window;
60 jpm 41
 
442 jp_milcent 42
public class StructureListeVue extends ContentPanel implements Rafraichissable {
60 jpm 43
 
553 jp_milcent 44
	private Mediateur mediateur = null;
45
	private Constantes i18nC = null;
448 jp_milcent 46
 
521 gduche 47
	private Grid<Structure> grille = null;
60 jpm 48
	private ListStore<Structure> store = null;
521 gduche 49
 
490 gduche 50
	private Button modifier;
51
	private Button supprimer;
52
	private Button ajouter;
1040 gduche 53
 
54
	private BarrePaginationVue pagination = null;
1613 aurelien 55
 
56
	private int indexElementSelectionne = 0;
57
	private Structure structureSelectionnee = null;
60 jpm 58
 
442 jp_milcent 59
	public StructureListeVue(Mediateur mediateurCourant) {
373 jp_milcent 60
		mediateur = mediateurCourant;
422 jp_milcent 61
		i18nC = mediateur.i18nC;
373 jp_milcent 62
 
553 jp_milcent 63
		setHeading(i18nC.titreStructureListe());
551 jp_milcent 64
		setLayout(new FitLayout());
60 jpm 65
 
66
		ToolBar toolBar = new ToolBar();
490 gduche 67
		ajouter = new Button(i18nC.ajouter());
521 gduche 68
		ajouter.setIcon(Images.ICONES.ajouter());
490 gduche 69
		ajouter.addSelectionListener(new SelectionListener<ButtonEvent>() {
70
			public void componentSelected(ButtonEvent ce) {
156 jp_milcent 71
				mediateur.clicAjouterStructure();
133 jpm 72
			}
69 jpm 73
		});
1630 aurelien 74
		ajouter.setToolTip(i18nC.indicationCreerUneFiche()+" "+i18nC.structureSingulier());
60 jpm 75
		toolBar.add(ajouter);
76
 
490 gduche 77
		modifier = new Button(i18nC.modifier());
521 gduche 78
		modifier.setIcon(Images.ICONES.formModifier());
490 gduche 79
		modifier.addSelectionListener(new SelectionListener<ButtonEvent>() {
80
			public void componentSelected(ButtonEvent ce) {
521 gduche 81
				mediateur.clicModifierStructure(grille.getSelectionModel().getSelectedItems());
156 jp_milcent 82
			}
83
		});
1630 aurelien 84
		modifier.setToolTip(i18nC.indicationModifierUneFiche());
60 jpm 85
		toolBar.add(modifier);
86
 
490 gduche 87
		supprimer = new Button(i18nC.supprimer());
521 gduche 88
		supprimer.setIcon(Images.ICONES.supprimer());
490 gduche 89
		supprimer.addSelectionListener(new SelectionListener<ButtonEvent>() {
90
			public void componentSelected(ButtonEvent ce) {
521 gduche 91
				clicSupprimerStructure(grille.getSelectionModel().getSelectedItems());
133 jpm 92
			}
93
		});
1630 aurelien 94
		supprimer.setToolTip(i18nC.indicationSupprimerUneFiche());
60 jpm 95
		toolBar.add(supprimer);
96
 
97
		setTopComponent(toolBar);
98
 
559 jp_milcent 99
		List<ColumnConfig> colonnes = new ArrayList<ColumnConfig>();
100
		colonnes.add(new ColumnConfig("ville", "Ville", 150));
101
		colonnes.add(new ColumnConfig("nom", "Nom", 450));
102
		ColumnModel modeleDeColonne = new ColumnModel(colonnes);
521 gduche 103
 
559 jp_milcent 104
		GridSelectionModel<Structure> modeleDeSelection = new GridSelectionModel<Structure>();
105
		modeleDeSelection.addSelectionChangedListener(new SelectionChangedListener<Structure>() {
60 jpm 106
			public void selectionChanged(SelectionChangedEvent<Structure> event) {
1613 aurelien 107
				structureSelectionnee = (Structure) event.getSelectedItem();
108
				indexElementSelectionne = store.indexOf(structureSelectionnee);
559 jp_milcent 109
				clicListe(structureSelectionnee);
60 jpm 110
			}
111
		});
521 gduche 112
 
551 jp_milcent 113
		store = new ListStore<Structure>();
114
		store.sort("ville", SortDir.ASC);
115
 
559 jp_milcent 116
		grille = new Grid<Structure>(store, modeleDeColonne);
551 jp_milcent 117
		grille.setWidth("100%");
118
		grille.setAutoExpandColumn("nom");
565 jp_milcent 119
		grille.getView().setAutoFill(true);
120
		grille.getView().setForceFit(true);
559 jp_milcent 121
		grille.setSelectionModel(modeleDeSelection);
566 jp_milcent 122
		grille.addListener(Events.ViewReady, new Listener<BaseEvent>() {
123
			public void handleEvent(BaseEvent be) {
124
				grille.getSelectionModel().select(0, false);
125
			}
126
		});
671 jp_milcent 127
		grille.addListener(Events.OnDoubleClick, new Listener<BaseEvent>() {
128
			public void handleEvent(BaseEvent be) {
129
				modifier.fireEvent(Events.Select);
130
			}
131
		});
521 gduche 132
		add(grille);
1040 gduche 133
 
134
		// Définition de la barre de pagination
135
		pagination = new BarrePaginationVue(new StructureListe(), mediateur);
136
		setBottomComponent(pagination);
60 jpm 137
	}
138
 
379 jp_milcent 139
	private void clicListe(Structure structure) {
865 jpm 140
		if (structure != null && store.getCount() > 0) {
141
			mediateur.clicListeStructure(structure);
142
		}
60 jpm 143
	}
448 jp_milcent 144
 
145
	private void clicSupprimerStructure(List<Structure> structuresASupprimer) {
609 jp_milcent 146
		mediateur.clicSupprimerStructure(this, structuresASupprimer);
448 jp_milcent 147
	}
60 jpm 148
 
551 jp_milcent 149
	private void gererEtatActivationBouton() {
150
		int nbreElementDuMagazin = store.getCount();
151
		if (nbreElementDuMagazin == 0) {
152
			supprimer.disable();
153
			modifier.disable();
154
		} else if (nbreElementDuMagazin > 0) {
155
			modifier.enable();
156
			if (((Utilisateur) Registry.get(RegistreId.UTILISATEUR_COURANT)).isIdentifie()) {
157
				supprimer.enable();
158
			}
159
		}
160
	}
161
 
635 jp_milcent 162
	public void rafraichir(Object nouvellesDonnees) {
163
		if (nouvellesDonnees instanceof StructureListe) {
164
			StructureListe structures = (StructureListe) nouvellesDonnees;
1040 gduche 165
			pagination.setlistePaginable(structures);
166
			pagination.rafraichir(structures.getPageTable());
60 jpm 167
 
556 jp_milcent 168
			if (structures != null) {
685 jp_milcent 169
				List<Structure> liste = structures.toList();
556 jp_milcent 170
				store.removeAll();
171
				store.add(liste);
609 jp_milcent 172
 
556 jp_milcent 173
				gererEtatActivationBouton();
174
 
175
				mediateur.actualiserPanneauCentral();
1040 gduche 176
				grille.fireEvent(Events.ViewReady);
60 jpm 177
			}
635 jp_milcent 178
		} else if (nouvellesDonnees instanceof Information) {
179
			Information info = (Information) nouvellesDonnees;
133 jpm 180
			if (info.getType().equals("suppression_structure")) {
155 jpm 181
				// Affichage d'un message d'information
1239 cyprien 182
				InfoLogger.display(i18nC.suppressionStructure(), info.toString().replaceAll("\n", "<br />"));
923 jpm 183
 
184
				List<Structure> selectionStructure = grille.getSelectionModel().getSelectedItems();
185
 
186
				if (info.toString().replaceAll("\n", "").equals("OK")) {
187
					mediateur.supprimerStructureAPersonne(this, selectionStructure);
188
				}
189
 
609 jp_milcent 190
				// Suppression des structures sélectionnées de la grille
155 jpm 191
				final int taille = selectionStructure.size();
192
				for (int i = 0; i < taille; i++) {
521 gduche 193
					store.remove(selectionStructure.get(i));
155 jpm 194
				}
195
 
551 jp_milcent 196
				gererEtatActivationBouton();
1613 aurelien 197
			} else if(info.getType().equals("structure_modifiee")) {
198
				if(structureSelectionnee != null) {
199
					store.remove(indexElementSelectionne);
200
					structureSelectionnee = null;
201
				}
202
				Structure structureModifiee = (Structure)info.getDonnee(0);
203
				// au cas ou le bouton appliquer aurait été cliqué avant de valider
204
				store.remove(structureModifiee);
205
				store.insert(structureModifiee, indexElementSelectionne);
206
				grille.repaint();
207
				grille.getSelectionModel().select(indexElementSelectionne, true);
208
				clicListe(structureModifiee);
156 jp_milcent 209
			} else if (info.getType().equals("maj_utilisateur")) {
551 jp_milcent 210
				gererEtatActivationBouton();
923 jpm 211
			} else if (info.getType().equals("suppression_structure_a_personne")) {
212
				// Affichage d'un message d'information
1239 cyprien 213
				InfoLogger.display(i18nC.suppressionStructureAPersonne(), info.toString().replaceAll("\n", "<br />"));
133 jpm 214
			}
156 jp_milcent 215
		} else {
635 jp_milcent 216
			GWT.log(Mediateur.i18nM.erreurRafraichir(nouvellesDonnees.getClass(), this.getClass()), null);
60 jpm 217
		}
156 jp_milcent 218
		layout();
60 jpm 219
	}
220
}