Subversion Repositories eFlore/Applications.coel

Rev

Rev 851 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
834 aurelien 1
package org.tela_botanica.client.vues;
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.Projet;
14
import org.tela_botanica.client.modeles.ProjetListe;
15
import org.tela_botanica.client.modeles.Utilisateur;
16
 
17
import com.extjs.gxt.ui.client.Registry;
18
import com.extjs.gxt.ui.client.Style.SortDir;
19
import com.extjs.gxt.ui.client.event.BaseEvent;
20
import com.extjs.gxt.ui.client.event.ButtonEvent;
21
import com.extjs.gxt.ui.client.event.Events;
22
import com.extjs.gxt.ui.client.event.Listener;
23
import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
24
import com.extjs.gxt.ui.client.event.SelectionChangedListener;
25
import com.extjs.gxt.ui.client.event.SelectionListener;
26
import com.extjs.gxt.ui.client.store.ListStore;
27
import com.extjs.gxt.ui.client.widget.ContentPanel;
28
import com.extjs.gxt.ui.client.widget.button.Button;
29
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
30
import com.extjs.gxt.ui.client.widget.grid.ColumnData;
31
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
32
import com.extjs.gxt.ui.client.widget.grid.Grid;
33
import com.extjs.gxt.ui.client.widget.grid.GridCellRenderer;
34
import com.extjs.gxt.ui.client.widget.grid.GridSelectionModel;
35
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
36
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
37
import com.google.gwt.core.client.GWT;
38
import com.google.gwt.user.client.Window;
39
 
40
public class ProjetListeVue extends ContentPanel implements Rafraichissable {
41
 
42
	private Mediateur mediateur = null;
43
	private Constantes i18nC = null;
44
 
45
	private Grid<Projet> grille = null;
46
	private ListStore<Projet> store = null;
47
	private ColumnModel modeleDesColonnes = null;
48
 
49
	private Button ajouter;
50
	private Button modifier;
51
	private Button supprimer;
52
 
53
	private boolean enSuppression = false;
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
		toolBar.add(modifier);
76
		modifier.addSelectionListener(new SelectionListener<ButtonEvent>() {
77
			public void componentSelected(ButtonEvent be) {
78
				int tailleSel = grille.getSelectionModel().getSelectedItems().size();
79
				if(tailleSel > 0) {
80
					if(grille.getSelectionModel().getSelectedItems().size() > 1) {
877 aurelien 81
						Window.alert("Veuillez ne sélectionner qu'un seul projet à modifier");
834 aurelien 82
					} else {
83
						mediateur.clicModifierProjet(grille.getSelectionModel().getSelectedItems());
84
					}
85
				}
86
			}
87
		});
88
 
89
		supprimer = new Button(i18nC.supprimer());
90
		supprimer.setIcon(Images.ICONES.supprimer());
91
		toolBar.add(supprimer);
92
		supprimer.addSelectionListener(new SelectionListener<ButtonEvent>() {
93
			public void componentSelected(ButtonEvent be) {
94
				mediateur.clicSupprimerProjet(grille.getSelectionModel().getSelectedItems());
95
			}
96
		});
97
 
98
		setTopComponent(toolBar);
99
 
100
		List<ColumnConfig> colonnes = new ArrayList<ColumnConfig>();
101
		// ATTENTION : les noms des colonnes doivent correspondre aux noms variables de la classe utilisée dans la liste
877 aurelien 102
		colonnes.add(new ColumnConfig("id_projet", i18nC.id(), 20));
834 aurelien 103
		colonnes.add(new ColumnConfig("nom", i18nC.nom(), 200));
104
		colonnes.add(new ColumnConfig("abreviation", i18nC.projetAbreviation(), 200));
877 aurelien 105
		colonnes.add(new ColumnConfig("resume", i18nC.projetResume(), 300));
106
		colonnes.add(new ColumnConfig("url", i18nC.projetUrl(), 200));
107
		colonnes.add(new ColumnConfig("mots_cles", i18nC.projetMotsCles(), 280));
834 aurelien 108
 
109
		modeleDesColonnes = new ColumnModel(colonnes);
110
 
111
		GridSelectionModel<Projet> modeleDeSelection = new GridSelectionModel<Projet>();
112
		modeleDeSelection.addSelectionChangedListener(new SelectionChangedListener<Projet>() {
113
			public void selectionChanged(SelectionChangedEvent<Projet> event) {
114
				Projet projet = (Projet) event.getSelectedItem();
115
				clicListe(projet);
116
			}
117
		});
118
 
119
		store = new ListStore<Projet>();
120
		store.sort("titre", SortDir.ASC);
121
 
122
		grille = new Grid<Projet>(store, modeleDesColonnes);
123
		grille.setWidth("100%");
124
		//grille.setAutoExpandColumn("titre");
125
		grille.getView().setAutoFill(true);
126
		grille.getView().setForceFit(true);
127
		grille.setSelectionModel(modeleDeSelection);
128
		grille.addListener(Events.ViewReady, new Listener<BaseEvent>() {
129
			@Override
130
			public void handleEvent(BaseEvent be) {
131
				grille.getSelectionModel().select(0, false);
132
			}
133
		});
134
 
135
		grille.addListener(Events.OnDoubleClick, new Listener<BaseEvent>(){
136
 
137
			@Override
138
			public void handleEvent(BaseEvent be) {
139
				modifier.fireEvent(Events.Select);
140
			}
141
 
142
		});
143
		add(grille);
144
	}
