Subversion Repositories eFlore/Applications.coel

Rev

Rev 1792 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
934 jpm 1
package org.tela_botanica.client.vues.collection;
453 jp_milcent 2
 
3
import java.util.ArrayList;
910 jpm 4
import java.util.Iterator;
453 jp_milcent 5
import java.util.List;
6
 
1792 aurelien 7
import org.tela_botanica.client.Coel;
453 jp_milcent 8
import org.tela_botanica.client.Mediateur;
9
import org.tela_botanica.client.RegistreId;
1633 aurelien 10
import org.tela_botanica.client.composants.ChampFiltreRecherche;
1239 cyprien 11
import org.tela_botanica.client.composants.InfoLogger;
453 jp_milcent 12
import org.tela_botanica.client.i18n.Constantes;
516 jp_milcent 13
import org.tela_botanica.client.images.Images;
453 jp_milcent 14
import org.tela_botanica.client.interfaces.Rafraichissable;
15
import org.tela_botanica.client.modeles.Information;
16
import org.tela_botanica.client.modeles.Utilisateur;
935 jpm 17
import org.tela_botanica.client.modeles.collection.Collection;
1762 mathias 18
import org.tela_botanica.client.modeles.collection.CollectionAsyncDao;
935 jpm 19
import org.tela_botanica.client.modeles.collection.CollectionListe;
1613 aurelien 20
import org.tela_botanica.client.modeles.personne.Personne;
1762 mathias 21
import org.tela_botanica.client.modeles.personne.PersonneAsyncDao;
935 jpm 22
import org.tela_botanica.client.modeles.publication.Publication;
1041 gduche 23
import org.tela_botanica.client.modeles.structure.StructureListe;
952 jpm 24
import org.tela_botanica.client.util.Debug;
1041 gduche 25
import org.tela_botanica.client.vues.BarrePaginationVue;
453 jp_milcent 26
 
27
import com.extjs.gxt.ui.client.Registry;
28
import com.extjs.gxt.ui.client.Style.SortDir;
567 jp_milcent 29
import com.extjs.gxt.ui.client.event.BaseEvent;
499 jp_milcent 30
import com.extjs.gxt.ui.client.event.ButtonEvent;
567 jp_milcent 31
import com.extjs.gxt.ui.client.event.Events;
1762 mathias 32
import com.extjs.gxt.ui.client.event.GridEvent;
567 jp_milcent 33
import com.extjs.gxt.ui.client.event.Listener;
453 jp_milcent 34
import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
35
import com.extjs.gxt.ui.client.event.SelectionChangedListener;
36
import com.extjs.gxt.ui.client.event.SelectionListener;
37
import com.extjs.gxt.ui.client.store.ListStore;
38
import com.extjs.gxt.ui.client.widget.ContentPanel;
499 jp_milcent 39
import com.extjs.gxt.ui.client.widget.button.Button;
558 jp_milcent 40
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
41
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
42
import com.extjs.gxt.ui.client.widget.grid.Grid;
43
import com.extjs.gxt.ui.client.widget.grid.GridSelectionModel;
453 jp_milcent 44
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
45
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
1792 aurelien 46
import com.google.gwt.user.client.Window;
453 jp_milcent 47
 
