Subversion Repositories eFlore/Applications.coel

Rev

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