Subversion Repositories eFlore/Applications.coel

Rev

Rev 1645 | Rev 1687 | 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;
1637 aurelien 20
import org.tela_botanica.client.util.Debug;
1040 gduche 21
import org.tela_botanica.client.vues.BarrePaginationVue;
60 jpm 22
 
23
import com.extjs.gxt.ui.client.Registry;
210 jp_milcent 24
import com.extjs.gxt.ui.client.Style.SortDir;
566 jp_milcent 25
import com.extjs.gxt.ui.client.event.BaseEvent;
490 gduche 26
import com.extjs.gxt.ui.client.event.ButtonEvent;
566 jp_milcent 27
import com.extjs.gxt.ui.client.event.Events;
28
import com.extjs.gxt.ui.client.event.Listener;
60 jpm 29
import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
30
import com.extjs.gxt.ui.client.event.SelectionChangedListener;
69 jpm 31
import com.extjs.gxt.ui.client.event.SelectionListener;
60 jpm 32
import com.extjs.gxt.ui.client.store.ListStore;
33
import com.extjs.gxt.ui.client.widget.ContentPanel;
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
 
1680 raphael 66
		setHeadingHtml(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) {
1637 aurelien 110
				if((Structure) event.getSelectedItem() != null) {
111
					structureSelectionnee = (Structure) event.getSelectedItem();
112
					indexElementSelectionne = store.indexOf(structureSelectionnee);
113
					clicListe(structureSelectionnee);
114
				}
60 jpm 115
			}
116
		});
521 gduche 117
 
551 jp_milcent 118
		store = new ListStore<Structure>();
119
		store.sort("ville", SortDir.ASC);
120
 
559 jp_milcent 121
		grille = new Grid<Structure>(store, modeleDeColonne);
551 jp_milcent 122
		grille.setWidth("100%");
123
		grille.setAutoExpandColumn("nom");
565 jp_milcent 124
		grille.getView().setAutoFill(true);
125
		grille.getView().setForceFit(true);
559 jp_milcent 126
		grille.setSelectionModel(modeleDeSelection);
566 jp_milcent 127
		grille.addListener(Events.ViewReady, new Listener<BaseEvent>() {
128
			public void handleEvent(BaseEvent be) {
129
				grille.getSelectionModel().select(0, false);
130
			}
131
		});
671 jp_milcent 132
		grille.addListener(Events.OnDoubleClick, new Listener<BaseEvent>() {
133
			public void handleEvent(BaseEvent be) {
134
				modifier.fireEvent(Events.Select);
135
			}
136
		});
521 gduche 137
		add(grille);
1040 gduche 138
 
1633 aurelien 139
		StructureListe structureListe = new StructureListe();
140
		champFiltreRecherche = new ChampFiltreRecherche(mediateurCourant, toolBar, structureListe);
1040 gduche 141
		// Définition de la barre de pagination
1633 aurelien 142
		pagination = new BarrePaginationVue(structureListe, mediateur);
1040 gduche 143
		setBottomComponent(pagination);
60 jpm 144
	}
145
 
379 jp_milcent 146
	private void clicListe(Structure structure) {
865 jpm 147
		if (structure != null && store.getCount() > 0) {
148
			mediateur.clicListeStructure(structure);
149
		}
60 jpm 150
	}
448 jp_milcent 151
 
152
	private void clicSupprimerStructure(List<Structure> structuresASupprimer) {
609 jp_milcent 153
		mediateur.clicSupprimerStructure(this, structuresASupprimer);
448 jp_milcent 154
	}
60 jpm 155
 
551 jp_milcent 156
	private void gererEtatActivationBouton() {
157
		int nbreElementDuMagazin = store.getCount();
158
		if (nbreElementDuMagazin == 0) {
159
			supprimer.disable();
160
			modifier.disable();
161
		} else if (nbreElementDuMagazin > 0) {
162
			modifier.enable();
163
			if (((Utilisateur) Registry.get(RegistreId.UTILISATEUR_COURANT)).isIdentifie()) {
164
				supprimer.enable();
165
			}
166
		}
167
	}
