Subversion Repositories eFlore/Applications.coel

Rev

Rev 1117 | 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
			@Override
126
			public void handleEvent(BaseEvent be) {
127
				grille.getSelectionModel().select(0, false);
128
			}
129
		});
130
 
131
		grille.addListener(Events.OnDoubleClick, new Listener<BaseEvent>(){
132
			@Override
133
			public void handleEvent(BaseEvent be) {
134
				modifier.fireEvent(Events.Select);
135
			}
136
		});
137
		add(grille);
1045 gduche 138
 
139
		// Définition de la barre de pagination
140
		pagination = new BarrePaginationVue(new StructureListe(), mediateur);
141
		setBottomComponent(pagination);
834 aurelien 142
	}
143
 
144
	public ListStore<Projet> getStore() {
145
		return store;
146
	}
147
 
148
	private void clicListe(Projet projet) {
149
		mediateur.clicListeProjet(projet);
150
	}
151
 
152
	private void gererEtatActivationBouton() {
153
		int nbreElementDuMagazin = store.getCount();
154
		ajouter.enable();
1074 jpm 155
		if (nbreElementDuMagazin <= 0) {
834 aurelien 156
			supprimer.disable();
157
			modifier.disable();
1074 jpm 158
		} else if (nbreElementDuMagazin > 0) {
159
			modifier.enable();
160
			if (mediateur.getUtilisateur().isIdentifie()) {
834 aurelien 161
				supprimer.enable();
162
			}
163
		}
164
	}
165
 
851 gduche 166
	public void rafraichir(Object nouvellesDonnees) {
167
		if (nouvellesDonnees instanceof ProjetListe) {
168
			ProjetListe projets = (ProjetListe) nouvellesDonnees;
1045 gduche 169
			pagination.setlistePaginable(projets);
170
			pagination.rafraichir(projets.getPageTable());
171
 
834 aurelien 172
			if (projets != null) {
928 jpm 173
				List<Projet> projetsListe = projets.toList();
834 aurelien 174
				store.removeAll();
928 jpm 175
				if (mediateur.getProjetId() != null) {
176
					String projetIdSelectionne = mediateur.getProjetId();
177
					Iterator<Projet> it = projetsListe.iterator();
178
					while (it.hasNext()) {
179
						Projet projetCourant = it.next();
180
						if (projetCourant.getId().equals(projetIdSelectionne)) {
181
							store.add(projetCourant);
182
						}
183
					}
184
				} else {
185
					store.add(projetsListe);
186
				}
924 jpm 187
				mediateur.actualiserPanneauCentral();
834 aurelien 188
			}
851 gduche 189
		} else if (nouvellesDonnees instanceof Information) {
190
			Information info = (Information) nouvellesDonnees;
834 aurelien 191
			if (info.getType().equals("maj_utilisateur")) {
192
				gererEtatActivationBouton();
924 jpm 193
			} else if (info.getType().equals("suppression_projet")) {
931 jpm 194
				String message = info.toString();
195
				if (info.getDonnee(0) != null) {
196
					message = (String) info.getDonnee(0);
197
				}
1080 gduche 198
				String idsNonSuppr = info.getDonnee(1).toString();
199
				if (!UtilString.isEmpty(idsNonSuppr))	{
200
					message = "Les projets " + idsNonSuppr + " n'ont pas été supprimés car ils sont liés à d'autres éléments";
201
				}
202
 
1239 cyprien 203
				InfoLogger.display(i18nC.projetTitreSuppression(), message, true);
1080 gduche 204
				supprimerProjetsSelectionnees(Arrays.asList(idsNonSuppr.split(",")));
931 jpm 205
				gererEtatActivationBouton();
834 aurelien 206
			}
207
		} else {
1117 jpm 208
			Debug.log(Mediateur.i18nM.erreurRafraichir(nouvellesDonnees.getClass(), this.getClass()));
834 aurelien 209
		}
1117 jpm 210
		layout();
834 aurelien 211
	}
212
 
1117 jpm 213
	public void supprimerProjetsSelectionnees(List<String> idsNonSuppr) {
834 aurelien 214
		List<Projet> selPub = grille.getSelectionModel().getSelectedItems();
1117 jpm 215
		for (Iterator<Projet> it = selPub.iterator(); it.hasNext();) {
1080 gduche 216
			Projet projetCourant = it.next();
217
			if (!idsNonSuppr.contains(projetCourant.getId().toString()))	{
218
				grille.getStore().remove(projetCourant);
219
			}
834 aurelien 220
		}
1088 gduche 221
 
222
		//Mettre à jour les filtres
223
		mediateur.mettreFiltreAJour(grille.getStore().getModels());
834 aurelien 224
		layout(true);
225
	}
1117 jpm 226
}