Subversion Repositories eFlore/Applications.coel

Rev

Rev 1613 | Rev 1633 | 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
		});
1630 aurelien 79
		ajouter.setToolTip(i18nC.indicationCreerUneFiche()+" "+i18nC.projetSingulier());
834 aurelien 80
		toolBar.add(ajouter);
81
 
82
		modifier = new Button(i18nC.modifier());
83
		modifier.setIcon(Images.ICONES.formModifier());
84
		modifier.addSelectionListener(new SelectionListener<ButtonEvent>() {
85
			public void componentSelected(ButtonEvent be) {
924 jpm 86
				mediateur.clicModifierProjet(grille.getSelectionModel().getSelectedItems());
1613 aurelien 87
				indexElementSelectionne = store.indexOf(grille.getSelectionModel().getSelectedItem());
834 aurelien 88
			}
89
		});
1630 aurelien 90
		modifier.setToolTip(i18nC.indicationModifierUneFiche());
924 jpm 91
		toolBar.add(modifier);
834 aurelien 92
 
93
		supprimer = new Button(i18nC.supprimer());
94
		supprimer.setIcon(Images.ICONES.supprimer());
95
		supprimer.addSelectionListener(new SelectionListener<ButtonEvent>() {
96
			public void componentSelected(ButtonEvent be) {
97
				mediateur.clicSupprimerProjet(grille.getSelectionModel().getSelectedItems());
98
			}
99
		});
1630 aurelien 100
		supprimer.setToolTip(i18nC.indicationSupprimerUneFiche());
924 jpm 101
		toolBar.add(supprimer);
834 aurelien 102
 
103
		setTopComponent(toolBar);
104
 
105
		List<ColumnConfig> colonnes = new ArrayList<ColumnConfig>();
106
		// ATTENTION : les noms des colonnes doivent correspondre aux noms variables de la classe utilisée dans la liste
877 aurelien 107
		colonnes.add(new ColumnConfig("id_projet", i18nC.id(), 20));
834 aurelien 108
		colonnes.add(new ColumnConfig("nom", i18nC.nom(), 200));
109
		colonnes.add(new ColumnConfig("abreviation", i18nC.projetAbreviation(), 200));
877 aurelien 110
		colonnes.add(new ColumnConfig("resume", i18nC.projetResume(), 300));
111
		colonnes.add(new ColumnConfig("url", i18nC.projetUrl(), 200));
928 jpm 112
		colonnes.add(new ColumnConfig("mot_cles", i18nC.projetMotsCles(), 280));
834 aurelien 113
 
114
		modeleDesColonnes = new ColumnModel(colonnes);
115
 
116
		GridSelectionModel<Projet> modeleDeSelection = new GridSelectionModel<Projet>();
117
		modeleDeSelection.addSelectionChangedListener(new SelectionChangedListener<Projet>() {
118
			public void selectionChanged(SelectionChangedEvent<Projet> event) {
1613 aurelien 119
				projetSelectionne = (Projet) event.getSelectedItem();
120
				clicListe(projetSelectionne);
834 aurelien 121
			}
122
		});
123
 
124
		store = new ListStore<Projet>();
926 jpm 125
		store.sort("id_projet", SortDir.ASC);
834 aurelien 126
 
127
		grille = new Grid<Projet>(store, modeleDesColonnes);
128
		grille.setWidth("100%");
924 jpm 129
		grille.setAutoExpandColumn("nom");
834 aurelien 130
		grille.getView().setAutoFill(true);
131
		grille.getView().setForceFit(true);
132
		grille.setSelectionModel(modeleDeSelection);
133
		grille.addListener(Events.ViewReady, new Listener<BaseEvent>() {
134
			public void handleEvent(BaseEvent be) {
135
				grille.getSelectionModel().select(0, false);
136
			}
137
		});
138
 
139
		grille.addListener(Events.OnDoubleClick, new Listener<BaseEvent>(){
140
			public void handleEvent(BaseEvent be) {
141
				modifier.fireEvent(Events.Select);
142
			}
143
		});
144
		add(grille);
1045 gduche 145
 
146
		// Définition de la barre de pagination
147
		pagination = new BarrePaginationVue(new StructureListe(), mediateur);
148
		setBottomComponent(pagination);
834 aurelien 149
	}
150
 
151
	public ListStore<Projet> getStore() {
152
		return store;
153
	}
154
 
155
	private void clicListe(Projet projet) {
156
		mediateur.clicListeProjet(projet);
157
	}
