Subversion Repositories eFlore/Applications.coel

Rev

Rev 928 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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