Subversion Repositories eFlore/Applications.coel

Rev

Rev 1513 | 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.projet;
834 aurelien 2
 
3
import java.util.ArrayList;
1080 gduche 4
import java.util.Arrays;
834 aurelien 5
import java.util.Iterator;
6
import java.util.List;
7
 
8
import org.tela_botanica.client.Mediateur;
9
import org.tela_botanica.client.RegistreId;
1239 cyprien 10
import org.tela_botanica.client.composants.InfoLogger;
834 aurelien 11
import org.tela_botanica.client.i18n.Constantes;
12
import org.tela_botanica.client.images.Images;
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.projet.Projet;
17
import org.tela_botanica.client.modeles.projet.ProjetListe;
1613 aurelien 18
import org.tela_botanica.client.modeles.publication.Publication;
1045 gduche 19
import org.tela_botanica.client.modeles.structure.StructureListe;
926 jpm 20
import org.tela_botanica.client.util.Debug;
1080 gduche 21
import org.tela_botanica.client.util.UtilString;
1045 gduche 22
import org.tela_botanica.client.vues.BarrePaginationVue;
834 aurelien 23
 
24
import com.extjs.gxt.ui.client.Registry;
25
import com.extjs.gxt.ui.client.Style.SortDir;
26
import com.extjs.gxt.ui.client.event.BaseEvent;
27
import com.extjs.gxt.ui.client.event.ButtonEvent;
28
import com.extjs.gxt.ui.client.event.Events;
29
import com.extjs.gxt.ui.client.event.Listener;
30
import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
31
import com.extjs.gxt.ui.client.event.SelectionChangedListener;
32
import com.extjs.gxt.ui.client.event.SelectionListener;
33
import com.extjs.gxt.ui.client.store.ListStore;
34
import com.extjs.gxt.ui.client.widget.ContentPanel;
931 jpm 35
import com.extjs.gxt.ui.client.widget.Info;
834 aurelien 36
import com.extjs.gxt.ui.client.widget.button.Button;
37
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
38
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
39
import com.extjs.gxt.ui.client.widget.grid.Grid;
40
import com.extjs.gxt.ui.client.widget.grid.GridSelectionModel;
41
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
42
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
43
import com.google.gwt.core.client.GWT;
1613 aurelien 44
import com.google.gwt.user.client.Window;
834 aurelien 45
 