158
 
159
	private void gererEtatActivationBouton() {
160
		int nbreElementDuMagazin = store.getCount();
161
		ajouter.enable();
1074 jpm 162
		if (nbreElementDuMagazin <= 0) {
834 aurelien 163
			supprimer.disable();
164
			modifier.disable();
1074 jpm 165
		} else if (nbreElementDuMagazin > 0) {
166
			modifier.enable();
167
			if (mediateur.getUtilisateur().isIdentifie()) {
834 aurelien 168
				supprimer.enable();
169
			}
170
		}
171
	}
172
 
851 gduche 173
	public void rafraichir(Object nouvellesDonnees) {
174
		if (nouvellesDonnees instanceof ProjetListe) {
175
			ProjetListe projets = (ProjetListe) nouvellesDonnees;
1045 gduche 176
			pagination.setlistePaginable(projets);
177
			pagination.rafraichir(projets.getPageTable());
178
 
834 aurelien 179
			if (projets != null) {
928 jpm 180
				List<Projet> projetsListe = projets.toList();
834 aurelien 181
				store.removeAll();
928 jpm 182
				if (mediateur.getProjetId() != null) {
183
					String projetIdSelectionne = mediateur.getProjetId();
184
					Iterator<Projet> it = projetsListe.iterator();
185
					while (it.hasNext()) {
186
						Projet projetCourant = it.next();
187
						if (projetCourant.getId().equals(projetIdSelectionne)) {
188
							store.add(projetCourant);
189
						}
190
					}
191
				} else {
192
					store.add(projetsListe);
193
				}
924 jpm 194
				mediateur.actualiserPanneauCentral();
834 aurelien 195
			}
851 gduche 196
		} else if (nouvellesDonnees instanceof Information) {
197
			Information info = (Information) nouvellesDonnees;
834 aurelien 198
			if (info.getType().equals("maj_utilisateur")) {
199
				gererEtatActivationBouton();
1613 aurelien 200
			} else if (info.getType().equals("projet_modifie")) {
201
				if(projetSelectionne != null) {
202
					store.remove(indexElementSelectionne);
203
					projetSelectionne = null;
204
				}
205
				Projet projetModifie = (Projet)info.getDonnee(0);
206
				// au cas ou le bouton appliquer aurait été cliqué avant de valider
207
				store.remove(projetModifie);
208
				store.insert(projetModifie, indexElementSelectionne);
209
				grille.repaint();
210
				grille.getSelectionModel().select(indexElementSelectionne, true);
211
				clicListe(projetModifie);
924 jpm 212
			} else if (info.getType().equals("suppression_projet")) {
931 jpm 213
				String message = info.toString();
214
				if (info.getDonnee(0) != null) {
215
					message = (String) info.getDonnee(0);
216
				}
1080 gduche 217
				String idsNonSuppr = info.getDonnee(1).toString();
218
				if (!UtilString.isEmpty(idsNonSuppr))	{
219
					message = "Les projets " + idsNonSuppr + " n'ont pas été supprimés car ils sont liés à d'autres éléments";
220
				}
221
 
1239 cyprien 222
				InfoLogger.display(i18nC.projetTitreSuppression(), message, true);
1080 gduche 223
				supprimerProjetsSelectionnees(Arrays.asList(idsNonSuppr.split(",")));
931 jpm 224
				gererEtatActivationBouton();
834 aurelien 225
			}
226
		} else {
1117 jpm 227
			Debug.log(Mediateur.i18nM.erreurRafraichir(nouvellesDonnees.getClass(), this.getClass()));
834 aurelien 228
		}
1117 jpm 229
		layout();
834 aurelien 230
	}
231
 
1117 jpm 232
	public void supprimerProjetsSelectionnees(List<String> idsNonSuppr) {
834 aurelien 233
		List<Projet> selPub = grille.getSelectionModel().getSelectedItems();
1117 jpm 234
		for (Iterator<Projet> it = selPub.iterator(); it.hasNext();) {
1080 gduche 235
			Projet projetCourant = it.next();
236
			if (!idsNonSuppr.contains(projetCourant.getId().toString()))	{
237
				grille.getStore().remove(projetCourant);
238
			}
834 aurelien 239
		}
1088 gduche 240
 
241
		//Mettre à jour les filtres
242
		mediateur.mettreFiltreAJour(grille.getStore().getModels());
834 aurelien 243
		layout(true);
244
	}
1117 jpm 245
}