168
 
635 jp_milcent 169
	public void rafraichir(Object nouvellesDonnees) {
170
		if (nouvellesDonnees instanceof StructureListe) {
171
			StructureListe structures = (StructureListe) nouvellesDonnees;
1633 aurelien 172
 
173
			champFiltreRecherche.setListePaginable(structures);
1040 gduche 174
			pagination.setlistePaginable(structures);
175
			pagination.rafraichir(structures.getPageTable());
60 jpm 176
 
556 jp_milcent 177
			if (structures != null) {
685 jp_milcent 178
				List<Structure> liste = structures.toList();
556 jp_milcent 179
				store.removeAll();
180
				store.add(liste);
609 jp_milcent 181
 
556 jp_milcent 182
				gererEtatActivationBouton();
183
 
184
				mediateur.actualiserPanneauCentral();
1040 gduche 185
				grille.fireEvent(Events.ViewReady);
60 jpm 186
			}
635 jp_milcent 187
		} else if (nouvellesDonnees instanceof Information) {
188
			Information info = (Information) nouvellesDonnees;
133 jpm 189
			if (info.getType().equals("suppression_structure")) {
155 jpm 190
				// Affichage d'un message d'information
1239 cyprien 191
				InfoLogger.display(i18nC.suppressionStructure(), info.toString().replaceAll("\n", "<br />"));
923 jpm 192
 
193
				List<Structure> selectionStructure = grille.getSelectionModel().getSelectedItems();
194
 
195
				if (info.toString().replaceAll("\n", "").equals("OK")) {
196
					mediateur.supprimerStructureAPersonne(this, selectionStructure);
197
				}
198
 
609 jp_milcent 199
				// Suppression des structures sélectionnées de la grille
155 jpm 200
				final int taille = selectionStructure.size();
201
				for (int i = 0; i < taille; i++) {
521 gduche 202
					store.remove(selectionStructure.get(i));
155 jpm 203
				}
204
 
551 jp_milcent 205
				gererEtatActivationBouton();
1613 aurelien 206
			} else if(info.getType().equals("structure_modifiee")) {
1637 aurelien 207
				Structure structureModifiee = (Structure)info.getDonnee(0);
208
				if(structureSelectionnee != null && structureModifiee != null) {
209
					if(structureSelectionnee.getId().equals(structureModifiee.getId())) {
210
						store.remove(indexElementSelectionne);
211
					} else {
212
						structureSelectionnee = null;
213
					}
214
					// au cas ou le bouton appliquer aurait été cliqué avant de valider
215
					store.remove(structureModifiee);
216
					store.insert(structureModifiee, indexElementSelectionne);
1645 aurelien 217
					structureSelectionnee = structureModifiee;
218
					int indexElementSelectionne = store.indexOf(structureSelectionnee);
219
					grille.getSelectionModel().select(indexElementSelectionne, false);
220
					grille.getView().focusRow(indexElementSelectionne);
221
					clicListe(structureSelectionnee);
1613 aurelien 222
				}
156 jp_milcent 223
			} else if (info.getType().equals("maj_utilisateur")) {
551 jp_milcent 224
				gererEtatActivationBouton();
923 jpm 225
			} else if (info.getType().equals("suppression_structure_a_personne")) {
226
				// Affichage d'un message d'information
1239 cyprien 227
				InfoLogger.display(i18nC.suppressionStructureAPersonne(), info.toString().replaceAll("\n", "<br />"));
133 jpm 228
			}
156 jp_milcent 229
		} else {
635 jp_milcent 230
			GWT.log(Mediateur.i18nM.erreurRafraichir(nouvellesDonnees.getClass(), this.getClass()), null);
60 jpm 231
		}
156 jp_milcent 232
		layout();
60 jpm 233
	}
234
}