46
public class ProjetListeVue extends ContentPanel implements Rafraichissable {
47
 
48
	private Mediateur mediateur = null;
49
	private Constantes i18nC = null;
50
 
51
	private Grid<Projet> grille = null;
52
	private ListStore<Projet> store = null;
53
	private ColumnModel modeleDesColonnes = null;
1045 gduche 54
	private BarrePaginationVue pagination = null;
55
 
834 aurelien 56
	private Button ajouter;
57
	private Button modifier;
58
	private Button supprimer;
59
 
1613 aurelien 60
	private int indexElementSelectionne = 0;
61
	private Projet projetSelectionne = null;
62
 
834 aurelien 63
	public ProjetListeVue(Mediateur mediateurCourant) {
64
		super();
65
		mediateur = mediateurCourant;
66
		i18nC = Mediateur.i18nC;
67
 
68
		setLayout(new FitLayout());
69
		setHeading("Projets");
70
 
71
		ToolBar toolBar = new ToolBar();
72
		ajouter = new Button(i18nC.ajouter());
73
		ajouter.setIcon(Images.ICONES.ajouter());
74
		ajouter.addSelectionListener(new SelectionListener<ButtonEvent>() {
75
			public void componentSelected(ButtonEvent be) {
76
				mediateur.clicAjouterProjet();
77
			}
78
		});
79
		toolBar.add(ajouter);
80
 
81
		modifier = new Button(i18nC.modifier());
82
		modifier.setIcon(Images.ICONES.formModifier());
83
		modifier.addSelectionListener(new SelectionListener<ButtonEvent>() {
84
			public void componentSelected(ButtonEvent be) {
924 jpm 85
				mediateur.clicModifierProjet(grille.getSelectionModel().getSelectedItems());
1613 aurelien 86
				indexElementSelectionne = store.indexOf(grille.getSelectionModel().getSelectedItem());
834 aurelien 87
			}
88
		});
924 jpm 89
		toolBar.add(modifier);
834 aurelien 90
 
91
		supprimer = new Button(i18nC.supprimer());
92
		supprimer.setIcon(Images.ICONES.supprimer());
93
		supprimer.addSelectionListener(new SelectionListener<ButtonEvent>() {
94
			public void componentSelected(ButtonEvent be) {
95
				mediateur.clicSupprimerProjet(grille.getSelectionModel().getSelectedItems());
96
			}
97
		});
924 jpm 98
		toolBar.add(supprimer);
834 aurelien 99
 
100
		setTopComponent(toolBar);
101
 
102
		List<ColumnConfig> colonnes = new ArrayList<ColumnConfig>();
103
		// ATTENTION : les noms des colonnes doivent correspondre aux noms variables de la classe utilisée dans la liste
877 aurelien 104
		colonnes.add(new ColumnConfig("id_projet", i18nC.id(), 20));
834 aurelien 105
		colonnes.add(new ColumnConfig("nom", i18nC.nom(), 200));
106
		colonnes.add(new ColumnConfig("abreviation", i18nC.projetAbreviation(), 200));
877 aurelien 107
		colonnes.add(new ColumnConfig("resume", i18nC.projetResume(), 300));
108
		colonnes.add(new ColumnConfig("url", i18nC.projetUrl(), 200));
928 jpm 109
		colonnes.add(new ColumnConfig("mot_cles", i18nC.projetMotsCles(), 280));
834 aurelien 110
 
111
		modeleDesColonnes = new ColumnModel(colonnes);
112
 
113
		GridSelectionModel<Projet> modeleDeSelection = new GridSelectionModel<Projet>();
114
		modeleDeSelection.addSelectionChangedListener(new SelectionChangedListener<Projet>() {
115
			public void selectionChanged(SelectionChangedEvent<Projet> event) {
1613 aurelien 116
				projetSelectionne = (Projet) event.getSelectedItem();
117
				clicListe(projetSelectionne);
834 aurelien 118
			}
119
		});
120
 
121
		store = new ListStore<Projet>();
926 jpm 122
		store.sort("id_projet", SortDir.ASC);
834 aurelien 123
 
124
		grille = new Grid<Projet>(store, modeleDesColonnes);
125
		grille.setWidth("100%");
924 jpm 126
		grille.setAutoExpandColumn("nom");
834 aurelien 127
		grille.getView().setAutoFill(true);
128
		grille.getView().setForceFit(true);
129
		grille.setSelectionModel(modeleDeSelection);
130
		grille.addListener(Events.ViewReady, new Listener<BaseEvent>() {
131
			public void handleEvent(BaseEvent be) {
132
				grille.getSelectionModel().select(0, false);
133
			}
134
		});
135
 
136
		grille.addListener(Events.OnDoubleClick, new Listener<BaseEvent>(){
137
			public void handleEvent(BaseEvent be) {
138
				modifier.fireEvent(Events.Select);
139
			}
140
		});
141
		add(grille);
1045 gduche 142
 
143
		// Définition de la barre de pagination
144
		pagination = new BarrePaginationVue(new StructureListe(), mediateur);
145
		setBottomComponent(pagination);
834 aurelien 146
	}
147
 
148
	public ListStore<Projet> getStore() {
149
		return store;
150
	}
151
 
152
	private void clicListe(Projet projet) {
153
		mediateur.clicListeProjet(projet);
154
	}
155
 
156
	private void gererEtatActivationBouton() {
157
		int nbreElementDuMagazin = store.getCount();
158
		ajouter.enable();
1074 jpm 159
		if (nbreElementDuMagazin <= 0) {
834 aurelien 160
			supprimer.disable();
161
			modifier.disable();
1074 jpm 162
		} else if (nbreElementDuMagazin > 0) {
163
			modifier.enable();
164
			if (mediateur.getUtilisateur().isIdentifie()) {
834 aurelien 165
				supprimer.enable();
166
			}
167
		}
168
	}
169
 
851 gduche 170
	public void rafraichir(Object nouvellesDonnees) {
171
		if (nouvellesDonnees instanceof ProjetListe) {
172
			ProjetListe projets = (ProjetListe) nouvellesDonnees;
1045 gduche 173
			pagination.setlistePaginable(projets);
174
			pagination.rafraichir(projets.getPageTable());
175
 
834 aurelien 176
			if (projets != null) {
928 jpm 177
				List<Projet> projetsListe = projets.toList();
834 aurelien 178
				store.removeAll();
928 jpm 179
				if (mediateur.getProjetId() != null) {
180
					String projetIdSelectionne = mediateur.getProjetId();
181
					Iterator<Projet> it = projetsListe.iterator();
182
					while (it.hasNext()) {
183
						Projet projetCourant = it.next();
184
						if (projetCourant.getId().equals(projetIdSelectionne)) {
185
							store.add(projetCourant);
186
						}
187
					}
188
				} else {
189
					store.add(projetsListe);
190
				}
924 jpm 191
				mediateur.actualiserPanneauCentral();
834 aurelien 192
			}
851 gduche 193
		} else if (nouvellesDonnees instanceof Information) {
194
			Information info = (Information) nouvellesDonnees;
834 aurelien 195
			if (info.getType().equals("maj_utilisateur")) {
196
				gererEtatActivationBouton();
1613 aurelien 197
			} else if (info.getType().equals("projet_modifie")) {
198
				if(projetSelectionne != null) {
199
					store.remove(indexElementSelectionne);
200
					projetSelectionne = null;
201
				}
202
				Projet projetModifie = (Projet)info.getDonnee(0);
203
				// au cas ou le bouton appliquer aurait été cliqué avant de valider
204
				store.remove(projetModifie);
205
				store.insert(projetModifie, indexElementSelectionne);
206
				grille.repaint();
207
				grille.getSelectionModel().select(indexElementSelectionne, true);
208
				clicListe(projetModifie);
924 jpm 209
			} else if (info.getType().equals("suppression_projet")) {
931 jpm 210
				String message = info.toString();
211
				if (info.getDonnee(0) != null) {
212
					message = (String) info.getDonnee(0);
213
				}
1080 gduche 214
				String idsNonSuppr = info.getDonnee(1).toString();
215
				if (!UtilString.isEmpty(idsNonSuppr))	{
216
					message = "Les projets " + idsNonSuppr + " n'ont pas été supprimés car ils sont liés à d'autres éléments";
217
				}
218
 
1239 cyprien 219
				InfoLogger.display(i18nC.projetTitreSuppression(), message, true);
1080 gduche 220
				supprimerProjetsSelectionnees(Arrays.asList(idsNonSuppr.split(",")));
931 jpm 221
				gererEtatActivationBouton();
834 aurelien 222
			}
223
		} else {
1117 jpm 224
			Debug.log(Mediateur.i18nM.erreurRafraichir(nouvellesDonnees.getClass(), this.getClass()));
834 aurelien 225
		}
1117 jpm 226
		layout();
834 aurelien 227
	}
228
 
1117 jpm 229
	public void supprimerProjetsSelectionnees(List<String> idsNonSuppr) {
834 aurelien 230
		List<Projet> selPub = grille.getSelectionModel().getSelectedItems();
1117 jpm 231
		for (Iterator<Projet> it = selPub.iterator(); it.hasNext();) {
1080 gduche 232
			Projet projetCourant = it.next();
233
			if (!idsNonSuppr.contains(projetCourant.getId().toString()))	{
234
				grille.getStore().remove(projetCourant);
235
			}
834 aurelien 236
		}
1088 gduche 237
 
238
		//Mettre à jour les filtres
239
		mediateur.mettreFiltreAJour(grille.getStore().getModels());
834 aurelien 240
		layout(true);
241
	}
1117 jpm 242
}