Subversion Repositories eFlore/Applications.coel

Rev

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