48
public class CollectionListeVue extends ContentPanel implements Rafraichissable {
49
 
558 jp_milcent 50
	private Mediateur mediateur = null;
51
	private Constantes i18nC = null;
453 jp_milcent 52
 
558 jp_milcent 53
	private Grid<Collection> grille = null;
453 jp_milcent 54
	private ListStore<Collection> store = null;
55
 
499 jp_milcent 56
	private Button modifier;
57
	private Button supprimer;
58
	private Button ajouter;
1041 gduche 59
	private BarrePaginationVue pagination = null;
1633 aurelien 60
	private ChampFiltreRecherche champFiltreRecherche = null;
1041 gduche 61
 
1613 aurelien 62
	private int indexElementSelectionne = 0;
63
	private Collection collectionSelectionnee = null;
64
 
453 jp_milcent 65
	public CollectionListeVue(Mediateur mediateurCourant) {
66
		mediateur = mediateurCourant;
919 jpm 67
		i18nC = Mediateur.i18nC;
453 jp_milcent 68
 
558 jp_milcent 69
		setLayout(new FitLayout());
1789 aurelien 70
		setHeaderVisible(false);
453 jp_milcent 71
 
72
		ToolBar toolBar = new ToolBar();
499 jp_milcent 73
		ajouter = new Button(i18nC.ajouter());
516 jp_milcent 74
		ajouter.setIcon(Images.ICONES.ajouter());
499 jp_milcent 75
		ajouter.addSelectionListener(new SelectionListener<ButtonEvent>() {
76
			public void componentSelected(ButtonEvent ce) {
453 jp_milcent 77
				mediateur.clicAjouterCollection();
78
			}
79
		});
1630 aurelien 80
		ajouter.setToolTip(i18nC.indicationCreerUneFiche()+" "+i18nC.collectionSingulier());
453 jp_milcent 81
		toolBar.add(ajouter);
82
 
499 jp_milcent 83
		modifier = new Button(i18nC.modifier());
516 jp_milcent 84
		modifier.setIcon(Images.ICONES.formModifier());
499 jp_milcent 85
		modifier.addSelectionListener(new SelectionListener<ButtonEvent>() {
86
			public void componentSelected(ButtonEvent ce) {
558 jp_milcent 87
				mediateur.clicModifierCollection(grille.getSelectionModel().getSelectedItems());
453 jp_milcent 88
			}
89
		});
1630 aurelien 90
		modifier.setToolTip(i18nC.indicationModifierUneFiche());
453 jp_milcent 91
		toolBar.add(modifier);
92
 
499 jp_milcent 93
		supprimer = new Button(i18nC.supprimer());
516 jp_milcent 94
		supprimer.setIcon(Images.ICONES.supprimer());
499 jp_milcent 95
		supprimer.addSelectionListener(new SelectionListener<ButtonEvent>() {
96
			public void componentSelected(ButtonEvent ce) {
558 jp_milcent 97
				clicSupprimerCollection(grille.getSelectionModel().getSelectedItems());
453 jp_milcent 98
			}
99
		});
1630 aurelien 100
		supprimer.setToolTip(i18nC.indicationSupprimerUneFiche());
453 jp_milcent 101
		toolBar.add(supprimer);
1633 aurelien 102
 
453 jp_milcent 103
		setTopComponent(toolBar);
104
 
558 jp_milcent 105
		List<ColumnConfig> colonnes = new ArrayList<ColumnConfig>();
703 jp_milcent 106
		colonnes.add(new ColumnConfig("nom", i18nC.personneNom(), 300));
1173 jpm 107
		colonnes.add(new ColumnConfig("_structure_nom_", i18nC.structure(), 200));
108
		colonnes.add(new ColumnConfig("_structure_ville_", i18nC.ville(), 150));
558 jp_milcent 109
		colonnes.get(1).setHidden(true);
110
		ColumnModel modeleDeColonne = new ColumnModel(colonnes);
453 jp_milcent 111
 
558 jp_milcent 112
		GridSelectionModel<Collection> modeleDeSelection = new GridSelectionModel<Collection>();
113
		modeleDeSelection.addSelectionChangedListener(new SelectionChangedListener<Collection>() {
114
			public void selectionChanged(SelectionChangedEvent<Collection> event) {
1613 aurelien 115
				collectionSelectionnee = (Collection) event.getSelectedItem();
116
				indexElementSelectionne = store.indexOf(collectionSelectionnee);
558 jp_milcent 117
				clicListe(collectionSelectionnee);
118
			}
119
		});
468 jp_milcent 120
 
453 jp_milcent 121
		store = new ListStore<Collection>();
122
 
558 jp_milcent 123
		grille = new Grid<Collection>(store, modeleDeColonne);
124
		grille.setWidth("100%");
125
		grille.setAutoExpandColumn("nom");
565 jp_milcent 126
		grille.getView().setAutoFill(true);
127
		grille.getView().setForceFit(true);
558 jp_milcent 128
		grille.setSelectionModel(modeleDeSelection);
567 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
 
140
		grille.addListener(Events.SortChange, new Listener<BaseEvent>() {
141
 
142
			@Override
143
			public void handleEvent(BaseEvent be) {
144
				GridEvent ge = (GridEvent<Collection>) be;
145
				// TODO rajouter un test sur le sort state pour trier par nom par défaut
146
				String tri = ge.getSortInfo().getSortField();
147
				if(tri.equals("_structure_ville_")) {
148
					tri = "cs_ville";
149
				} else {
150
					tri = Collection.PREFIXE+"_"+tri;
151
				}
152
				CollectionAsyncDao.tri = tri+" "+ge.getSortInfo().getSortDir().toString();
153
				pagination.changePage();
154
			}
155
		});
558 jp_milcent 156
		add(grille);
1041 gduche 157
 
1633 aurelien 158
		CollectionListe collectionListe = new CollectionListe();
159
		champFiltreRecherche = new ChampFiltreRecherche(mediateur, toolBar, collectionListe);
1041 gduche 160
		// Définition de la barre de pagination
1687 raphael 161
		pagination = new BarrePaginationVue(collectionListe, mediateur, champFiltreRecherche);
1041 gduche 162
		setBottomComponent(pagination);
453 jp_milcent 163
	}
164
 
865 jpm 165
	private void clicListe(Collection collection) {
166
		if (collection != null && store.getCount() > 0) {
167
			mediateur.clicListeCollection(collection);
453 jp_milcent 168
		}
169
	}
1284 gduche 170
 
453 jp_milcent 171
	private void clicSupprimerCollection(List<Collection> collectionsASupprimer) {
172
		if (store.getCount() > 0) {
173
			mediateur.clicSupprimerCollection(this, collectionsASupprimer);
174
		}
175
	}
558 jp_milcent 176
 
177
	private void gererEtatActivationBouton() {
178
		int nbreElementDuMagazin = store.getCount();
900 jpm 179
		ajouter.enable();
558 jp_milcent 180
		if (nbreElementDuMagazin == 0) {
181
			supprimer.disable();
182
			modifier.disable();
183
		} else if (nbreElementDuMagazin > 0) {
184
			modifier.enable();
185
			if (((Utilisateur) Registry.get(RegistreId.UTILISATEUR_COURANT)).isIdentifie()) {
186
				supprimer.enable();
187
			}
188
		}
189
	}
453 jp_milcent 190
 
851 gduche 191
	public void rafraichir(Object nouvellesDonnees) {
1322 gduche 192
 
851 gduche 193
		if (nouvellesDonnees instanceof CollectionListe) {
194
			CollectionListe collections = (CollectionListe) nouvellesDonnees;
453 jp_milcent 195
 
1041 gduche 196
			pagination.setlistePaginable(collections);
197
			int[] pt = collections.getPageTable();
198
			pagination.rafraichir(collections.getPageTable());
1633 aurelien 199
			champFiltreRecherche.setListePaginable(collections);
1041 gduche 200
 
1284 gduche 201
			if (collections != null) {
684 jp_milcent 202
				List<Collection> liste = collections.toList();
558 jp_milcent 203
				store.removeAll();
204
				store.add(liste);
205
 
206
				mediateur.actualiserPanneauCentral();
453 jp_milcent 207
			}
851 gduche 208
		} else if (nouvellesDonnees instanceof Information) {
209
			Information info = (Information) nouvellesDonnees;
1122 jpm 210
			if (info.getType().equals("maj_utilisateur")) {
211
				gererEtatActivationBouton();
1613 aurelien 212
			} else if (info.getType().equals("modif_collection")) {
1792 aurelien 213
				// curieusement la suppression efface aussi l'index de l'élément
214
				// car elle redéclenche l'évenement de selection (on le stocke donc temporairement)
215
				int temporaire = indexElementSelectionne;
1613 aurelien 216
				if(collectionSelectionnee != null) {
1792 aurelien 217
					store.remove(collectionSelectionnee);
1613 aurelien 218
					collectionSelectionnee = null;
219
				}
220
				Collection collecModifiee = (Collection)info.getDonnee(0);
221
				// au cas ou le bouton appliquer aurait été cliqué avant de valider
222
				store.remove(collecModifiee);
1792 aurelien 223
				indexElementSelectionne = temporaire;
224
				store.insert(collecModifiee, temporaire);
1645 aurelien 225
				collectionSelectionnee = collecModifiee;
226
				int indexElementSelectionne = store.indexOf(collectionSelectionnee);
227
				grille.getSelectionModel().select(indexElementSelectionne, false);
228
				grille.getView().focusRow(indexElementSelectionne);
1792 aurelien 229
				clicListe(collectionSelectionnee);
1122 jpm 230
			} else if (info.getType().equals("suppression_collection")) {
453 jp_milcent 231
				// Affichage d'un message d'information
1239 cyprien 232
				InfoLogger.display(i18nC.suppressionCollection(), info.toString().replaceAll("\n", "<br />"));
453 jp_milcent 233
 
910 jpm 234
				supprimerCollectionsSelectionnees();
453 jp_milcent 235
 
558 jp_milcent 236
				gererEtatActivationBouton();
453 jp_milcent 237
			}
238
		} else {
952 jpm 239
			Debug.log(Mediateur.i18nM.erreurRafraichir(nouvellesDonnees.getClass(), this.getClass()));
453 jp_milcent 240
		}
241
		layout();
242
	}
910 jpm 243
 
244
	private void supprimerCollectionsSelectionnees() {
245
		List<Collection> collectionsSelectionnees = grille.getSelectionModel().getSelectedItems();
246
		Iterator<Collection> it = collectionsSelectionnees.iterator();
247
		while (it.hasNext()) {
248
			grille.getStore().remove(it.next());
249
		}
250
		layout(true);
251
	}
453 jp_milcent 252
}