Subversion Repositories eFlore/Applications.coel

Rev

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