Subversion Repositories eFlore/Applications.coel

Rev

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