Subversion Repositories eFlore/Applications.coel

Rev

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