Subversion Repositories eFlore/Applications.coel

Rev

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