Subversion Repositories eFlore/Applications.coel

Rev

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