Subversion Repositories eFlore/Applications.coel

Rev

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