Subversion Repositories eFlore/Applications.coel

Rev

Rev 935 | 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();
152
		if(!((Utilisateur)Registry.get(RegistreId.UTILISATEUR_COURANT)).isIdentifie()) {
153
			supprimer.disable();
154
			modifier.disable();
155
		} else {
156
			if (nbreElementDuMagazin <= 0) {
157
				supprimer.disable();
158
				modifier.disable();
159
			} else {
160
				supprimer.enable();
161
				modifier.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
				}
198
				Info.display(i18nC.projetTitreSuppression(), message);
834 aurelien 199
				supprimerProjetsSelectionnees();
931 jpm 200
				gererEtatActivationBouton();
834 aurelien 201
			}
202
		} else {
924 jpm 203
			GWT.log(Mediateur.i18nM.erreurRafraichir(nouvellesDonnees.getClass(), this.getClass()), null);
834 aurelien 204
		}
205
	}
206
 
207
	public void supprimerProjetsSelectionnees() {
208
		List<Projet> selPub = grille.getSelectionModel().getSelectedItems();
209
		GWT.log("Le résultat dans supprimer est : "+grille.getSelectionModel().getSelection().size()+" ", null);
210
		for(Iterator<Projet> it = selPub.iterator(); it.hasNext();) {
211
			GWT.log("Le résultat dans rafraichir est : "+grille.getSelectionModel().getSelection().size()+" ", null);
212
			grille.getStore().remove(it.next());
213
		}
214
		layout(true);
215
	}
216
 
217
}