145
 
146
	public ListStore<Projet> getStore() {
147
		return store;
148
	}
149
 
150
	private void clicListe(Projet projet) {
151
		mediateur.clicListeProjet(projet);
152
	}
153
 
154
	private void gererEtatActivationBouton() {
155
		int nbreElementDuMagazin = store.getCount();
156
		ajouter.enable();
157
		if(!((Utilisateur)Registry.get(RegistreId.UTILISATEUR_COURANT)).isIdentifie()) {
158
			supprimer.disable();
159
			modifier.disable();
160
		} else {
161
			if (nbreElementDuMagazin <= 0) {
162
				supprimer.disable();
163
				modifier.disable();
164
			} else {
165
				supprimer.enable();
166
				modifier.enable();
167
			}
168
		}
169
	}
170
 
851 gduche 171
	public void rafraichir(Object nouvellesDonnees) {
172
		if (nouvellesDonnees instanceof ProjetListe) {
173
			ProjetListe projets = (ProjetListe) nouvellesDonnees;
834 aurelien 174
 
175
			if (projets != null) {
176
				List<Projet> liste = projets.toList();
177
				store = new ListStore<Projet>();
178
				store.removeAll();
179
				store.add(liste);
180
				grille.reconfigure(store, modeleDesColonnes);
181
				grille.getSelectionModel().select(0, false);
182
 
183
				repaint();
184
			}
185
 
186
			//mediateur.actualiserPanneauCentral();
187
			gererEtatActivationBouton();
188
			layout(true);
851 gduche 189
		} else if (nouvellesDonnees instanceof Information) {
190
			Information info = (Information) nouvellesDonnees;
834 aurelien 191
			if (info.getType().equals("maj_utilisateur")) {
192
				gererEtatActivationBouton();
193
			}
194
 
195
			if (info.getType().equals("suppression_projet")) {
196
				supprimerProjetsSelectionnees();
197
				enSuppression = true;
198
			}
199
 
200
			if (info.getType().equals("suppression_auteur") && enSuppression) {
201
				supprimerProjetsSelectionnees();
202
				enSuppression = false;
203
			}
204
 
205
		} else {
851 gduche 206
			GWT.log(mediateur.i18nM.erreurRafraichir(nouvellesDonnees.getClass(), this.getClass()), null);
834 aurelien 207
		}
208
	}
209
 
210
	public void supprimerProjetsSelectionnees() {
211
		List<Projet> selPub = grille.getSelectionModel().getSelectedItems();
212
		GWT.log("Le résultat dans supprimer est : "+grille.getSelectionModel().getSelection().size()+" ", null);
213
		for(Iterator<Projet> it = selPub.iterator(); it.hasNext();) {
214
			GWT.log("Le résultat dans rafraichir est : "+grille.getSelectionModel().getSelection().size()+" ", null);
215
			grille.getStore().remove(it.next());
216
		}
217
		grille.reconfigure(store, modeleDesColonnes);
218
		layout(true);
219
	}
220
 
221
}