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;
|
|
|
29 |
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.ColumnModel;
|
|
|
32 |
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.layout.FitLayout;
|
|
|
35 |
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
|
|
|
36 |
import com.google.gwt.core.client.GWT;
|
|
|
37 |
|
|
|
38 |
public class ProjetListeVue extends ContentPanel implements Rafraichissable {
|
|
|
39 |
|
|
|
40 |
private Mediateur mediateur = null;
|
|
|
41 |
private Constantes i18nC = null;
|
|
|
42 |
|
|
|
43 |
private Grid<Projet> grille = null;
|
|
|
44 |
private ListStore<Projet> store = null;
|
|
|
45 |
private ColumnModel modeleDesColonnes = null;
|
|
|
46 |
|
|
|
47 |
private Button ajouter;
|
|
|
48 |
private Button modifier;
|
|
|
49 |
private Button supprimer;
|
|
|
50 |
|
|
|
51 |
public ProjetListeVue(Mediateur mediateurCourant) {
|
|
|
52 |
super();
|
|
|
53 |
mediateur = mediateurCourant;
|
|
|
54 |
i18nC = Mediateur.i18nC;
|
|
|
55 |
|
|
|
56 |
setLayout(new FitLayout());
|
|
|
57 |
setHeading("Projets");
|
|
|
58 |
|
|
|
59 |
ToolBar toolBar = new ToolBar();
|
|
|
60 |
ajouter = new Button(i18nC.ajouter());
|
|
|
61 |
ajouter.setIcon(Images.ICONES.ajouter());
|
|
|
62 |
ajouter.addSelectionListener(new SelectionListener<ButtonEvent>() {
|
|
|
63 |
public void componentSelected(ButtonEvent be) {
|
|
|
64 |
mediateur.clicAjouterProjet();
|
|
|
65 |
}
|
|
|
66 |
});
|
|
|
67 |
toolBar.add(ajouter);
|
|
|
68 |
|
|
|
69 |
modifier = new Button(i18nC.modifier());
|
|
|
70 |
modifier.setIcon(Images.ICONES.formModifier());
|
|
|
71 |
modifier.addSelectionListener(new SelectionListener<ButtonEvent>() {
|
|
|
72 |
public void componentSelected(ButtonEvent be) {
|
924 |
jpm |
73 |
mediateur.clicModifierProjet(grille.getSelectionModel().getSelectedItems());
|
834 |
aurelien |
74 |
}
|
|
|
75 |
});
|
924 |
jpm |
76 |
toolBar.add(modifier);
|
834 |
aurelien |
77 |
|
|
|
78 |
supprimer = new Button(i18nC.supprimer());
|
|
|
79 |
supprimer.setIcon(Images.ICONES.supprimer());
|
|
|
80 |
supprimer.addSelectionListener(new SelectionListener<ButtonEvent>() {
|
|
|
81 |
public void componentSelected(ButtonEvent be) {
|
|
|
82 |
mediateur.clicSupprimerProjet(grille.getSelectionModel().getSelectedItems());
|
|
|
83 |
}
|
|
|
84 |
});
|
924 |
jpm |
85 |
toolBar.add(supprimer);
|
834 |
aurelien |
86 |
|
|
|
87 |
setTopComponent(toolBar);
|
|
|
88 |
|
|
|
89 |
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
|
877 |
aurelien |
91 |
colonnes.add(new ColumnConfig("id_projet", i18nC.id(), 20));
|
834 |
aurelien |
92 |
colonnes.add(new ColumnConfig("nom", i18nC.nom(), 200));
|
|
|
93 |
colonnes.add(new ColumnConfig("abreviation", i18nC.projetAbreviation(), 200));
|
877 |
aurelien |
94 |
colonnes.add(new ColumnConfig("resume", i18nC.projetResume(), 300));
|
|
|
95 |
colonnes.add(new ColumnConfig("url", i18nC.projetUrl(), 200));
|
|
|
96 |
colonnes.add(new ColumnConfig("mots_cles", i18nC.projetMotsCles(), 280));
|
834 |
aurelien |
97 |
|
|
|
98 |
modeleDesColonnes = new ColumnModel(colonnes);
|
|
|
99 |
|
|
|
100 |
GridSelectionModel<Projet> modeleDeSelection = new GridSelectionModel<Projet>();
|
|
|
101 |
modeleDeSelection.addSelectionChangedListener(new SelectionChangedListener<Projet>() {
|
|
|
102 |
public void selectionChanged(SelectionChangedEvent<Projet> event) {
|
|
|
103 |
Projet projet = (Projet) event.getSelectedItem();
|
|
|
104 |
clicListe(projet);
|
|
|
105 |
}
|
|
|
106 |
});
|
|
|
107 |
|
|
|
108 |
store = new ListStore<Projet>();
|
926 |
jpm |
109 |
store.sort("id_projet", SortDir.ASC);
|
834 |
aurelien |
110 |
|
|
|
111 |
grille = new Grid<Projet>(store, modeleDesColonnes);
|
|
|
112 |
grille.setWidth("100%");
|
924 |
jpm |
113 |
grille.setAutoExpandColumn("nom");
|
834 |
aurelien |
114 |
grille.getView().setAutoFill(true);
|
|
|
115 |
grille.getView().setForceFit(true);
|
|
|
116 |
grille.setSelectionModel(modeleDeSelection);
|
|
|
117 |
grille.addListener(Events.ViewReady, new Listener<BaseEvent>() {
|
|
|
118 |
@Override
|
|
|
119 |
public void handleEvent(BaseEvent be) {
|
|
|
120 |
grille.getSelectionModel().select(0, false);
|
|
|
121 |
}
|
|
|
122 |
});
|
|
|
123 |
|
|
|
124 |
grille.addListener(Events.OnDoubleClick, new Listener<BaseEvent>(){
|
|
|
125 |
@Override
|
|
|
126 |
public void handleEvent(BaseEvent be) {
|
|
|
127 |
modifier.fireEvent(Events.Select);
|
|
|
128 |
}
|
|
|
129 |
});
|
|
|
130 |
add(grille);
|
|
|
131 |
}
|
|
|
132 |
|
|
|
133 |
public ListStore<Projet> getStore() {
|
|
|
134 |
return store;
|
|
|
135 |
}
|
|
|
136 |
|
|
|
137 |
private void clicListe(Projet projet) {
|
|
|
138 |
mediateur.clicListeProjet(projet);
|
|
|
139 |
}
|
|
|
140 |
|
|
|
141 |
private void gererEtatActivationBouton() {
|
|
|
142 |
int nbreElementDuMagazin = store.getCount();
|
|
|
143 |
ajouter.enable();
|
|
|
144 |
if(!((Utilisateur)Registry.get(RegistreId.UTILISATEUR_COURANT)).isIdentifie()) {
|
|
|
145 |
supprimer.disable();
|
|
|
146 |
modifier.disable();
|
|
|
147 |
} else {
|
|
|
148 |
if (nbreElementDuMagazin <= 0) {
|
|
|
149 |
supprimer.disable();
|
|
|
150 |
modifier.disable();
|
|
|
151 |
} else {
|
|
|
152 |
supprimer.enable();
|
|
|
153 |
modifier.enable();
|
|
|
154 |
}
|
|
|
155 |
}
|
|
|
156 |
}
|
|
|
157 |
|
851 |
gduche |
158 |
public void rafraichir(Object nouvellesDonnees) {
|
|
|
159 |
if (nouvellesDonnees instanceof ProjetListe) {
|
|
|
160 |
ProjetListe projets = (ProjetListe) nouvellesDonnees;
|
834 |
aurelien |
161 |
if (projets != null) {
|
|
|
162 |
List<Projet> liste = projets.toList();
|
|
|
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 |
}
|